Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Calculate = function (totalMonths) {
- RecalculatePerc = function () {
- percentCorrelation.forEach(function (item,i,array) {
- //TODO: Count sum with lambda
- array[i] = item / sum
- });
- }
- AddRemainder = function (remainder,row) {
- row.broker += remainder*percentCorrelation.brokerPerc
- row.pillow += remainder*percentCorrelation.pillowPerc
- row.reserved += remainder*percentCorrelation.reservedPerc
- //TODO: Please make it return null, and work directly with row data as link in C++ or ref in C#
- return row
- }
- //Todo: @DAIMOM refactor to not class
- class Row {
- constructor(data, totalMoney, broker, pillow, reserved, currentAim) {
- this.data = data,
- this.totalMoney = totalMoney,
- this.broker = broker,
- this.pillow = pillow,
- this.reserved = reserved,
- this.currentAim = currentAim
- }
- }
- var percentCorrelation = {
- //Todo(ez): get from data fields
- brokerPerc: 0.7,
- pillowPerc: 0.2,
- reservedPerc: 0.1
- }
- var resultData = []
- //Todo: get from data fields
- resultData.add(new Row(Data.now(),brokerNow+pillowNow+reservedNow,brokerNow,pillowNow,reservedNow,1))
- for (var i = 1; i <= totalMonths; i++) {
- var row = new Row()
- //Todo: refactor into 1 string if possible
- row = resultData[i-1]
- row.data.setMonth(row.data.getMonth()+1)
- row.broker += gain*percentCorrelation.brokerPerc
- row.pillow += gain*percentCorrelation.pillowPerc
- row.reserved += gain*percentCorrelation.reservedPerc
- if(row.pillow > pillowMax){
- percentCorrelation.pillowPerc = 0
- RecalculatePerc()
- var remainder = row.pillow - pillowMax
- row.pillow = pillowMax
- row = AddRemainder(remainder,row)
- }
- if(row.reserved > reservedMax){
- percentCorrelation.reservedPerc = 0
- RecalculatePerc()
- var remainder = row.reserved - reservedMax
- row.reserved = reservedMax
- row = AddRemainder(remainder,row)
- }
- row.totalMoney += gain
- if(row.totalMoney != (row.broker+row.pillow+row.pillow)){
- throw Error("Бюджет не сошёлся!")
- }
- //Todo: make recalculte for different aims
- resultData.add(row)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement