Mercurial > minori
diff src/gui/pages/statistics.cc @ 93:d5efb81540b3
statistics: add graph!
also now we have a VERY VERY simple graph widget that probably
sucks and doesn't work half the time :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 01 Nov 2023 13:52:34 -0400 |
parents | d02fdf1d6708 |
children | 2f373d48f889 |
line wrap: on
line diff
--- a/src/gui/pages/statistics.cc Wed Nov 01 00:00:56 2023 -0400 +++ b/src/gui/pages/statistics.cc Wed Nov 01 13:52:34 2023 -0400 @@ -3,6 +3,7 @@ #include "core/session.h" #include "gui/pages/anime_list.h" #include "gui/widgets/text.h" +#include "gui/widgets/graph.h" #include <QString> #include <QTextDocument> #include <QTextStream> @@ -22,18 +23,31 @@ setPalette(pal); setAutoFillBackground(true); - TextWidgets::LabelledSection* anime_list_paragraph = new TextWidgets::LabelledSection( + _anime_list.reset(new TextWidgets::LabelledSection( tr("Anime list"), tr("Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:"), - "", this); - anime_list_data = anime_list_paragraph->GetParagraph(); + "", this)); + + /* spaghetti incoming */ + QWidget* score_dist_widget = new QWidget(this); + QVBoxLayout* score_dist_layout = new QVBoxLayout(score_dist_widget); - TextWidgets::LabelledSection* application_paragraph = - new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this); - application_data = application_paragraph->GetParagraph(); + QWidget* content = new QWidget(score_dist_widget); + QVBoxLayout* content_layout = new QVBoxLayout(content); + score_dist_layout->addWidget(new TextWidgets::Header(tr("Score distribution"), content)); + _score_distribution_graph.reset(new Graph<int>(content)); + content_layout->addWidget(_score_distribution_graph.get()); + content_layout->setContentsMargins(0, 0, 0, 0); + content->setContentsMargins(12, 0, 0, 0); - layout->addWidget(anime_list_paragraph); - layout->addWidget(application_paragraph); + score_dist_layout->addWidget(content); + score_dist_layout->setContentsMargins(0, 0, 0, 0); + + _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this)); + + layout->addWidget(_anime_list.get()); + layout->addWidget(score_dist_widget); + layout->addWidget(_application.get()); layout->addStretch(); QTimer* timer = new QTimer(this); @@ -90,6 +104,14 @@ } #undef ADD_TIME_SEGMENT +inline int GetTotalWithScore(int score) { + int count = 0; + for (const auto& item : Anime::db.items) + if (item.second.IsInUserList() && item.second.GetUserScore() == score) + count++; + return count; +} + void StatisticsPage::UpdateStatistics() { /* Anime list */ QString string = ""; @@ -100,14 +122,18 @@ ts << MinutesToDateString(Anime::db.GetTotalPlannedAmount()).c_str() << '\n'; ts << Anime::db.GetAverageScore() << '\n'; ts << Anime::db.GetScoreDeviation(); - anime_list_data->SetText(string); + _anime_list->GetParagraph()->SetText(string); + + _score_distribution_graph->Clear(); + for (int i = 10; i <= 100; i += 10) + _score_distribution_graph->AddItem(i, GetTotalWithScore(i)); string = ""; ts << QString::fromUtf8(SecondsToDateString(session.uptime() / 1000).c_str()) << '\n'; ts << session.GetRequests(); /* Application */ // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000)); - application_data->SetText(string); + _application->GetParagraph()->SetText(string); } #include "gui/pages/moc_statistics.cpp"