From 6499130957e9afc9a28ec3a610fa3721f0f34fd1 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 May 2023 23:46:32 +0200 Subject: [PATCH] Count time spent in stoppage --- events.cpp | 17 ++++++++++++++++- events.h | 1 + main.cpp | 8 +++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/events.cpp b/events.cpp index 2ed6649..a87d83c 100644 --- a/events.cpp +++ b/events.cpp @@ -233,6 +233,8 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) s.offense = true; s.stoppage = false; uint64_t last_gained_possession = 0; + uint64_t last_stoppage = 0; + uint64_t time_spent_in_stoppage = 0; unsigned num_touches = 0; for (const Event &e : events) { if (e.t > t) { @@ -251,6 +253,7 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) if (e.type == "catch") { if (num_touches == 0) { // Pick up. last_gained_possession = e.t; + time_spent_in_stoppage = 0; } ++num_touches; } @@ -258,10 +261,12 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) num_touches = 1; s.offense = true; last_gained_possession = e.t; + time_spent_in_stoppage = 0; } if (e.type == "defense" || e.type == "their_throwaway") { s.offense = true; num_touches = 0; + time_spent_in_stoppage = 0; } if (e.type == "drop" || e.type == "throwaway") { s.offense = false; @@ -269,13 +274,23 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) } if (e.type == "stoppage") { s.stoppage = true; + last_stoppage = e.t; } if (e.type == "restart") { s.stoppage = false; + if (last_stoppage != 0) { + time_spent_in_stoppage += (e.t - last_stoppage); + last_stoppage = 0; + } } } + if (s.stoppage && last_stoppage != 0) { + time_spent_in_stoppage += (t - last_stoppage); + } + s.num_passes = (num_touches == 0) ? 0 : num_touches - 1; - s.possession_sec = (s.offense && last_gained_possession != 0 && num_touches != 0) ? (t - last_gained_possession) / 1000 : 0; + s.possession_sec = (s.offense && last_gained_possession != 0 && num_touches != 0) ? (t - last_gained_possession - time_spent_in_stoppage) / 1000 : 0; + s.stoppage_sec = (s.offense && last_gained_possession != 0 && num_touches != 0) ? time_spent_in_stoppage / 1000 : 0; return s; } diff --git a/events.h b/events.h index d0f5b19..cd77004 100644 --- a/events.h +++ b/events.h @@ -37,6 +37,7 @@ public: bool stoppage; unsigned num_passes; unsigned possession_sec; + unsigned stoppage_sec; }; Status get_status_at(uint64_t t); std::set get_team_at(uint64_t t); diff --git a/main.cpp b/main.cpp index 7b139b0..a01b572 100644 --- a/main.cpp +++ b/main.cpp @@ -249,7 +249,13 @@ void MainWindow::update_status(uint64_t t) char buf[256]; snprintf(buf, sizeof(buf), "%d–%d | %s | %d passes, %d sec possession", s.our_score, s.their_score, s.offense ? "offense" : "defense", s.num_passes, s.possession_sec); - ui->status->setText(buf); + if (s.stoppage_sec > 0) { + char buf2[256]; + snprintf(buf2, sizeof(buf2), "%s (plus %d sec stoppage)", buf, s.stoppage_sec); + ui->status->setText(buf2); + } else { + ui->status->setText(buf); + } } void MainWindow::update_player_buttons(uint64_t t) -- 2.39.2