function displayHeatmapSessionHourOfDay()

in src/lambda_functions/cw_custom_widget_nodejs/widgets/heatmap.js [89:119]


function displayHeatmapSessionHourOfDay({ widgetContext, queryResults }) {
  const {
    timeRange: { start, end },
  } = widgetContext;
  // at least four hours
  if ((end - start) / 1000 / 60 / 60 < 4) {
    return '<pre class="error">Time range should be greater than 4 hours</pre>';
  }
  const data = queryResults
    .map((x) => x.reduce((a, c) => ({ [c.field]: c.value, ...a }), {}))
    .map((x) => {
      const d = new Date(x['@t']);
      return {
        // TODO handle locales
        group: d.toLocaleString('en-US', { weekday: 'short' }),
        variable: `0${d.getHours()}`.slice(-2),
        value: Number(x['@count']),
      };
    });

  // TODO locale
  const groups = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  const vars = ['00', '02', '04', '06', '08', '10', '12', '14', '16', '18', '20', '22'];

  return displayHeatMap({
    data,
    widgetContext,
    groups,
    vars,
  });
}