Mercurial > minori
comparison src/gui/pages/statistics.cpp @ 10:4b198a111713
Update
things actually compile now btw
qttest wants to fuck over the model but that might be my fault so /shrug
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 16 Sep 2023 02:06:01 -0400 |
parents | 5c0397762b53 |
children | fc1bf97c528b |
comparison
equal
deleted
inserted
replaced
9:5c0397762b53 | 10:4b198a111713 |
---|---|
1 #include "gui/pages/statistics.h" | 1 #include "gui/pages/statistics.h" |
2 #include "gui/pages/anime_list.h" | 2 #include "gui/pages/anime_list.h" |
3 #include "gui/ui_utils.h" | 3 #include "gui/ui_utils.h" |
4 #include "session.h" | 4 #include "core/session.h" |
5 #include "core/anime_db.h" | |
5 #include <QString> | 6 #include <QString> |
6 #include <QTextDocument> | 7 #include <QTextDocument> |
7 #include <QTextStream> | 8 #include <QTextStream> |
8 #include <QTimer> | 9 #include <QTimer> |
9 #include <QVBoxLayout> | 10 #include <QVBoxLayout> |
46 void StatisticsWidget::showEvent(QShowEvent*) { | 47 void StatisticsWidget::showEvent(QShowEvent*) { |
47 UpdateStatistics(); | 48 UpdateStatistics(); |
48 } | 49 } |
49 | 50 |
50 /* me abusing macros :) */ | 51 /* me abusing macros :) */ |
51 #define ADD_TIME_SEGMENT(r, x, s, p) \ | 52 #define ADD_TIME_SEGMENT(r, x, s, p) { \ |
52 if (x > 0) \ | 53 if (x > 0) \ |
53 r << x << ((x == 1) ? s : p) | 54 r << x << ((x == 1) ? s : p); } |
54 std::string StatisticsWidget::MinutesToDateString(int minutes) { | 55 std::string StatisticsWidget::MinutesToDateString(int minutes) { |
55 /* ew */ | 56 /* ew */ |
56 int years = (minutes * (1 / 525949.2F)); | 57 int years = (minutes * (1 / 525949.2F)); |
57 int months = (minutes * (1 / 43829.1F)) - (years * 12); | 58 int months = (minutes * (1 / 43829.1F)) - (years * 12); |
58 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F); | 59 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F); |
66 if (rest_minutes > 0 || return_stream.str().size() == 0) | 67 if (rest_minutes > 0 || return_stream.str().size() == 0) |
67 return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); | 68 return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); |
68 return return_stream.str(); | 69 return return_stream.str(); |
69 } | 70 } |
70 | 71 |
71 std::string StatisticsWidget::SecondsToDateString(int seconds) { | 72 std::string StatisticsWidget::SecondsToDateString(int sec) { |
72 /* this is all fairly unnecessary, but works:tm: */ | 73 /* this is all fairly unnecessary, but works:tm: */ |
73 std::chrono::duration<int, std::ratio<1>> int_total_mins(seconds); | 74 int years = sec * (1 / 31556952.0F); |
74 auto int_years = std::chrono::duration_cast<std::chrono::years>(int_total_mins); | 75 int months = sec * (1 / 2629746.0F) - (years * 12); |
75 auto int_months = std::chrono::duration_cast<std::chrono::months>(int_total_mins - int_years); | 76 int days = sec * (1 / 86400.0F) - (years * 365.2425F) - (months * 30.436875F); |
76 auto int_days = std::chrono::duration_cast<std::chrono::days>(int_total_mins - int_years - int_months); | 77 int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24); |
77 auto int_hours = std::chrono::duration_cast<std::chrono::hours>(int_total_mins - int_years - int_months - int_days); | 78 int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F); |
78 auto int_minutes = std::chrono::duration_cast<std::chrono::minutes>(int_total_mins - int_years - int_months - | 79 int seconds = sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); |
79 int_days - int_hours); | |
80 auto int_seconds = std::chrono::duration_cast<std::chrono::seconds>(int_total_mins - int_years - int_months - | |
81 int_days - int_hours - int_minutes); | |
82 std::ostringstream return_stream; | 80 std::ostringstream return_stream; |
83 ADD_TIME_SEGMENT(return_stream, int_years, " year ", " years "); | 81 ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); |
84 ADD_TIME_SEGMENT(return_stream, int_months, " month ", " months "); | 82 ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); |
85 ADD_TIME_SEGMENT(return_stream, int_days, " day ", " days "); | 83 ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); |
86 ADD_TIME_SEGMENT(return_stream, int_hours, " hour ", " hours "); | 84 ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); |
87 ADD_TIME_SEGMENT(return_stream, int_minutes, " minute ", " minutes "); | 85 ADD_TIME_SEGMENT(return_stream, minutes, " minute ", " minutes "); |
88 if (int_seconds.count() > 0 || return_stream.str().size() == 0) | 86 if (seconds > 0 || return_stream.str().size() == 0) |
89 return_stream << int_seconds.count() << ((int_seconds.count() == 1) ? " second" : " seconds"); | 87 return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); |
90 return return_stream.str(); | 88 return return_stream.str(); |
91 } | 89 } |
92 #undef ADD_TIME_SEGMENT | 90 #undef ADD_TIME_SEGMENT |
93 | 91 |
94 void StatisticsWidget::UpdateStatistics() { | 92 void StatisticsWidget::UpdateStatistics() { |
95 /* Anime list */ | 93 /* Anime list */ |
96 QString string = ""; | 94 QString string = ""; |
97 QTextStream ts(&string); | 95 QTextStream ts(&string); |
98 ts << Anime::db->GetTotalAnimeAmount() << '\n'; | 96 ts << Anime::db.GetTotalAnimeAmount() << '\n'; |
99 ts << Anime::db->GetTotalEpisodeAmount() << '\n'; | 97 ts << Anime::db.GetTotalEpisodeAmount() << '\n'; |
100 ts << MinutesToDateString(Anime::db->GetTotalWatchedAmount()).c_str() << '\n'; | 98 ts << MinutesToDateString(Anime::db.GetTotalWatchedAmount()).c_str() << '\n'; |
101 ts << MinutesToDateString(Anime::db->GetTotalPlannedAmount()).c_str() << '\n'; | 99 ts << MinutesToDateString(Anime::db.GetTotalPlannedAmount()).c_str() << '\n'; |
102 ts << Anime::db->GetAverageScore() << '\n'; | 100 ts << Anime::db.GetAverageScore() << '\n'; |
103 ts << Anime::db->GetScoreDeviation(); | 101 ts << Anime::db.GetScoreDeviation(); |
104 UiUtils::SetPlainTextEditData(anime_list_data, string); | 102 UiUtils::SetPlainTextEditData(anime_list_data, string); |
105 | 103 |
106 /* Application */ | 104 /* Application */ |
107 // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000)); | 105 // UiUtils::SetPlainTextEditData(application_data, QString::number(session.uptime() / 1000)); |
108 UiUtils::SetPlainTextEditData(application_data, QString(SecondsToDateString(session.uptime() / 1000).c_str())); | 106 UiUtils::SetPlainTextEditData(application_data, QString(SecondsToDateString(session.uptime() / 1000).c_str())); |
109 } | 107 } |
110 | 108 |
111 #include "gui/pages/moc_statistics.h" | 109 #include "gui/pages/moc_statistics.cpp" |