This Gist was automatically created by Carbide, a free online programming environment.
Last active
December 5, 2017 20:48
-
-
Save carbide-public/153c5843d8ddb50e2ea3c375a8dc31de to your computer and use it in GitHub Desktop.
untitled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g = [{"date":"2017-11-09T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Protect Site","timestamp":"2017-11-09T18:35:18.117176Z"}]}]},{"date":"2017-11-10T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-10T17:46:36.541212Z"}]}]},{"date":"2017-11-14T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-14T18:02:06.240847Z"}]}]},{"date":"2017-11-15T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-15T01:27:08.243900Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-15T23:14:44.785836Z"}]}]},{"date":"2017-11-17T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-17T20:44:48.150898Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-17T22:05:47.592787Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-17T22:16:54.742046Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-17T22:27:17.560401Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-17T22:35:58.936860Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-17T23:08:47.253747Z"}]}]},{"date":"2017-11-18T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-18T00:48:50.250172Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-18T00:59:36.916522Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-18T01:38:46.274285Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-18T01:53:30.364902Z"}]}]},{"date":"2017-11-20T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-20T17:45:40.140478Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-20T18:20:40.151288Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-20T18:54:15.148189Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-20T19:05:42.275912Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-20T19:13:24.523649Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-20T19:21:07.101239Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-20T21:07:20.978094Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-20T21:54:36.627376Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-20T23:05:35.132857Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-20T23:13:18.596115Z"}]}]},{"date":"2017-11-21T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-21T00:29:44.669314Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-21T01:50:13.075754Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-21T02:21:43.263596Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-21T02:34:00.290377Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-21T17:32:32.882787Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-21T22:58:31.589861Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-21T23:32:55.673555Z"}]}]},{"date":"2017-11-27T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-27T18:53:05.992724Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-27T20:51:39.428265Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-27T23:44:01.589584Z"}]}]},{"date":"2017-11-28T00:00:00Z","incidents":[{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-28T01:23:33.570090Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-28T17:09:34.400165Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-28T17:17:26.308111Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-28T17:26:37.073853Z"}]},{"updates":[{"description":"Version 0.2: More Better Protection","status":"Update Site","timestamp":"2017-11-28T17:43:11.922524Z"}]},{"updates":[{"description":"Version 0.3: Protection Etcetera","status":"Update Site","timestamp":"2017-11-28T18:14:18.360420Z"}]}]}] | |
function findDayIndex(day,data) { | |
let dates = data.map((obj) => obj.date); | |
return dates.indexOf(day); | |
} | |
function outOfData(ptr,data) { | |
let idx = findDayIndex(ptr.day, data); | |
if (idx < (data.length - 1)) { | |
return false; | |
} | |
return ptr.dayIndex >= data[idx].incidents.length - 1; | |
} | |
function movePointerForward(ptr,data) { | |
let idx = findDayIndex(ptr.day, data); | |
if (ptr.dayIndex < data[idx].incidents.length - 1) { | |
return {'day':ptr.day, 'dayIndex':ptr.dayIndex + 1} | |
} else { | |
return {'day':data[idx+1].date, 'dayIndex':0} | |
} | |
} | |
function movePointer(n, ptr, data) { | |
let newPtr = {'day':ptr.day, 'dayIndex':ptr.dayIndex}; | |
let haveEnoughData = true; | |
for (let i = 0; i < n; i++ && haveEnoughData) { | |
newPtr = movePointerForward(newPtr, data); | |
haveEnoughData = !outOfData(newPtr,data); | |
} | |
return newPtr; | |
} | |
function calcLimit (data, limit, offset) { | |
let index = 0; | |
let ptr = {'day':data[0].date,'dayIndex':0} | |
for(;index < offset && !outOfData(ptr,data); index++) { | |
} | |
} | |
let foo = "2017-11-14T00:00:00Z"; | |
let foo2 = "2017-11-28T00:00:00Z" | |
let point = {'day':foo, 'dayIndex':0} | |
let point2 = {'day':foo2, 'dayIndex':0} | |
let point3 = {'day':foo2, 'dayIndex':5} | |
let zdates = g.map((obj) => obj.date); | |
zdates.indexOf(foo) | |
findDayIndex(foo2, g) | |
g.length - 1 | |
outOfData(point,g) | |
outOfData(point2,g) | |
outOfData(point3,g) | |
point | |
let a = movePointerForward(point,g) | |
let b = movePointerForward(a,g) | |
let c = movePointerForward(b, g) | |
let d = movePointerForward(c, g) | |
let e = movePointerForward(d, g) | |
let z = movePointer(5,point,g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment