annotate src/gui/pages/statistics.cc @ 354:9aaf1e788896

core/endian: fix compile error under clang
author Paper <paper@paper.us.eu.org>
date Sun, 14 Jul 2024 23:39:42 -0400
parents 6b0768158dcd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "gui/pages/statistics.h"
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
2 #include "core/anime_db.h"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
3 #include "core/session.h"
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 178
diff changeset
4 #include "core/strings.h"
305
91ac90a34003 core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
5 #include "core/time.h"
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "gui/pages/anime_list.h"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
7 #include "gui/widgets/graph.h"
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 37
diff changeset
8 #include "gui/widgets/text.h"
178
bc8d2ccff09c win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents: 172
diff changeset
9
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <QString>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <QTextDocument>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #include <QTextStream>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <QTimer>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <QVBoxLayout>
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 #include <QWidget>
178
bc8d2ccff09c win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents: 172
diff changeset
16
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
17 #include <cmath>
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 #include <sstream>
250
c130f47f6f48 *: many many changes
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
19
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
20 StatisticsPage::StatisticsPage(QWidget* parent)
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
21 : QFrame(parent) {
295
b82841e76e79 *: better support on Windows
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
22 setBackgroundRole(QPalette::Base);
b82841e76e79 *: better support on Windows
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
23
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
24 QVBoxLayout* layout = new QVBoxLayout(this);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
26 setFrameShape(QFrame::Box);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 setFrameShadow(QFrame::Sunken);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 37
diff changeset
29 setAutoFillBackground(true);
37
9ae9365dd4ea window.cpp: fix sidebar on Linux
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
30
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
31 const std::vector<std::pair<std::string, std::string>> al_data_template = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
32 {Strings::Translate("Anime count:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
33 {Strings::Translate("Episode count:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
34 {Strings::Translate("Time spent watching:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
35 {Strings::Translate("Time to complete:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
36 {Strings::Translate("Average score:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
37 {Strings::Translate("Score deviation:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
38 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
39
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
40 _anime_list.GetHeader().SetText(Strings::Translate("Anime List"));
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
41 _anime_list.GetContent().SetData(al_data_template);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
42
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
43 layout->addWidget(&_anime_list);
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
44
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
45 {
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
46 QWidget* score_dist_widget = new QWidget(this);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
47 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
49 TextWidgets::Header* hdr = new TextWidgets::Header(score_dist_widget);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
50 hdr->SetText(Strings::Translate("Score distribution"));
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
51 score_dist_layout->addWidget(hdr);
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
52
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
53 /* Ew */
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
54 {
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
55 QWidget* score_graph_parent = new QWidget(score_dist_widget);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
56 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
94
2f373d48f889 *: etc changes to graph stuff
Paper <mrpapersonic@gmail.com>
parents: 93
diff changeset
57
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
58 score_parent_layout->addWidget(&_score_distribution_graph);
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
59
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
60 score_parent_layout->setSpacing(0);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
61 score_parent_layout->setContentsMargins(12, 0, 0, 0);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
62
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
63 score_dist_layout->addWidget(score_graph_parent);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
64 }
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
65
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
66 score_dist_layout->setContentsMargins(0, 0, 0, 0);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
67
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
68 layout->addWidget(score_dist_widget);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
69 }
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
70
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
71 const std::vector<std::pair<std::string, std::string>> app_data_template = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
72 {Strings::Translate("Uptime:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
73 {Strings::Translate("Requests made:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
74 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
75
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
76 _application.GetHeader().SetText(Strings::Translate("Minori"));
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
77 _application.GetContent().SetData(app_data_template);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
78
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
79 layout->addWidget(&_application);
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
80
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
81 layout->addStretch();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 QTimer* timer = new QTimer(this);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 connect(timer, &QTimer::timeout, this, [this] {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85 if (isVisible())
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 UpdateStatistics();
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 });
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 timer->start(1000); // update statistics every second
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
91 void StatisticsPage::showEvent(QShowEvent*) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 UpdateStatistics();
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 94
diff changeset
95 inline int GetTotalWithScore(const int score) {
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
96 int count = 0;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
97 for (const auto& item : Anime::db.items)
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
98 if (item.second.IsInUserList() && item.second.GetUserScore() == score)
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
99 count++;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
100 return count;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
101 }
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
102
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
103 void StatisticsPage::UpdateStatistics() {
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
104 const std::vector<std::pair<std::string, std::string>> al_data = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
105 {Strings::Translate("Anime count:"), Strings::ToUtf8String(Anime::db.GetTotalAnimeAmount())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
106 {Strings::Translate("Episode count:"), Strings::ToUtf8String(Anime::db.GetTotalEpisodeAmount())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
107 {Strings::Translate("Time spent watching:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
108 {Strings::Translate("Time to complete:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
109 {Strings::Translate("Average score:"), Strings::ToUtf8String(Anime::db.GetAverageScore())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
110 {Strings::Translate("Score deviation:"), Strings::ToUtf8String(Anime::db.GetScoreDeviation())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
111 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
112
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
113 _anime_list.GetContent().SetData(al_data);
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
114
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
115 _score_distribution_graph.Clear();
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
116 for (int i = 10; i <= 100; i += 10)
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
117 _score_distribution_graph.AddItem(i, GetTotalWithScore(i));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 /* Application */
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
120 const std::vector<std::pair<std::string, std::string>> app_data_template = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
121 {Strings::Translate("Uptime:"), Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
122 {Strings::Translate("Requests made:"), Strings::ToUtf8String(session.GetRequests())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
123 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
124
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 305
diff changeset
125 _application.GetContent().SetData(app_data_template);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 }