Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. /**
  2. * A snippet of code I used to compare two petitions on the UK Parliament web site - wanting to know
  3. * which grew fastest to challenge the claim "My Petition Is Bigger Than Yours".
  4. * This input data is from the JSON download from the petition web site.
  5. * A future version of this code could generalise its input to allow a petition to be selected for comparison.
  6. */
  7.  
  8. const data = {
  9. "Revoke Article 50":{
  10. "created_at": "2019-01-29T13:53:56.492Z",
  11. "updated_at": "2019-02-16T22:35:36.886Z",
  12. "rejected_at": null,
  13. "opened_at": "2019-02-11T17:08:20.928Z",
  14. "closed_at": null,
  15. "moderation_threshold_reached_at": "2019-01-29T16:19:13.966Z",
  16. "response_threshold_reached_at": "2019-02-12T07:46:09.405Z",
  17. "government_response_at": null,
  18. "debate_threshold_reached_at": "2019-02-16T15:17:14.708Z",
  19. "scheduled_debate_date": null,
  20. "debate_outcome_at": null,
  21. },
  22. "Hard Brexit":{
  23. "signature_count": 353427,
  24. "created_at": "2018-10-07T22:34:13.115Z",
  25. "updated_at": "2019-02-16T22:37:57.711Z",
  26. "rejected_at": null,
  27. "opened_at": "2018-10-17T09:57:44.028Z",
  28. "closed_at": null,
  29. "moderation_threshold_reached_at": "2018-10-10T10:54:22.833Z",
  30. "response_threshold_reached_at": "2018-11-27T21:28:02.990Z",
  31. "government_response_at": "2018-12-14T09:57:34.136Z",
  32. "debate_threshold_reached_at": "2018-12-15T18:51:04.394Z",
  33. "scheduled_debate_date": "2019-01-14",
  34. "debate_outcome_at": "2019-01-15T12:39:39.423Z"
  35. }
  36. }
  37.  
  38. function report(name) {
  39. const poll = data[name];
  40. const opened_at = new Date(poll.opened_at),
  41. response_threshold_reached_at = new Date(poll.response_threshold_reached_at),
  42. debate_threshold_reached_at = new Date(poll.debate_threshold_reached_at);
  43.  
  44. function toTime(milliseconds) {
  45. let minutes = milliseconds / 1000.0 / 60.0;
  46. let hours = minutes / 60.0;
  47. let days = hours / 24.0;
  48.  
  49. minutes = (minutes % 60).toFixed(1);
  50. hours = (hours % 24).toFixed(0);
  51. days = days.toFixed(0);
  52.  
  53. return `${days} days, ${hours} hours, ${minutes} minutes`;
  54. }
  55.  
  56. console.dir({
  57. "Poll": name,
  58. "Time to reach 10,000": toTime(response_threshold_reached_at - opened_at),
  59. "Time to reach 100,000": toTime(debate_threshold_reached_at - opened_at)
  60. });
  61. }
  62.  
  63. for (name in data) { report(name); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement