google calendar graphs | test calendar api graph Iga's cycle for as long as there are valid dates | test google calendar search swimlane | Search

This code searches Google Calendar for events matching given keywords and generates a heatmap visualization of the results, showing the frequency of events over time.

Run example

npm run import -- "test google calendar search heatmap"

test google calendar search heatmap

var importer = require('../Core');

var options = {};
var listEvents = importer.import("list events")
var d3Heatmap = importer.import("d3 calendar")

var now = new Date();
function calendarSearchToHeatmap(searches) {
    return importer.runAllPromises(searches
        .map((s, i) => (resolve) => listEvents({
            auth: options.auth,
            calendarId: 'Emotions',
            q: s
        })
            .then(r => {
                //console.log(s);
                //console.log(r.map(e => e.event.start.dateTime));
                resolve(r.map(e => ({
                    id: e.event.id,
                    start: new Date(e.event.start.dateTime),
                    end: new Date(e.event.end.dateTime),
                })));
            })
            .catch(e => console.log(e))))
        .then(r => d3Heatmap(r))
}

module.exports = calendarSearchToHeatmap;

if(typeof $ != 'undefined') {
    $.async();
    
    calendarSearchToHeatmap([
        'coincidence',
        /*
        'work',
        'working',
        'worked',
        'study sauce',
        'portal',
        'renewal',
        'work on sos',
        'jupyter',
        'jupytangular',
        'unit tests',
        'selenium',
        'angular',
        'mind spree',
        '"c#"',
        'docker',
        'quake 3',
        'kernels',
        'notebook',
        'media server',
        */
    ])
        .then(r => $.html(r))
        .catch(e => $.sendError(e))

}

What the code could have been:

const importer = require('../Core');

const options = {
  auth: {}, // TODO: Move auth logic to a separate function for better reusability
};

const { listEvents, runAllPromises, d3Heatmap } = importer;

const calendarSearchToHeatmap = async searches => {
  try {
    const events = await Promise.all(
      searches.map((search, index) =>
        listEvents({
          auth: options.auth,
          calendarId: 'Emotions',
          q: search,
        }).then(response => ({
          id: response.event.id,
          start: new Date(response.event.start.dateTime),
          end: new Date(response.event.end.dateTime),
        }))
      )
    );

    return d3Heatmap(events);
  } catch (error) {
    throw error;
  }
};

module.exports = calendarSearchToHeatmap;

import $ from 'jquery';

if (typeof $!== 'undefined') {
  $(document).ready(() => {
    calendarSearchToHeatmap([
      'coincidence',
      // Add more searches here
    ]).then(response => {
      $('body').html(response);
    }).catch(error => {
      $.sendError(error);
    });
  });
}

This code fetches and visualizes Google Calendar events based on provided search queries.

Here's a breakdown:

  1. Imports:

  2. Initialization:

  3. calendarSearchToHeatmap Function:

  4. Module Export:

  5. Execution:

In essence, this code provides a way to search Google Calendar for events based on keywords and visualize the results as a heatmap, allowing for a visual representation of event occurrences over time.