Skip to content

Instantly share code, notes, and snippets.

@hitman99
Created June 11, 2019 08:52
Show Gist options
  • Save hitman99/ba924b3c69fe4603ff0376c8cb1308ec to your computer and use it in GitHub Desktop.
Save hitman99/ba924b3c69fe4603ff0376c8cb1308ec to your computer and use it in GitHub Desktop.
const outage_avg = ()=>{
const incidents = [...document.querySelectorAll('.incident-list')].map(node => [...node.querySelectorAll('.secondary.color-secondary')]);
let avg = incidents.map(inciList => {
return inciList.reduce( (acc , inci) => {
const timestamps = inci.innerText.substr(0, inci.innerText.length - 4).split('-');
if (timestamps[1].indexOf(',') == -1) {
timestamps[1] = `${timestamps[0].split(',')[0]},${timestamps[1]}`;
}
acc.count++;
acc.average += (new Date(timestamps[1]).getTime() - new Date(timestamps[0]).getTime()) / 60000;
if (acc.month.length == 0) {
acc.month = timestamps[0].split(' ')[0];
}
return acc;
}, {count: 0, average: 0, month: ""} );
});
console.table(avg.map(mavg => {
return [mavg.month, Math.floor(mavg.average/mavg.count), mavg.count];
}).reverse());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment