· 5 years ago · Jul 06, 2020, 08:04 PM
1 calculateMt(row) {
2 const initialVariables = Object.keys(row).reduce((acc, val) => {
3 acc[val] = row[val].value;
4 return acc;
5 }, {});
6
7 const composedVariables = Object.keys(this.vars).reduce((acc, val) => {
8 acc[val] = this.vars[val].value;
9 return acc;
10 }, initialVariables);
11
12 const h = window.btoa(JSON.stringify(composedVariables));
13 const isCalcuated = this.alreadyCalculatedMts.filter(current => {
14 return current.key == h
15 });
16
17 if(isCalcuated.length < 1) {
18 //console.log("PEGANDOLE A LA API");
19 api.getMt({
20 account_scenario_id: this.scenarioID,
21 variables: composedVariables
22 }).then((response) => {
23 const tmp = { key: h, values: response.data };
24 this.alreadyCalculatedMts.push(tmp);
25 return tmp
26 });
27 }else{
28 return [ isCalcuated[0].values.mt, isCalcuated[0].values.mo ];
29 }
30 },