]> git.sesse.net Git - pkanalytics/commitdiff
Correct counting of global points.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 May 2023 20:40:44 +0000 (22:40 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 May 2023 20:40:44 +0000 (22:40 +0200)
ultimate.js

index b56a856d68016f2a887a700a5b1cb1de4e72a8ce..7fbfa172bf3c189f1dfc9a379eb511d935ee28d3 100644 (file)
@@ -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;