Created
April 9, 2020 02:27
-
-
Save yadav26/8cf8ae74b5b47bb87e59408815bd7124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
var express = require('express') | |
const app = express() | |
var rp = require('request-promise'); | |
app.listen(process.env.PORT || 3000) | |
Pools = []; | |
SRPool = []; | |
Selections = []; | |
intCounter = 0; | |
// dates = [["2020-03-16"],["2020-03-19"], ["2020-02-28"],["2020-03-05"],["2020-02-25"],["2020-03-13"],["2020-02-20"],["2020-03-19"] ]; | |
class ValidationInputClass { | |
constructor(counter, input) { | |
// console.log("Constructor : ", input ); | |
this.id = counter; | |
this.inselec = input[0]; | |
this.num_combinations_invested = input[1]; | |
this.assignee = input[2]; | |
this.cashout_amount = input[3]; | |
this.decided_sales_amount = input[4] | |
} | |
} | |
function getDatePrefixZero (s){ | |
var newstr = s.toString().length < 2 ? '0'+s : s; | |
return newstr; | |
} | |
async function CallRequestApi(val_data) { | |
qs = 'http://internal-cca-green-loadbala-6rcp2ko77xxo-1577499540.ap-southeast-2.elb.amazonaws.com:7001/test/offer'; | |
var s = val_data.inselec; | |
var myselections = s.split('/'); | |
var intarr = []; | |
myselections.forEach(row => { | |
tmpint = []; | |
var cols = row.split(","); | |
cols.forEach(col => { | |
if(col.search('-') != -1 ) | |
{//its a range | |
var start = parseInt( col.split('-')[0]); | |
var end = parseInt(col.split('-')[1]); | |
for(let i = start; i <= end; ++i) | |
{ | |
tmpint.push(i); | |
} | |
} | |
else{ | |
tmpint.push(parseInt(col)); | |
} | |
}); | |
intarr.push(tmpint); | |
}); | |
//console.log (intarr); | |
var dt = val_data.assignee.split('('); | |
dt = dt[1].split(')')[0]; | |
var calenderdate = dt.split('-'); | |
var dt = val_data.assignee.split('('); | |
var formatdate = calenderdate[2] + '-'+ getDatePrefixZero(calenderdate[1]) + '-' + getDatePrefixZero(calenderdate[0]) ; | |
var options = { | |
method: 'POST', | |
uri: qs, | |
body: { | |
meetingDate: formatdate, | |
meetingMnemonic: "BR", | |
poolType: "QUADDIE", | |
hostSystem: "VIC", | |
firstLegOfPool: 6, | |
amount: val_data.decided_sales_amount, | |
selections: intarr, | |
fieldLegs: [ | |
false, | |
false, | |
false, | |
false | |
] | |
}, | |
json: true // Automatically stringifies the body to JSON | |
}; | |
let parsedBody = await rp(options); | |
var result = parsedBody.toString(); | |
if(result.search('Error calculating offer') != -1) | |
{ | |
console.log("Error - ", val_data.assignee); | |
return; | |
} | |
var combcnt = result.split("combinationCount="); | |
var combinations = combcnt[1].split("}"); | |
var res = result.split("Total Value: "); | |
var trueValue = res[1].split("\n")[0]; | |
var prtstr = '\n Resulted[' +val_data.id+']' + ' Combinations = ' + combinations[0] + ', True Value = ' + trueValue ; | |
console.log(prtstr); | |
var inputstr = ' Input #[' +val_data.id+']' + ' selections = [' + intarr[0] +'],['+ intarr[1]+'],['+ intarr[2]+'],['+ intarr[3]+'] num_combinations_invested = ' + val_data.num_combinations_invested + ' Amount invested = ' + val_data.decided_sales_amount; | |
// console.log(val_data.id, combinations[0], trueValue, intarr[0], intarr[1], intarr[2], intarr[3], val_data.decided_sales_amount, val_data.num_combinations_invested, val_data.cashout_amount); | |
console.log(inputstr); | |
} | |
(async function () { | |
let data = fs.readFileSync('./../selections_br_nsw.txt'); | |
const content = data.toString(); | |
// Invoke the next step here however you like | |
//console.log(content); // Put all of the code here (not the best solution) | |
var lines = content.split('\r\n'); | |
intCounter = 0; | |
lines.forEach(element => { | |
//do stuff | |
//console.log(element); | |
var cols = element.split(';'); | |
if (cols.length == 5) { | |
var vo = new ValidationInputClass(intCounter++, cols); | |
Selections.push(vo); | |
} | |
}); | |
for (item of Selections) { | |
await CallRequestApi(item); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2020-04-08 13:19:12,515 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:27] Starting Offer Calculation
2020-04-08 13:19:12,517 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:41] Punter Selections: FlexiSelections{selectionList=[[1, 2, 3, 4, 6, 7], [1, 2, 7, 9, 13], [1, 2, 4, 5, 8, 9, 10, 12, 13, 17, 18, 19, 20], [2]], combinationCount=390}
2020-04-08 13:19:12,517 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:42] Paid-for Selections: FlexiSelections{selectionList=[[1, 2, 3, 4, 6, 7], [1, 2, 7, 9, 13], [1, 2, 4, 5, 8, 9, 10, 12, 13, 17, 18, 19, 20], [2]], combinationCount=390}
2020-04-08 13:19:12,517 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:43] Live Selections: FlexiSelections{selectionList=[[6], [1], [18], [2]], combinationCount=1}
2020-04-08 13:19:12,518 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:44] Effective pool total: 873594.488000
2020-04-08 13:19:12,518 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:45] Functioning pool total: 873594.488000
2020-04-08 13:19:12,518 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:46] Flexi Investment: 0.1282
2020-04-08 13:19:12,518 DEBUG [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:169] Extrapolating stored collation of 170.606026 to 170.6060260000
2020-04-08 13:19:12,518 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:200] True probability for Leg 4 runner 2 are: 0.41322312
2020-04-08 13:19:12,518 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:98] Combo: 6 1 18 2, Collation : 170.6060260000, Potential Div: 5120.5, Potential Return: 656.44810, Probability: 0.413223, True Value: 271.2594
2020-04-08 13:19:12,519 INFO [http-nio-7001-exec-10] a.c.c.q.c.c.CashOutCalculator [CashOutCalculator.java:58] Total Value: 271.2594