X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=events.h;h=df5fcb6a9b8c8b08871f2d76ef7804a5501652f7;hb=daa040b3caa306ecbc1a3e8d312250ed331a1870;hp=66398d1d567eb1d941f1db83c4a1c98ad298a188;hpb=8761ac364a5361a75a03fdcc0bb780764aa99e86;p=pkanalytics diff --git a/events.h b/events.h index 66398d1..df5fcb6 100644 --- a/events.h +++ b/events.h @@ -7,15 +7,15 @@ #include #include #include +#include class EventsModel : public QAbstractTableModel { public: - EventsModel(sqlite3 *db) : db(db) {} + EventsModel(sqlite3 *db, int match_id); int rowCount(const QModelIndex &parent) const override { - refresh_if_needed(); return events.size(); } int columnCount(const QModelIndex &column) const override @@ -25,7 +25,38 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &index, int role) const override; - int insert_event(uint64_t t, int player_id); + unsigned insert_event(uint64_t t, std::optional player_id, std::optional formation_id, const std::string &type = "unknown"); // Returns the row. + void delete_event(unsigned row); + std::string get_event_type(unsigned row) { return events[row].type; } + void set_event_type(unsigned row, const std::string &type); + void set_event_formation(unsigned row, int formation_id); + uint64_t get_time(unsigned row) { return events[row].t; } + unsigned get_last_event_pos(uint64_t t) const; // Last event that happened at or before t. + QModelIndex get_last_event_qt(uint64_t t) const { + return createIndex(get_last_event_pos(t), 0); + } + std::optional get_player_id(unsigned row) { return events[row].player_id; } + + struct Status { + unsigned our_score, their_score; + enum { NOT_STARTED, OFFENSE, DEFENSE } attack_state; + unsigned offensive_formation, defensive_formation; + bool stoppage; + enum { NOT_PULLING, SHOULD_PULL, PULL_IN_AIR } pull_state; + unsigned num_passes; + unsigned possession_sec; + unsigned stoppage_sec; + }; + Status get_status_at(uint64_t t); + std::set get_team_at(uint64_t t); + void set_team_at(uint64_t, const std::set &new_team); + std::vector sort_team(const std::set &team) const; // Ordered first by gender, then by number. + void set_formation_at(uint64_t t, bool offense, unsigned formation); + + // Used to notify when we've inserted a new one into the database. + void inserted_new_formation(int formation_id, const std::string &name) { + formations[formation_id] = Formation{ formation_id, name }; + } private: struct Player { @@ -33,19 +64,28 @@ private: std::string number; std::string name; }; - mutable std::map players; + std::map players; + std::map player_ordering; // From id to position. + + struct Formation { + int formation_id; + std::string name; + }; + std::map formations; struct Event { + int event_id; uint64_t t; std::optional player_id; + std::optional formation_id; std::string type; }; - mutable std::vector events; - mutable bool stale = true; + std::vector events; sqlite3 *db; + int match_id; - void refresh_if_needed() const; + void load_data(); }; #endif // !defined(_EVENTS_H)