Skip to content

Instantly share code, notes, and snippets.

@m0rjc
Created February 19, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0rjc/e1c22546ffa533c0de55a7a351c7d725 to your computer and use it in GitHub Desktop.
Save m0rjc/e1c22546ffa533c0de55a7a351c7d725 to your computer and use it in GitHub Desktop.
/**
* A snippet of code I used to compare two petitions on the UK Parliament web site - wanting to know
* which grew fastest to challenge the claim "My Petition Is Bigger Than Yours".
* This input data is from the JSON download from the petition web site.
* A future version of this code could generalise its input to allow a petition to be selected for comparison.
*/
const data = {
"Revoke Article 50":{
"created_at": "2019-01-29T13:53:56.492Z",
"updated_at": "2019-02-16T22:35:36.886Z",
"rejected_at": null,
"opened_at": "2019-02-11T17:08:20.928Z",
"closed_at": null,
"moderation_threshold_reached_at": "2019-01-29T16:19:13.966Z",
"response_threshold_reached_at": "2019-02-12T07:46:09.405Z",
"government_response_at": null,
"debate_threshold_reached_at": "2019-02-16T15:17:14.708Z",
"scheduled_debate_date": null,
"debate_outcome_at": null,
},
"Hard Brexit":{
"signature_count": 353427,
"created_at": "2018-10-07T22:34:13.115Z",
"updated_at": "2019-02-16T22:37:57.711Z",
"rejected_at": null,
"opened_at": "2018-10-17T09:57:44.028Z",
"closed_at": null,
"moderation_threshold_reached_at": "2018-10-10T10:54:22.833Z",
"response_threshold_reached_at": "2018-11-27T21:28:02.990Z",
"government_response_at": "2018-12-14T09:57:34.136Z",
"debate_threshold_reached_at": "2018-12-15T18:51:04.394Z",
"scheduled_debate_date": "2019-01-14",
"debate_outcome_at": "2019-01-15T12:39:39.423Z"
}
}
function report(name) {
const poll = data[name];
const opened_at = new Date(poll.opened_at),
response_threshold_reached_at = new Date(poll.response_threshold_reached_at),
debate_threshold_reached_at = new Date(poll.debate_threshold_reached_at);
function toTime(milliseconds) {
let minutes = milliseconds / 1000.0 / 60.0;
let hours = minutes / 60.0;
let days = hours / 24.0;
minutes = (minutes % 60).toFixed(1);
hours = (hours % 24).toFixed(0);
days = days.toFixed(0);
return `${days} days, ${hours} hours, ${minutes} minutes`;
}
console.dir({
"Poll": name,
"Time to reach 10,000": toTime(response_threshold_reached_at - opened_at),
"Time to reach 100,000": toTime(debate_threshold_reached_at - opened_at)
});
}
for (name in data) { report(name); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment