Mercurial > minori
comparison src/gui/pages/statistics.cc @ 370:ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 25 Jul 2025 10:22:04 -0400 |
| parents | 6b0768158dcd |
| children |
comparison
equal
deleted
inserted
replaced
| 369:47c9f8502269 | 370:ea3a74ed2ef9 |
|---|---|
| 15 #include <QWidget> | 15 #include <QWidget> |
| 16 | 16 |
| 17 #include <cmath> | 17 #include <cmath> |
| 18 #include <sstream> | 18 #include <sstream> |
| 19 | 19 |
| 20 StatisticsPage::StatisticsPage(QWidget* parent) | 20 StatisticsPage::StatisticsPage(QWidget *parent) : QFrame(parent) |
| 21 : QFrame(parent) { | 21 { |
| 22 setBackgroundRole(QPalette::Base); | 22 setBackgroundRole(QPalette::Base); |
| 23 | 23 |
| 24 QVBoxLayout* layout = new QVBoxLayout(this); | 24 QVBoxLayout *layout = new QVBoxLayout(this); |
| 25 | 25 |
| 26 setFrameShape(QFrame::Box); | 26 setFrameShape(QFrame::Box); |
| 27 setFrameShadow(QFrame::Sunken); | 27 setFrameShadow(QFrame::Sunken); |
| 28 | 28 |
| 29 setAutoFillBackground(true); | 29 setAutoFillBackground(true); |
| 30 | 30 |
| 31 const std::vector<std::pair<std::string, std::string>> al_data_template = { | 31 const std::vector<std::pair<std::string, std::string>> al_data_template = { |
| 32 {Strings::Translate("Anime count:"), ""}, | 32 {Strings::Translate("Anime count:"), ""}, |
| 33 {Strings::Translate("Episode count:"), ""}, | 33 {Strings::Translate("Episode count:"), ""}, |
| 34 {Strings::Translate("Time spent watching:"), ""}, | 34 {Strings::Translate("Time spent watching:"), ""}, |
| 35 {Strings::Translate("Time to complete:"), ""}, | 35 {Strings::Translate("Time to complete:"), ""}, |
| 36 {Strings::Translate("Average score:"), ""}, | 36 {Strings::Translate("Average score:"), ""}, |
| 37 {Strings::Translate("Score deviation:"), ""}, | 37 {Strings::Translate("Score deviation:"), ""}, |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 _anime_list.GetHeader().SetText(Strings::Translate("Anime List")); | 40 _anime_list.GetHeader().SetText(Strings::Translate("Anime List")); |
| 41 _anime_list.GetContent().SetData(al_data_template); | 41 _anime_list.GetContent().SetData(al_data_template); |
| 42 | 42 |
| 43 layout->addWidget(&_anime_list); | 43 layout->addWidget(&_anime_list); |
| 44 | 44 |
| 45 { | 45 { |
| 46 QWidget* score_dist_widget = new QWidget(this); | 46 QWidget *score_dist_widget = new QWidget(this); |
| 47 QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget); | 47 QVBoxLayout *score_dist_layout = new QVBoxLayout(score_dist_widget); |
| 48 | 48 |
| 49 TextWidgets::Header* hdr = new TextWidgets::Header(score_dist_widget); | 49 TextWidgets::Header *hdr = new TextWidgets::Header(score_dist_widget); |
| 50 hdr->SetText(Strings::Translate("Score distribution")); | 50 hdr->SetText(Strings::Translate("Score distribution")); |
| 51 score_dist_layout->addWidget(hdr); | 51 score_dist_layout->addWidget(hdr); |
| 52 | 52 |
| 53 /* Ew */ | 53 /* Ew */ |
| 54 { | 54 { |
| 55 QWidget* score_graph_parent = new QWidget(score_dist_widget); | 55 QWidget *score_graph_parent = new QWidget(score_dist_widget); |
| 56 QVBoxLayout* score_parent_layout = new QVBoxLayout(score_graph_parent); | 56 QVBoxLayout *score_parent_layout = new QVBoxLayout(score_graph_parent); |
| 57 | 57 |
| 58 score_parent_layout->addWidget(&_score_distribution_graph); | 58 score_parent_layout->addWidget(&_score_distribution_graph); |
| 59 | 59 |
| 60 score_parent_layout->setSpacing(0); | 60 score_parent_layout->setSpacing(0); |
| 61 score_parent_layout->setContentsMargins(12, 0, 0, 0); | 61 score_parent_layout->setContentsMargins(12, 0, 0, 0); |
| 67 | 67 |
| 68 layout->addWidget(score_dist_widget); | 68 layout->addWidget(score_dist_widget); |
| 69 } | 69 } |
| 70 | 70 |
| 71 const std::vector<std::pair<std::string, std::string>> app_data_template = { | 71 const std::vector<std::pair<std::string, std::string>> app_data_template = { |
| 72 {Strings::Translate("Uptime:"), ""}, | 72 {Strings::Translate("Uptime:"), ""}, |
| 73 {Strings::Translate("Requests made:"), ""}, | 73 {Strings::Translate("Requests made:"), ""}, |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 _application.GetHeader().SetText(Strings::Translate("Minori")); | 76 _application.GetHeader().SetText(Strings::Translate("Minori")); |
| 77 _application.GetContent().SetData(app_data_template); | 77 _application.GetContent().SetData(app_data_template); |
| 78 | 78 |
| 79 layout->addWidget(&_application); | 79 layout->addWidget(&_application); |
| 80 | 80 |
| 81 layout->addStretch(); | 81 layout->addStretch(); |
| 82 | 82 |
| 83 QTimer* timer = new QTimer(this); | 83 QTimer *timer = new QTimer(this); |
| 84 connect(timer, &QTimer::timeout, this, [this] { | 84 connect(timer, &QTimer::timeout, this, [this] { |
| 85 if (isVisible()) | 85 if (isVisible()) |
| 86 UpdateStatistics(); | 86 UpdateStatistics(); |
| 87 }); | 87 }); |
| 88 timer->start(1000); // update statistics every second | 88 timer->start(1000); // update statistics every second |
| 89 } | 89 } |
| 90 | 90 |
| 91 void StatisticsPage::showEvent(QShowEvent*) { | 91 void StatisticsPage::showEvent(QShowEvent *) |
| 92 { | |
| 92 UpdateStatistics(); | 93 UpdateStatistics(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 inline int GetTotalWithScore(const int score) { | 96 inline int GetTotalWithScore(const int score) |
| 97 { | |
| 96 int count = 0; | 98 int count = 0; |
| 97 for (const auto& item : Anime::db.items) | 99 for (const auto &item : Anime::db.items) |
| 98 if (item.second.IsInUserList() && item.second.GetUserScore() == score) | 100 if (item.second.IsInUserList() && item.second.GetUserScore() == score) |
| 99 count++; | 101 count++; |
| 100 return count; | 102 return count; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void StatisticsPage::UpdateStatistics() { | 105 void StatisticsPage::UpdateStatistics() |
| 106 { | |
| 104 const std::vector<std::pair<std::string, std::string>> al_data = { | 107 const std::vector<std::pair<std::string, std::string>> al_data = { |
| 105 {Strings::Translate("Anime count:"), Strings::ToUtf8String(Anime::db.GetTotalAnimeAmount())}, | 108 {Strings::Translate("Anime count:"), Strings::ToUtf8String(Anime::db.GetTotalAnimeAmount())}, |
| 106 {Strings::Translate("Episode count:"), Strings::ToUtf8String(Anime::db.GetTotalEpisodeAmount())}, | 109 {Strings::Translate("Episode count:"), Strings::ToUtf8String(Anime::db.GetTotalEpisodeAmount())}, |
| 107 {Strings::Translate("Time spent watching:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)}, | 110 {Strings::Translate("Time spent watching:"), |
| 108 {Strings::Translate("Time to complete:"), Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)}, | 111 Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalWatchedAmount(), 60.0)}, |
| 109 {Strings::Translate("Average score:"), Strings::ToUtf8String(Anime::db.GetAverageScore())}, | 112 {Strings::Translate("Time to complete:"), |
| 110 {Strings::Translate("Score deviation:"), Strings::ToUtf8String(Anime::db.GetScoreDeviation())}, | 113 Time::GetSecondsAsAbsoluteString(Time::Units::Minutes, Anime::db.GetTotalPlannedAmount(), 60.0)}, |
| 114 {Strings::Translate("Average score:"), Strings::ToUtf8String(Anime::db.GetAverageScore())}, | |
| 115 {Strings::Translate("Score deviation:"), Strings::ToUtf8String(Anime::db.GetScoreDeviation())}, | |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 _anime_list.GetContent().SetData(al_data); | 118 _anime_list.GetContent().SetData(al_data); |
| 114 | 119 |
| 115 _score_distribution_graph.Clear(); | 120 _score_distribution_graph.Clear(); |
| 116 for (int i = 10; i <= 100; i += 10) | 121 for (int i = 10; i <= 100; i += 10) |
| 117 _score_distribution_graph.AddItem(i, GetTotalWithScore(i)); | 122 _score_distribution_graph.AddItem(i, GetTotalWithScore(i)); |
| 118 | 123 |
| 119 /* Application */ | 124 /* Application */ |
| 120 const std::vector<std::pair<std::string, std::string>> app_data_template = { | 125 const std::vector<std::pair<std::string, std::string>> app_data_template = { |
| 121 {Strings::Translate("Uptime:"), Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)}, | 126 {Strings::Translate("Uptime:"), |
| 122 {Strings::Translate("Requests made:"), Strings::ToUtf8String(session.GetRequests())}, | 127 Time::GetSecondsAsAbsoluteString(Time::Units::Seconds, session.uptime() / 1000)}, |
| 128 {Strings::Translate("Requests made:"), Strings::ToUtf8String(session.GetRequests())}, | |
| 123 }; | 129 }; |
| 124 | 130 |
| 125 _application.GetContent().SetData(app_data_template); | 131 _application.GetContent().SetData(app_data_template); |
| 126 } | 132 } |
