Exemplo n.º 1
0
 return map(w, (wi, j) => {
   const bounds = timewindow.timeWindowBounds(new Date(processed),
     dimensions[i], -j);
   return wi ? sfn ? extend({}, wi, {
     summary: sfn(t, wi.quantity, bounds.from, bounds.to)
   }) : extend({}, wi) : null;
 });
Exemplo n.º 2
0
          const quantities = map(w, (tw, j) => {
            const bounds = timewindow.timeWindowBounds(new Date(now),
              dimensions[i], -j);
            const current = tw && tw.quantity && tw.quantity.current ?
              tw.quantity.current : 0;
            const accumulated = accumfn(mplan.metering_plan.metrics, mu.metric)
              (current, mu.quantity, u.start, u.end, bounds.from, bounds.to,
                getCell);

            // Do not accumulate if the function returns null
            if(accumulated === null) {
              debug('No accumulation in window %d index %d', i, j);
              return tw ? extend({}, tw) : null;
            }

            // Switch old current to previous in previously accumulated windows
            if(tw && tw.quantity && tw.quantity.current) {
              debug('Accumulating window %d index %d' +
                ' new quantity %o old quantity %o', i, j, tw, mu);
              return {
                quantity: {
                  previous: tw.quantity.current,
                  current: accumulated
                }
              };
            }

            // Create a new accumulated object at the window
            debug('New window %d index %d new quantity %o', i, j, tw);
            return {
              quantity: {
                current: accumulated
              }
            };
          });
Exemplo n.º 3
0
 return map(w, (s, j) => {
   // Calculate the from and to bounds of the window
   const bounds = timewindow.timeWindowBounds(new Date(processed),
     dimensions[i], -j);
   // Return the charge, return null if it's undefined
   return s ? cfn ? extend({}, s, {
     charge: cfn(t, s.cost, bounds.from, bounds.to)
   }) : extend({}, s) : null;
 });