diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-08-08 16:09:33 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-08-08 16:09:33 +0200 |
| commit | 053a2a3f09d24784223ef8c7e8aea812df512518 (patch) | |
| tree | e9a97edc6da4327d07b5bf77d255563a04c6bb22 | |
| parent | 02271d6d72e711201a7a3295a2b28d6427badbb5 (diff) | |
| download | telesucker-053a2a3f09d24784223ef8c7e8aea812df512518.tar.gz telesucker-053a2a3f09d24784223ef8c7e8aea812df512518.zip | |
optimize game phase split, comparing strings instead of datesrelease/2.16.0
| -rw-r--r-- | worker.js | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -72,23 +72,27 @@ amqp.connect(RABBITMQ_URI).then(async (rabbit) => { spawn_time = moment(spawn.time); const forward_profiler = logger.startTimer(); + // return telemetry { m_a_id, data, start, end } in an interval - const gamePhase = (start, end) => { return { - match_api_id: match_api_id, - data: telemetry.slice( - // assumes Telemetry is ordered by timestamp. - telemetry.findIndex((ev) => - moment(ev.time).isSameOrAfter( - spawn_time.clone().add(start, "seconds") - ) ), - telemetry.findIndex((ev) => - moment(ev.time).isSameOrAfter( - spawn_time.clone().add(end, "seconds") - ) ) // slice does not include end - ), - start: start, - match_start: spawn.time, - end: end + const gamePhase = (start, end) => { + let spawn_plus_start = spawn_time.clone() + .add(start, "seconds") + .format("YYYY-MM-DDTHH:mm:ss") + "+0000", + spawn_plus_end = spawn_time.clone() + .add(end, "seconds") + .format("YYYY-MM-DDTHH:mm:ss") + "+0000"; + return { + match_api_id: match_api_id, + data: telemetry.slice( + // assumes Telemetry is ordered by timestamp, + // assumes it uses the format as above + telemetry.findIndex((ev) => !(ev.time<spawn_plus_start)), + telemetry.findIndex((ev) => !(ev.time<spawn_plus_end)) + // slice does not include end + ), + start: start, + match_start: spawn.time, + end: end } }; // split into phases const phases = [ |
