Mercurial > minori
comparison src/gui/pages/statistics.cc @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 01 Apr 2024 02:43:44 -0400 |
parents | d14f8e0e40c3 |
children | 9a88e1725fd2 |
comparison
equal
deleted
inserted
replaced
257:699a20c57dc8 | 258:862d0d8619f6 |
---|---|
1 #include "gui/pages/statistics.h" | 1 #include "gui/pages/statistics.h" |
2 #include "core/anime_db.h" | 2 #include "core/anime_db.h" |
3 #include "core/session.h" | |
3 #include "core/strings.h" | 4 #include "core/strings.h" |
4 #include "core/session.h" | |
5 #include "gui/pages/anime_list.h" | 5 #include "gui/pages/anime_list.h" |
6 #include "gui/widgets/graph.h" | |
6 #include "gui/widgets/text.h" | 7 #include "gui/widgets/text.h" |
7 #include "gui/widgets/graph.h" | |
8 | 8 |
9 #include <QString> | 9 #include <QString> |
10 #include <QTextDocument> | 10 #include <QTextDocument> |
11 #include <QTextStream> | 11 #include <QTextStream> |
12 #include <QTimer> | 12 #include <QTimer> |
13 #include <QVBoxLayout> | 13 #include <QVBoxLayout> |
14 #include <QWidget> | 14 #include <QWidget> |
15 | 15 |
16 #include <cmath> | |
16 #include <sstream> | 17 #include <sstream> |
17 #include <cmath> | |
18 | 18 |
19 enum class TimeUnits { | 19 enum class TimeUnits { |
20 SECONDS, | 20 SECONDS, |
21 MINUTES | 21 MINUTES |
22 }; | 22 }; |
58 score_dist_layout->setContentsMargins(0, 0, 0, 0); | 58 score_dist_layout->setContentsMargins(0, 0, 0, 0); |
59 | 59 |
60 layout->addWidget(score_dist_widget); | 60 layout->addWidget(score_dist_widget); |
61 } | 61 } |
62 | 62 |
63 | |
64 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this)); | 63 _application.reset(new TextWidgets::LabelledSection(tr("Minori"), tr("Uptime:\nRequests made:"), "\n\n", this)); |
65 layout->addWidget(_application.get()); | 64 layout->addWidget(_application.get()); |
66 | 65 |
67 layout->addStretch(); | 66 layout->addStretch(); |
68 | 67 |
82 * which unit to stop on | 81 * which unit to stop on |
83 * [in] int amount: | 82 * [in] int amount: |
84 * amount of units to parse | 83 * amount of units to parse |
85 * [in, defaults to 1.0] double unit_in_seconds: | 84 * [in, defaults to 1.0] double unit_in_seconds: |
86 * equivalent of one of 'amount' in seconds, e.g. minutes would be 60.0 | 85 * equivalent of one of 'amount' in seconds, e.g. minutes would be 60.0 |
87 */ | 86 */ |
88 static std::string TimeToDateString(TimeUnits unit, int amount, double unit_in_seconds = 1.0) { | 87 static std::string TimeToDateString(TimeUnits unit, int amount, double unit_in_seconds = 1.0) { |
89 /* avoid calculating this twice */ | 88 /* avoid calculating this twice */ |
90 const double years_conv = (31556952.0 / unit_in_seconds); | 89 const double years_conv = (31556952.0 / unit_in_seconds); |
91 const double months_conv = (2629746.0 / unit_in_seconds); | 90 const double months_conv = (2629746.0 / unit_in_seconds); |
92 const double days_conv = (86400.0 / unit_in_seconds); | 91 const double days_conv = (86400.0 / unit_in_seconds); |
93 const double hours_conv = (3600.0 / unit_in_seconds); | 92 const double hours_conv = (3600.0 / unit_in_seconds); |
94 const double minutes_conv = (60.0 / unit_in_seconds); | 93 const double minutes_conv = (60.0 / unit_in_seconds); |
95 const double seconds_conv = (1.0 / unit_in_seconds); | 94 const double seconds_conv = (1.0 / unit_in_seconds); |
96 | 95 |
97 const int years = amount / years_conv; | 96 const int years = amount / years_conv; |
98 const int months = std::fmod(amount, years_conv) / months_conv; | 97 const int months = std::fmod(amount, years_conv) / months_conv; |
99 const int days = std::fmod(amount, months_conv) / days_conv; | 98 const int days = std::fmod(amount, months_conv) / days_conv; |
100 const int hours = std::fmod(amount, days_conv) / hours_conv; | 99 const int hours = std::fmod(amount, days_conv) / hours_conv; |
101 const int minutes = std::fmod(amount, hours_conv) / minutes_conv; | 100 const int minutes = std::fmod(amount, hours_conv) / minutes_conv; |
102 const int seconds = std::fmod(amount, minutes_conv) / seconds_conv; | 101 const int seconds = std::fmod(amount, minutes_conv) / seconds_conv; |
103 | 102 |
104 const auto add_time_segment = [](std::ostringstream& str, int amount, const std::string_view& singular, const std::string_view& plural, bool always = false) { | 103 const auto add_time_segment = [](std::ostringstream& str, int amount, const std::string_view& singular, |
104 const std::string_view& plural, bool always = false) { | |
105 if (amount > 0 || always) | 105 if (amount > 0 || always) |
106 str << amount << ((amount == 1) ? singular : plural); | 106 str << amount << ((amount == 1) ? singular : plural); |
107 }; | 107 }; |
108 | 108 |
109 std::ostringstream string; | 109 std::ostringstream string; |