annotate src/gui/pages/statistics.cc @ 311:fb0f6b5050ff

linux: add required blank svg icon (???)
author Paper <paper@paper.us.eu.org>
date Tue, 11 Jun 2024 13:08:41 -0400
parents 91ac90a34003
children 6b0768158dcd
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
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
20 StatisticsPage::StatisticsPage(QWidget* parent) : QFrame(parent) {
295
b82841e76e79 *: better support on Windows
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
21 setBackgroundRole(QPalette::Base);
b82841e76e79 *: better support on Windows
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
22
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
23 QVBoxLayout* layout = new QVBoxLayout(this);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
25 setFrameShape(QFrame::Box);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 setFrameShadow(QFrame::Sunken);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 37
diff changeset
28 setAutoFillBackground(true);
37
9ae9365dd4ea window.cpp: fix sidebar on Linux
Paper <mrpapersonic@gmail.com>
parents: 15
diff changeset
29
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
30 _anime_list.reset(new TextWidgets::LabelledSection(
51
75c804f713b2 window: add about window,
Paper <mrpapersonic@gmail.com>
parents: 49
diff changeset
31 tr("Anime list"),
63
3d2decf093bb *: fix many clang warnings
Paper <mrpapersonic@gmail.com>
parents: 51
diff changeset
32 tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"),
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
33 "", this));
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
34 layout->addWidget(_anime_list.get());
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
35
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
36 {
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
37 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
38 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
40 score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), score_dist_widget));
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
41
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
42 /* Ew */
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
43 {
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
44 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
45 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent);
94
2f373d48f889 *: etc changes to graph stuff
Paper <mrpapersonic@gmail.com>
parents: 93
diff changeset
46
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
47 _score_distribution_graph.reset(new Graph<int>(score_graph_parent));
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
48 score_parent_layout->addWidget(_score_distribution_graph.get());
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
49
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
50 score_parent_layout->setSpacing(0);
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
51 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
52
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
53 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
54 }
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
55
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
56 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
57
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
58 layout->addWidget(score_dist_widget);
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
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
61 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this));
172
45a0967485f1 graph, statistics: make my code a little less messy
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
62 layout->addWidget(_application.get());
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
63
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
64 layout->addStretch();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 QTimer* timer = new QTimer(this);
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 connect(timer, &QTimer::timeout, this, [this] {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 if (isVisible())
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 UpdateStatistics();
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 });
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 timer->start(1000); // update statistics every second
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
74 void StatisticsPage::showEvent(QShowEvent*) {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75 UpdateStatistics();
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77
102
b315f3759c56 *: big patch
Paper <mrpapersonic@gmail.com>
parents: 94
diff changeset
78 inline int GetTotalWithScore(const int score) {
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
79 int count = 0;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
80 for (const auto& item : Anime::db.items)
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
81 if (item.second.IsInUserList() && item.second.GetUserScore() == score)
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
82 count++;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
83 return count;
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
84 }
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
85
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
86 void StatisticsPage::UpdateStatistics() {
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 /* Anime list */
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 QString string = "";
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 QTextStream ts(&string);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90 ts << Anime::db.GetTotalAnimeAmount() << '\n';
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
91 ts << Anime::db.GetTotalEpisodeAmount() << '\n';
305
91ac90a34003 core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
92 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)) << '\n';
91ac90a34003 core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
93 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)) << '\n';
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
94 ts << Anime::db.GetAverageScore() << '\n';
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
95 ts << Anime::db.GetScoreDeviation();
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
96 _anime_list->GetData()->setText(string);
93
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
97
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
98 _score_distribution_graph->Clear();
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
99 for (int i = 10; i <= 100; i += 10)
d5efb81540b3 statistics: add graph!
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
100 _score_distribution_graph->AddItem(i, GetTotalWithScore(i));
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101
47
d8eb763e6661 information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
102 string = "";
305
91ac90a34003 core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
103 ts << Strings::ToQString(Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)) << '\n';
47
d8eb763e6661 information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
104 ts << session.GetRequests();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 /* Application */
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106 // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000));
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
107 _application->GetData()->setText(string);
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 }