]> git.sesse.net Git - pkanalytics/blob - events.h
Fix pull button availability.
[pkanalytics] / events.h
1 #ifndef _EVENTS_H
2 #define _EVENTS_H 1
3
4 #include <sqlite3.h>
5 #include <stdint.h>
6 #include <QAbstractTableModel>
7 #include <map>
8 #include <vector>
9 #include <optional>
10 #include <set>
11
12 class EventsModel : public QAbstractTableModel
13 {
14 public:
15         EventsModel(sqlite3 *db);
16
17         int rowCount(const QModelIndex &parent) const override
18         {
19                 return events.size();
20         }
21         int columnCount(const QModelIndex &column) const override
22         {
23                 return 3;
24         }
25         QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
26         QVariant data(const QModelIndex &index, int role) const override;
27
28         unsigned insert_event(uint64_t t, std::optional<int> player_id, const std::string &type = "unknown");  // Returns the row.
29         void delete_event(unsigned row);
30         void set_event_type(unsigned row, const std::string &type);
31         uint64_t get_time(unsigned row) { return events[row].t; }
32         std::optional<int> get_player_id(unsigned row) { return events[row].player_id; }
33
34         struct Status {
35                 unsigned our_score, their_score;
36                 bool offense;
37                 bool stoppage;
38                 bool should_pull;
39                 unsigned num_passes;
40                 unsigned possession_sec;
41                 unsigned stoppage_sec;
42         };
43         Status get_status_at(uint64_t t);
44         std::set<int> get_team_at(uint64_t t);
45
46 private:
47         struct Player {
48                 int player_id;
49                 std::string number;
50                 std::string name;
51         };
52         std::map<int, Player> players;
53
54         struct Event {
55                 int event_id;
56                 uint64_t t;
57                 std::optional<int> player_id;
58                 std::string type;
59         };
60         std::vector<Event> events;
61
62         sqlite3 *db;
63
64         void load_data();
65 };
66
67 #endif  // !defined(_EVENTS_H)