From: Steinar H. Gunderson Date: Wed, 10 May 2023 20:40:44 +0000 (+0200) Subject: Correct counting of global points. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d891df4899f9e619c3b3416e8964fb88c4452ebf;hp=258fdeb237f0c821cfae94442ae94b62ddf2d0af;p=pkanalytics Correct counting of global points. --- diff --git a/ultimate.js b/ultimate.js index b56a856..7fbfa17 100644 --- a/ultimate.js +++ b/ultimate.js @@ -93,6 +93,8 @@ function process_matches(json) { let globals = players['globals']; for (const match of json['matches']) { + let our_score = 0; + let their_score = 0; let handler = null; let prev_handler = null; let live_since = null; @@ -122,12 +124,17 @@ function process_matches(json) { // Liveness management if (type === 'pull' || type === 'their_pull' || type === 'restart') { live_since = t; + } else if (type === 'catch' && last_pull_was_ours === null) { + // Someone forgot to add the pull, so we'll need to wing it. + console.log('Missing pull on ' + our_score + '\u2013' + their_score + ' in ' + match['description'] + '; pretending to have one.'); + live_since = t; + last_pull_was_ours = !offense; } else if (type === 'goal' || type === 'their_goal' || type === 'stoppage') { for (const [q,p] of Object.entries(players)) { if (p.on_field_since === null) { continue; } - if (p.last_point_seen !== point_num) { + if (type !== 'stoppage' && p.last_point_seen !== point_num) { // In case the player did nothing this point, // not even subbing in. p.last_point_seen = point_num; @@ -135,38 +142,50 @@ function process_matches(json) { } attribute_player_time(p, t, live_since); + if (type !== 'stoppage') { + if (last_pull_was_ours === true) { // D point. + ++p.defensive_points_completed; + if (type === 'goal') { + ++p.defensive_points_won; + } + } else if (last_pull_was_ours === false) { // O point. + ++p.offensive_points_completed; + if (type === 'goal') { + ++p.offensive_points_won; + } + } + } + } + + if (type !== 'stoppage') { + // Update globals. + ++globals.points_played; if (last_pull_was_ours === true) { // D point. - ++p.defensive_points_completed; + ++globals.defensive_points_completed; if (type === 'goal') { - ++p.defensive_points_won; + ++globals.defensive_points_won; } } else if (last_pull_was_ours === false) { // O point. - ++p.offensive_points_completed; + ++globals.offensive_points_completed; if (type === 'goal') { - ++p.offensive_points_won; + ++globals.offensive_points_won; } } } - - // Update globals. - ++globals.points_played; if (live_since !== null) { globals.playing_time_ms += t - live_since; } - if (last_pull_was_ours === true) { // D point. - ++globals.defensive_points_completed; - if (type === 'goal') { - ++globals.defensive_points_won; - } - } else if (last_pull_was_ours === false) { // O point. - ++globals.offensive_points_completed; - if (type === 'goal') { - ++globals.offensive_points_won; - } - } + live_since = null; } + // Score management + if (type === 'goal') { + ++our_score; + } else if (type === 'their_goal') { + ++their_score; + } + // Point count management if (p !== undefined && type !== 'out' && p.last_point_seen !== point_num) { p.last_point_seen = point_num;