Created
November 4, 2015 02:40
-
-
Save nkijak/fdcb4d8a75dff13ac58e to your computer and use it in GitHub Desktop.
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
var events = [{"event": circuitStarted, value: { name: "A"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 1", "count": 150}, when:<timestamp>} | |
{"event": circuitStarted, value: { name: "B"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 2", "count": 20}, when:<timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 3", "count": 6}, when:<timestamp>} | |
{"event": circuitComplete, value: { name: "B"}, when: <timestamp>} | |
{"event": circuitStarted, value: { name: "B"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 2", "count": 18}, when:<timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 3", "count": 5}, when:<timestamp>} | |
{"event": circuitComplete, value: { name: "B"}, when: <timestamp>} | |
{"event": circuitComplete, value: { name: "A"}, when: <timestamp>} | |
{"event": circuitStarted, value: { name: "A"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 1", "count": 145}, when:<timestamp>} | |
{"event": circuitStarted, value: { name: "B"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 2", "count": 18}, when:<timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 3", "count": 5}, when:<timestamp>} | |
{"event": circuitComplete, value: { name: "B"}, when: <timestamp>} | |
{"event": circuitStarted, value: { name: "B"}, when: <timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 2", "count": 17}, when:<timestamp>} | |
{"event": exerciseComplete, value: {id: "exID 3", "count": 4}, when:<timestamp>} | |
{"event": circuitComplete, value: { name: "B"}, when: <timestamp>} | |
{"event": circuitComplete, value: { name: "A"}, when: <timestamp>}] | |
function Report() { | |
} | |
Report.Replayer = function() { | |
var replayerSelf = this; | |
var _state = {totalscore: 0, curcuits: []}; | |
this.circuitStarted = function(value) { | |
_state.curcuits.push({"name": value.name, "score":0, "curcuits":[]}); | |
} | |
this.circuitComplete = function(value) { | |
var circuit = _state.curcuits.pop(); | |
_state.curcuits.peek().curcuits.push(circuit); | |
} | |
this.exerciseComplete = function(value) { | |
_state.curcuits.peek().score += value.count; | |
_state.totalscore += value.count; | |
} | |
} | |
var replayer = new Report.Replayer() | |
for (var event in events) { | |
replayer[event.event](event.value); | |
} | |
logJson(replayer._state); | |
//{totalscore: 388, curcuits:[ | |
// {name: A, score: 49, curcuits: [ | |
// {name: B, score: 26, curcuits:[]} | |
// {name: B, score: 23, curcuits:[]} | |
// ]}, | |
// {name: A, score: 44, curcuits: [ | |
// {name: B, score: 23, curcuits:[]} | |
// {name: B, score: 21, curcuits:[]} | |
// ]} | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can change this.exerciseComplete to record exercises too:
Giving something like