Mercurial > minori
comparison src/gui/pages/statistics.cc @ 189:649786bae914
*: etc. code cleanup
I've removed most macros and stuff
dep/animia: [UNTESTED] use raw C++ instead of Objective-C++
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 19:42:33 -0500 |
parents | 9613d72b097e |
children | 4d461ef7d424 |
comparison
equal
deleted
inserted
replaced
188:168382a89b21 | 189:649786bae914 |
---|---|
73 void StatisticsPage::showEvent(QShowEvent*) { | 73 void StatisticsPage::showEvent(QShowEvent*) { |
74 UpdateStatistics(); | 74 UpdateStatistics(); |
75 } | 75 } |
76 | 76 |
77 /* me abusing macros :) */ | 77 /* me abusing macros :) */ |
78 #define ADD_TIME_SEGMENT(r, x, s, p) \ | 78 static void add_time_segment(std::ostringstream& str, int x, const std::string_view& s, const std::string_view& p) { |
79 if (x > 0) \ | 79 if (x > 0) |
80 r << x << ((x == 1) ? s : p) | 80 str << x << ((x == 1) ? s : p); |
81 } | |
82 | |
81 std::string StatisticsPage::MinutesToDateString(const int minutes) { | 83 std::string StatisticsPage::MinutesToDateString(const int minutes) { |
82 /* ew */ | 84 /* ew */ |
83 int years = (minutes * (1 / 525949.2F)); | 85 int years = (minutes * (1 / 525949.2F)); |
84 int months = (minutes * (1 / 43829.1F)) - (years * 12); | 86 int months = (minutes * (1 / 43829.1F)) - (years * 12); |
85 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F); | 87 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F); |
86 int hours = (minutes * (1 / 60.0F)) - (years * 8765.82F) - (months * 730.485F) - (days * 24); | 88 int hours = (minutes * (1 / 60.0F)) - (years * 8765.82F) - (months * 730.485F) - (days * 24); |
87 int rest_minutes = (minutes) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440) - (hours * 60); | 89 int rest_minutes = (minutes) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440) - (hours * 60); |
88 std::ostringstream return_stream; | 90 std::ostringstream return_stream; |
89 ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); | 91 add_time_segment(return_stream, years, " year ", " years "); |
90 ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); | 92 add_time_segment(return_stream, months, " month ", " months "); |
91 ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); | 93 add_time_segment(return_stream, days, " day ", " days "); |
92 ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); | 94 add_time_segment(return_stream, hours, " hour ", " hours "); |
93 if (rest_minutes > 0 || return_stream.str().size() == 0) | 95 if (rest_minutes > 0 || return_stream.str().size() == 0) |
94 return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); | 96 return_stream << rest_minutes << ((rest_minutes == 1) ? " minute" : " minutes"); |
95 return return_stream.str(); | 97 return return_stream.str(); |
96 } | 98 } |
97 | 99 |
103 int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24); | 105 int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24); |
104 int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F); | 106 int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F); |
105 int seconds = | 107 int seconds = |
106 sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); | 108 sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); |
107 std::ostringstream return_stream; | 109 std::ostringstream return_stream; |
108 ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); | 110 add_time_segment(return_stream, years, " year ", " years "); |
109 ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); | 111 add_time_segment(return_stream, months, " month ", " months "); |
110 ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); | 112 add_time_segment(return_stream, days, " day ", " days "); |
111 ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); | 113 add_time_segment(return_stream, hours, " hour ", " hours "); |
112 ADD_TIME_SEGMENT(return_stream, minutes, " minute ", " minutes "); | 114 add_time_segment(return_stream, minutes, " minute ", " minutes "); |
113 if (seconds > 0 || return_stream.str().size() == 0) | 115 if (seconds > 0 || return_stream.str().size() == 0) |
114 return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); | 116 return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); |
115 return return_stream.str(); | 117 return return_stream.str(); |
116 } | 118 } |
117 #undef ADD_TIME_SEGMENT | |
118 | 119 |
119 inline int GetTotalWithScore(const int score) { | 120 inline int GetTotalWithScore(const int score) { |
120 int count = 0; | 121 int count = 0; |
121 for (const auto& item : Anime::db.items) | 122 for (const auto& item : Anime::db.items) |
122 if (item.second.IsInUserList() && item.second.GetUserScore() == score) | 123 if (item.second.IsInUserList() && item.second.GetUserScore() == score) |