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.
npm run import -- "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))
}
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:
Imports:
importer
: A custom module likely containing utility functions for importing other modules.listEvents
: A function to list events from a Google Calendar.d3Heatmap
: A function to create a heatmap visualization using the D3.js library.Initialization:
options
: An empty object to store configuration options (likely for authentication).now
: A Date
object representing the current time.calendarSearchToHeatmap
Function:
importer.runAllPromises
to concurrently fetch events for each query using listEvents
.d3Heatmap
to generate a heatmap visualization.Module Export:
calendarSearchToHeatmap
function, making it available for use in other parts of the application.Execution:
$
is defined (likely a custom environment variable or object).calendarSearchToHeatmap
function with a list of search queries.$.html
.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.