Best of Crypto

Best of Crypto

1648150020

Examples for the 2019 Derivhack Hackathon

Introduction

The goal of the ISDA Common Domain Model (CDM) is to allow financial institutions to have a coherent representation of financial instruments and events. This document shows how institutions can use the CDM and the Algorand blockchain to maintain separately owned but coherent financial databases with the following properties:

  1. Coherency: All institutions participating in a trade agree on the digital representation of that trade at any point in time.
  2. Privacy: The details of the trade are only revealed to the institutions which participate in it. Any other agent cannot learn anything about the trade.
  3. Lineage: Any modification in the state of a trade can refer to the previous state, generating a traceable lineage for the history of that trade.
  4. Ease of Use: Because the Algorand blockchain is a permissionless blockchain, institutions can interact with it using the software of their choice, and without the need to set up their own distributed system. Algorand provides easy to use APIs that read to and write from the blockchain, and SDKs in Python, Go, Java and Javascript.

The Algorand Blockchain

The Algorand blockchain can process 1000 transactions per second with a latency of less than 5 seconds and ensures transaction finality with point-of-sale speed. The Algorand blockchain is a permissionless blockchain with hundreds of independently operating nodes distributed around the world. The Algorand blockchain allows developers to create their applications without having to set up their own distributed systems. In addition, Algorand provides extensive documentation, and provides SDKs in four languages (Go, Python, Java and Javascript) to interact with the blockchain.

Figure 1: Nodes running the Algorand client software around the world Figure 1: Nodes running the Algorand client software around the world

Installing, Compiling and Running the Code

Dependencies

Running the code in this repository requires that you have

  1. A Unix-based OS such as Mac OS X or Linux
  2. Java
  3. Maven

Java and Maven Installation

OS X

These are bash scripts which install Java and Maven and set the correct paths to use them. These scripts are in the INSTALL folder and should be run in the following order

  1. install_brew.sh if the user does not have Hombrew installed (OS X utility to install programs)
  2. install_java.sh if the user does not have Java installed. This installs the OpenJDK
  3. install_maven.sh if the user does not have Maven installed
  4. install_mongo.sh if the user does not have MongoDB installed

Ubuntu

These are bash scripts which install Java and Maven and set the correct paths to use them. These scripts are in the INSTALL folder and should be run in the following order

  1. install_java_for_ubuntu.sh if the user does not have Java installed. This installs the OpenJDK
  2. install_maven_for_ubuntu.sh if the user does not have Maven installed
  3. install_mongo_for_ubuntu.sh if the user does not have MongoDB installed

Java library Installation

The main directory contains a pom.xml file which Maven uses to download Java libraries that the code depends on, including the Algorand Java SDK, and the Java implementation of the ISDA CDM.

The code has been tested on a computer running OS X Version 10.14.5, OpenJDK 13, and Maven version 3.6.1. and on an AWS instance ("4.15.0-1044-aws") running Ubuntu 18.04.2 LTS, OpenJDK 11 and Maven version 3.6.0

Compilation

A settings.xml file is provided in the project root directory, use it install dependencies as below:

mvn -s settings.xml clean install

You can also run

sh compile.sh

from the root directory.

Running the Code

To run the example code, type

sh run.sh 

in the root directory.

This script will start a MongoDB service and run the examples for the first three use cases in the hackathon. Ubuntu users need to uncomment the following line to run the mongo service on ubuntu.

##UNCOMMENT THIS LINE FOR UBUNBTU                                                                                                 
# bash start_mongo_on_ubuntu.sh 

(OPTIONAL): Starting and Stopping MongoDB

The code needs to have a Mongo DB service running to persist some information. Right now the run.sh script starts this service automatically if it is not running. However, we have provided scripts to start and stop this automatically

To run the mongodb service, run

sh start_mongo.sh

To stop the mongodb service, run

sh stop_mongo.sh

Example Use Cases

Execution

In the Derivhack Hackathon, users are given a trade execution file and need to

  1. Load the JSON file into their system
  2. Create users in their distributed ledger corresponding to the parties in the execution
  3. Create a report of the execution

In this example, we use the Algorand blockchain to ensure different parties have consistent versions of the file, while keeping their datastores private. The information stored in the chain includes the global key of the execution, its lineage, and the file path where the user stored the Execution JSON object in their private data store.

The following function, from the class CommitExecution.java reads a CDM Event, creates Algorand accounts for all parties in the event. It gets the executing party (Client 1's broker), and has this party send details of the execution to all other parties on the Algorand blockchain.

 public  class CommitExecution {

    public static void main(String [] args) throws Exception{
        
        //Read the input arguments and read them into files
        String fileName = args[0];
        String fileContents = ReadAndWrite.readFile(fileName);

         //Read the event file into a CDM object using the Rosetta object mapper
        ObjectMapper rosettaObjectMapper = RosettaObjectMapper.getDefaultRosettaObjectMapper();
        Event event = rosettaObjectMapper
                .readValue(fileContents, Event.class);
        
        //Create Algorand Accounts for all parties
        // and persist accounts to filesystem/database
        List<Party> parties = event.getParty();
        User user;
        DB mongoDB = MongoUtils.getDatabase("users");
        parties.parallelStream()
                .map(party -> User.getOrCreateUser(party,mongoDB))
                .collect(Collectors.toList());

        //Get the execution
        Execution execution = event
                                .getPrimitive()
                                .getExecution().get(0)
                                .getAfter()
                                .getExecution();


        // Get the executing party  reference
        String executingPartyReference = execution.getPartyRole()
                .stream()
                .filter(r -> r.getRole() == PartyRoleEnum.EXECUTING_ENTITY)
                .map(r -> r.getPartyReference().getGlobalReference())
                .collect(MoreCollectors.onlyElement());

        // Get the executing party
        Party executingParty = event.getParty().stream()
                .filter(p -> executingPartyReference.equals(p.getMeta().getGlobalKey()))
                .collect(MoreCollectors.onlyElement());

        // Get all other parties
        List<Party> otherParties =  event.getParty().stream()
                .filter(p -> !executingPartyReference.equals(p.getMeta().getGlobalKey()))
                .collect(Collectors.toList());

        // Find or create the executing user
        User executingUser = User.getOrCreateUser(executingParty, mongoDB);
       
        //Send all other parties the contents of the event as a set of blockchain transactions
        List<User> users = otherParties.
                            parallelStream()
                            .map(p -> User.getOrCreateUser(p,mongoDB))
                            .collect(Collectors.toList());

        List<Transaction> transactions = users
                                            .parallelStream()
                                            .map(u->executingUser.sendEventTransaction(u,event,"execution"))
                                            .collect(Collectors.toList());
        
    }
}

The corresponding shell command to execute this function with the Block trades file is

##Commit the execution file to the blockchain
mvn -s settings.xml exec:java -Dexec.mainClass="com.algorand.demo.CommitExecution" \
 -Dexec.args="./Files/UC1_block_execute_BT1.json" -e -q

Allocation

The second use case for Derivhack is allocation of trades. That is, the block trade execution given in use case 1 will be allocated among multiple accounts. Participants are also given a JSON CDM file specifying the [allocation] (https://github.com/algorand/DerivhackExamples/blob/master/Files/UC2_allocation_execution_AT1.json). Since allocations are CDM events, the same logic applies as in the Execution use case. To commit the allocation event to the blockchain, participants can use the following shell command

mvn -s settings.xml exec:java -Dexec.mainClass="com.algorand.demo.CommitAllocation" \
 -Dexec.args="./Files/UC2_allocation_execution_AT1.json" -e -q

Affirmation

The third use case is the affirmation of the trade by the clients. In contrast with the other cases, the Participants can look at the classes CommitAffirmation.java (https://github.com/algorand/DerivhackExamples/blob/master/src/main/java/com/algorand/demo/CommitAffirmation.java) and AffirmImpl.java (https://github.com/algorand/DerivhackExamples/blob/master/src/main/java/com/algorand/demo/AffirmationImpl.java) for examples on how to derive the Affirmation of a trade from its allocation.

In the affirmation step, the client produces a CDM affirmation from the Allocation Event, and sends the affirmation to the broker over the Algorand Chain.


``` class CommitAffirmation {
public static void main(String[] args){

        //Load the database to lookup users
        DB mongoDB = MongoUtils.getDatabase("users");

        //Load a file with client global keys
        String allocationFile = args[0];
        String allocationCDM = ReadAndWrite.readFile(allocationFile);
        ObjectMapper rosettaObjectMapper = RosettaObjectMapper.getDefaultRosettaObjectMapper();
        Event allocationEvent = null;
            try{
                allocationEvent = rosettaObjectMapper
                                    .readValue(allocationCDM, Event.class);
            }
            catch(java.io.IOException e){
                e.printStackTrace();
            }
                
       
        List<Trade> allocatedTrades = allocationEvent.getPrimitive().getAllocation().get(0).getAfter().getAllocatedTrade();
        //Keep track of the trade index
        int tradeIndex = 0;

        //Collect the affirmation transaction id and broker key in a file
        String result = "";
        //For each trade...
        for(Trade trade: allocatedTrades){

        //Get the broker that we need to send the affirmation to
        String brokerReference = trade.getExecution().getPartyRole()
            .stream()
            .filter(r -> r.getRole() == PartyRoleEnum.EXECUTING_ENTITY)
            .map(r -> r.getPartyReference().getGlobalReference())
            .collect(MoreCollectors.onlyElement());

            User broker = User.getUser(brokerReference,mongoDB);

        //Get the client reference for that trade
        String clientReference = trade.getExecution()
                                        .getPartyRole()
                                        .stream()
                                        .filter(r-> r.getRole()==PartyRoleEnum.CLIENT)
                                        .map(r->r.getPartyReference().getGlobalReference())
                                        .collect(MoreCollectors.onlyElement());
                
        // Load the client user, with algorand passphrase
        User user = User.getUser(clientReference,mongoDB);
        String algorandPassphrase = user.algorandPassphrase;

        // Confirm the user has received the global key of the allocation from the broker
        String receivedKey = AlgorandUtils.readEventTransaction( algorandPassphrase, allocationEvent.getMeta().getGlobalKey());
        assert receivedKey == allocationEvent.getMeta().getGlobalKey() : "Have not received allocation event from broker";
            //Compute the affirmation
            Affirmation affirmation = new AffirmImpl().doEvaluate(allocationEvent,tradeIndex).build();
                    
             //Send the affirmation to the broker
            Transaction transaction = 
                        user.sendAffirmationTransaction(broker, affirmation);
                    
            result += transaction.getTx() + "," + brokerReference +"\n";
                    
                
            tradeIndex = tradeIndex + 1;
        }
        try{
           ReadAndWrite.writeFile("./Files/AffirmationOutputs.txt", result);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

}

Download Details:
Author: algorand
Source Code: https://github.com/algorand/DerivhackExamples
License: MIT License

#algorand  #blockchain  #cryptocurrency #java 

What is GEEK

Buddha Community

Examples for the 2019 Derivhack Hackathon
Trevor  Russel

Trevor Russel

1618115820

New Hackathon For Data Scientists — Workation Price Prediction Challenge

MachineHack, in association with Analytics India Magazine, has come up with yet another hackathon for the machine learning community — the Workation Price Prediction Challenge.

In the light of the new normal, different websites have started providing packages to work from different locations. The concept of workation — a portmanteau of work and vacation– is gaining currency. However, it is challenging to find a good place with all the amenities, including high-speed internet and a comfortable stay within the budget.

Thus, to solve the real-world problem of finding the best deals for workations, MachineHack is challenging the machine learning community to build a model for predicting the price per person for workation trips.

To facilitate this, MachineHack has collected workation packages in and around India — starting from Kashmir to Kanyakumari and from Gujarat to Assam. The data has more than 18000+ rows of different packages with details like start location, hotel type, cost per person, destination, itinerary, and many more. Using this dataset, along with the knowledge of machine learning, deep learning, and model building, the participants need to create a model that can efficiently and accurately predict a workation trip’s expense.

#data science hackathon #hackathon #hackathon for data scientists #machine learning hackathon #ml hackathon #predicting workation price #workation price prediction challenge

Edna  Bernhard

Edna Bernhard

1596855420

Melanoma Tumor Size Prediction: Weekend Hackathon

MachineHack welcomes all Data Science and Machine Learning enthusiasts to another exciting weekend hackathon. This weekend, participants must use their data science skills to predict the melanoma tumor size based on a number of factors.

#featured #datascience hackathons #hackathon #machine learning hackathon #machine learning hackathons

Laravel AJAX CRUD Example Tutorial

Hello Guys,

Today I will show you how to create laravel AJAX CRUD example tutorial. In this tutorial we are implements ajax crud operation in laravel. Also perform insert, update, delete operation using ajax in laravel 6 and also you can use this ajax crud operation in laravel 6, laravel 7. In ajax crud operation we display records in datatable.

Read More : Laravel AJAX CRUD Example Tutorial

https://www.techsolutionstuff.com/post/laravel-ajax-crud-example-tutorial


Read Also : Read Also : Laravel 6 CRUD Tutorial with Example

https://techsolutionstuff.com/post/laravel-6-crud-tutorial-with-example

#laravel ajax crud example tutorial #ajax crud example in laravel #laravel crud example #laravel crud example with ajax #laravel #php

3 Examples Of Design Applications With Great UX

When it comes to design, it has long been said that simplicity is key. And although I always understood the basis for this saying, I never fully appreciated what it really meant.

As a beginner it is natural to want to show all your ability by wowing your audience. And as a teacher I see my students making this mistake often. They try to build out features as much as possible and try to showcase every aspect of their ability. As many of you know, this approach does not always result in the most aesthetically pleasing design, let alone the most user friendly experience. This is why I have stressed the importance of simplicity to all my students from the first day I started teaching.

For our latest project, I assigned teams of 4 to each create a prototype for a design application.

#design #web-design #hackernoon-top-story #ux #good-ux-design-examples #good-ui-design-examples #web-application-ui-examples #web-application-design-example

Tyshawn  Braun

Tyshawn Braun

1599586380

Product Sentiment Classification: Weekend Hackathon

We are back with another weekend hackathon and this weekend we are challenging the machinehack community to build an NLP model to analyze sentiments in the product reviews for various electronic products.

Analyzing sentiments related to various products such as Tablet, Mobile and various other gizmos can be fun and difficult especially when collected across various demographics around the world. In this weekend hackathon, we challenge the machinehackers community to develop a machine learning model to accurately classify various products into 4 different classes of sentiments based on the raw text review provided by the user. Analyzing these sentiments will not only help us serve the customers better but can also reveal a lot of customer traits present/hidden in the reviews.

The challenge will start on 4th Sep Friday at 6 pm IST.

Click here to participate

Problem Statement & Description

The sentiment analysis requires a lot to be taken into account mainly due to the preprocessing involved to represent raw text and make them machine-understandable. Usually, we stem and lemmatize the raw information and then represent it using TF-IDF, Word Embeddings, etc. However, provided the state-of-the-art NLP models such as Transformer based BERT models one can skip the manual feature engineering like TF-IDF and Count Vectorizers.

The dataset collected has close to 9000 rows with 4 columns and the reviews are in the form of raw text. The labels for each review are provided with the training labels such as positive, negative, no sentiment, and can’t be said(neutral sentence).

In this short span of time, we would encourage you to leverage the ImageNet moment (Transfer Learning) in NLP using various pre-trained models to classify the product reviews correctly using Multi-class Log Loss as a metric.

Given are raw customer reviews over various types of products with 4 different sentiment classes. Your objective as a data scientist is to build a natural language processing model that can accurately classify the class of sentiments as close as possible.


#hackathons #machine learning hackathon #machinehack hackathon #machine-learing