]> git.sesse.net Git - pkanalytics/blob - events.h
910e2b92a6517ad88803e16b9b42a405fa010e9a
[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
11 class EventsModel : public QAbstractTableModel
12 {
13 public:
14         EventsModel(sqlite3 *db);
15
16         int rowCount(const QModelIndex &parent) const override
17         {
18                 return events.size();
19         }
20         int columnCount(const QModelIndex &column) const override
21         {
22                 return 3;
23         }
24         QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
25         QVariant data(const QModelIndex &index, int role) const override;
26
27         unsigned insert_event(uint64_t t, int player_id);  // Returns the row.
28         void delete_event(unsigned row);
29         void set_event_type(unsigned row, const std::string &type);
30         uint64_t get_time(unsigned row) { return events[row].t; }
31
32         struct Status {
33                 unsigned our_score, their_score;
34                 bool offense;
35                 unsigned num_passes;
36                 unsigned possession_sec;
37         };
38         Status get_status_at(uint64_t t);
39
40 private:
41         struct Player {
42                 int player_id;
43                 std::string number;
44                 std::string name;
45         };
46         std::map<int, Player> players;
47
48         struct Event {
49                 int event_id;
50                 uint64_t t;
51                 std::optional<int> player_id;
52                 std::string type;
53         };
54         std::vector<Event> events;
55
56         sqlite3 *db;
57
58         void load_data();
59 };
60
61 #endif  // !defined(_EVENTS_H)