#!/usr/bin/env node /* * Analyse poll requests from the demo server to see if cht-gateway is waking * up as expected on a particular device. * * Use: * curl https://medic-gateway-demo-server.herokuapp.com/ | jq -r '.datastore.requests[].time' | scripts/analyse_poll_intervals * * Options: * -d | --discard= number of timestamps to discard from the start of the list */ const SS = require('simple-statistics'); const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin }); //> PROCESS ARGS var i, discard = 0; for(i=0; i { timestamps.unshift(new Date(line).getTime()); }); rl.on('close', () => { // If user has requested to discard some of the early timestamps, do this now. // This is useful if the initial timestamps are anomalous. while(discard--) timestamps.shift(); const single_diffs = [], double_diffs = []; var i; for(i=1; i 1) double_diffs[i-2] = (timestamps[i] - timestamps[i-2]) / 1000; } console.log('Timestamps: ' + timestamps.length); report('SINGLE DIFFS', single_diffs); report('DOUBLE DIFFS', double_diffs); console.log('Finished.'); });