Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. Calculate = function (totalMonths) {
  2. RecalculatePerc = function () {
  3. percentCorrelation.forEach(function (item,i,array) {
  4. //TODO: Count sum with lambda
  5. array[i] = item / sum
  6. });
  7. }
  8.  
  9. AddRemainder = function (remainder,row) {
  10. row.broker += remainder*percentCorrelation.brokerPerc
  11. row.pillow += remainder*percentCorrelation.pillowPerc
  12. row.reserved += remainder*percentCorrelation.reservedPerc
  13. //TODO: Please make it return null, and work directly with row data as link in C++ or ref in C#
  14. return row
  15. }
  16.  
  17. //Todo: @DAIMOM refactor to not class
  18. class Row {
  19. constructor(data, totalMoney, broker, pillow, reserved, currentAim) {
  20. this.data = data,
  21. this.totalMoney = totalMoney,
  22. this.broker = broker,
  23. this.pillow = pillow,
  24. this.reserved = reserved,
  25. this.currentAim = currentAim
  26. }
  27. }
  28.  
  29. var percentCorrelation = {
  30. //Todo(ez): get from data fields
  31. brokerPerc: 0.7,
  32. pillowPerc: 0.2,
  33. reservedPerc: 0.1
  34. }
  35.  
  36. var resultData = []
  37. //Todo: get from data fields
  38. resultData.add(new Row(Data.now(),brokerNow+pillowNow+reservedNow,brokerNow,pillowNow,reservedNow,1))
  39. for (var i = 1; i <= totalMonths; i++) {
  40. var row = new Row()
  41. //Todo: refactor into 1 string if possible
  42. row = resultData[i-1]
  43. row.data.setMonth(row.data.getMonth()+1)
  44. row.broker += gain*percentCorrelation.brokerPerc
  45. row.pillow += gain*percentCorrelation.pillowPerc
  46. row.reserved += gain*percentCorrelation.reservedPerc
  47.  
  48.  
  49. if(row.pillow > pillowMax){
  50. percentCorrelation.pillowPerc = 0
  51. RecalculatePerc()
  52. var remainder = row.pillow - pillowMax
  53. row.pillow = pillowMax
  54. row = AddRemainder(remainder,row)
  55. }
  56. if(row.reserved > reservedMax){
  57. percentCorrelation.reservedPerc = 0
  58. RecalculatePerc()
  59. var remainder = row.reserved - reservedMax
  60. row.reserved = reservedMax
  61. row = AddRemainder(remainder,row)
  62. }
  63.  
  64. row.totalMoney += gain
  65. if(row.totalMoney != (row.broker+row.pillow+row.pillow)){
  66. throw Error("Бюджет не сошёлся!")
  67. }
  68.  
  69. //Todo: make recalculte for different aims
  70. resultData.add(row)
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement