Example #1
0
 return monthsBetween(options.start, options.end).map(m => {
   const record = {};
   // Add the potentially new (but possibly overwritten based on options) fields
   record[rangeField] = yyyymmdd(m);
   record[accField] = sparseCounts[yyyymmdd(m)] || (options.fillLast ? prevVal:0);
   prevVal = sparseCounts[yyyymmdd(m)];
   return record;
 });
Example #2
0
 const sparseCounts = data.reduce((m, e) => {
   let date_of = null;
   // Try date first (note, sometimes this is not a truncated date)
   if (e.date !== undefined) {
     date_of = new Date(e.date)
   }
   // Try month and year (many count results will use this instead due to SQL group by clauses)
   if (e.year !== undefined && e.month !== undefined) {
     date_of = new Date(`${e.year}/${e.month}/01`);
   }
   // If a specific dateKey was provided
   if (dateKey && e[dateKey] !== undefined) {
     date_of = new Date(e[dateKey]);
   }
   
   if (date_of && e[acc]) {
     m[yyyymmdd(date_of)] = e[acc];
   }
   return m;
 }, {});