Skip to content

Commit

Permalink
Merge pull request #37 from actusfrf/dev
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
nbundi authored Aug 10, 2020
2 parents ec9b134 + dd41f0b commit 28138b8
Show file tree
Hide file tree
Showing 7 changed files with 1,975 additions and 647 deletions.
2,566 changes: 1,961 additions & 605 deletions frontend/public/data/actus-dictionary.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/src/components/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class Form extends PureComponent {
}

// get contract identifier from id (accronym)
let identifier = Object.keys(res.data.taxonomy).filter(key => (res.data.taxonomy[key].accronym.indexOf(id) > -1))[0];
let identifier = Object.keys(res.data.taxonomy).filter(key => (res.data.taxonomy[key].acronym.indexOf(id) > -1))[0];

// get taxonomy, applicability and terms lists for respective contract
let applicability = res.data.applicability[identifier]
Expand Down Expand Up @@ -276,7 +276,7 @@ export class Form extends PureComponent {
originalRequiredFields: {...mandatoryFieldIdentifiers},
originalNonRequiredFields: {...optionalFieldIdentifiers},
groupDescription: taxonomy.description,
contractType: taxonomy.accronym,
contractType: taxonomy.acronym,
identifier: identifier,
error: {
...this.state.error
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Landing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Landing extends PureComponent {
{
Object.keys(contracts).map( (key) =>
<Contract key={key}
contractType={contracts[key].accronym}
contractType={contracts[key].acronym}
name={contracts[key].name}
description={contracts[key].description} />
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/ACTUS Webapp.postman_collection.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.actus.webapp.controllers;

import org.actus.webapp.models.Demo;
import org.actus.webapp.models.DemoMeta;
import org.actus.webapp.repositories.DemoRepository;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
Expand Down
25 changes: 5 additions & 20 deletions src/main/java/org/actus/webapp/controllers/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public double stateAt(String id, LocalDateTime time, StateSpace contractStates,
public List<Event> solveContract(@RequestBody Map<String, Object> json) {

// extract contract terms from body
ContractModel terms = extractTerms(json);
ContractModel terms = ContractModel.parse(json);

// define (empty) risk factor observer
MarketModel observer = new MarketModel();
Expand All @@ -78,38 +78,23 @@ public List<EventStream> solveContractBatch(@RequestBody ActusData json) {
contractData.forEach(entry -> {
// extract contract terms
ContractModel terms;
String contractId = (entry.get("contractId") == null)? "NA":entry.get("contractId").toString();
String contractId = (entry.get("contractID") == null)? "NA":entry.get("contractID").toString();
try {
terms = extractTerms(entry);
terms = ContractModel.parse(entry);
} catch(Exception e){
output.add(new EventStream(contractId, "Failure", e.toString(), new ArrayList<Event>()));
return; // skipt this iteration and continue with next
}
// compute contract events
try {
output.add(new EventStream(entry.get("contractId").toString(), "Success", "", computeEvents(terms, observer)));
output.add(new EventStream(contractId, "Success", "", computeEvents(terms, observer)));
}catch(Exception e){
output.add(new EventStream(entry.get("contractId").toString(), "Failure", e.toString(), new ArrayList<Event>()));
output.add(new EventStream(contractId, "Failure", e.toString(), new ArrayList<Event>()));
}
});
return output;
}

private ContractModel extractTerms(Map<String,Object> json) {
// convert json terms object to a java map (required input for actus model parsing)
Map<String, String> map = new HashMap<String, String>();
for (Map.Entry<String, Object> entry : json.entrySet()) {

System.out.println(entry.getKey() + ":" + entry.getValue());

// capitalize input json keys as required in contract model parser
map.put(entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1), entry.getValue().toString());
}

// parse attributes
return ContractModel.parse(map);
}

private RiskFactorModelProvider createObserver(List<ObservedData> json) {
MarketModel observer = new MarketModel();

Expand Down
20 changes: 5 additions & 15 deletions src/main/java/org/actus/webapp/models/Event.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package org.actus.webapp.models;

import java.time.LocalDateTime;
import java.util.Map;

import org.actus.events.ContractEvent;
//import org.json.JSONObject;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.databind.JsonNode;

import org.springframework.data.mongodb.core.mapping.Field;


Expand All @@ -29,13 +19,13 @@ public Event() {
}

public Event(ContractEvent event) {
this.type = event.type();
this.time = event.time().toString();
this.type = event.eventType().toString();
this.time = event.eventTime().toString();
this.payoff = event.payoff();
this.currency = event.currency();
this.nominalValue = event.states()[1];
this.nominalRate = event.states()[3];
this.nominalAccrued = event.states()[2];
this.nominalValue = event.states().notionalPrincipal;
this.nominalRate = event.states().nominalInterestRate;
this.nominalAccrued = event.states().accruedInterest;
}

public String getType() {
Expand Down

0 comments on commit 28138b8

Please sign in to comment.