Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/pages/statistics.cpp Sun Sep 10 03:59:16 2023 -0400 +++ b/src/gui/pages/statistics.cpp Sat Sep 16 02:06:01 2023 -0400 @@ -1,7 +1,8 @@ #include "gui/pages/statistics.h" #include "gui/pages/anime_list.h" #include "gui/ui_utils.h" -#include "session.h" +#include "core/session.h" +#include "core/anime_db.h" #include <QString> #include <QTextDocument> #include <QTextStream> @@ -48,9 +49,9 @@ } /* me abusing macros :) */ -#define ADD_TIME_SEGMENT(r, x, s, p) \ +#define ADD_TIME_SEGMENT(r, x, s, p) { \ if (x > 0) \ - r << x << ((x == 1) ? s : p) + r << x << ((x == 1) ? s : p); } std::string StatisticsWidget::MinutesToDateString(int minutes) { /* ew */ int years = (minutes * (1 / 525949.2F)); @@ -68,25 +69,22 @@ return return_stream.str(); } -std::string StatisticsWidget::SecondsToDateString(int seconds) { +std::string StatisticsWidget::SecondsToDateString(int sec) { /* this is all fairly unnecessary, but works:tm: */ - std::chrono::duration<int, std::ratio<1>> int_total_mins(seconds); - auto int_years = std::chrono::duration_cast<std::chrono::years>(int_total_mins); - auto int_months = std::chrono::duration_cast<std::chrono::months>(int_total_mins - int_years); - auto int_days = std::chrono::duration_cast<std::chrono::days>(int_total_mins - int_years - int_months); - auto int_hours = std::chrono::duration_cast<std::chrono::hours>(int_total_mins - int_years - int_months - int_days); - auto int_minutes = std::chrono::duration_cast<std::chrono::minutes>(int_total_mins - int_years - int_months - - int_days - int_hours); - auto int_seconds = std::chrono::duration_cast<std::chrono::seconds>(int_total_mins - int_years - int_months - - int_days - int_hours - int_minutes); + int years = sec * (1 / 31556952.0F); + int months = sec * (1 / 2629746.0F) - (years * 12); + int days = sec * (1 / 86400.0F) - (years * 365.2425F) - (months * 30.436875F); + int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24); + int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F); + int seconds = sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); std::ostringstream return_stream; - ADD_TIME_SEGMENT(return_stream, int_years, " year ", " years "); - ADD_TIME_SEGMENT(return_stream, int_months, " month ", " months "); - ADD_TIME_SEGMENT(return_stream, int_days, " day ", " days "); - ADD_TIME_SEGMENT(return_stream, int_hours, " hour ", " hours "); - ADD_TIME_SEGMENT(return_stream, int_minutes, " minute ", " minutes "); - if (int_seconds.count() > 0 || return_stream.str().size() == 0) - return_stream << int_seconds.count() << ((int_seconds.count() == 1) ? " second" : " seconds"); + ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); + ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); + ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); + ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); + ADD_TIME_SEGMENT(return_stream, minutes, " minute ", " minutes "); + if (seconds > 0 || return_stream.str().size() == 0) + return_stream << seconds << ((seconds == 1) ? " second" : " seconds"); return return_stream.str(); } #undef ADD_TIME_SEGMENT @@ -95,12 +93,12 @@ /* Anime list */ QString string = ""; QTextStream ts(&string); - ts << Anime::db->GetTotalAnimeAmount() << '\n'; - ts << Anime::db->GetTotalEpisodeAmount() << '\n'; - ts << MinutesToDateString(Anime::db->GetTotalWatchedAmount()).c_str() << '\n'; - ts << MinutesToDateString(Anime::db->GetTotalPlannedAmount()).c_str() << '\n'; - ts << Anime::db->GetAverageScore() << '\n'; - ts << Anime::db->GetScoreDeviation(); + ts << Anime::db.GetTotalAnimeAmount() << '\n'; + ts << Anime::db.GetTotalEpisodeAmount() << '\n'; + ts << MinutesToDateString(Anime::db.GetTotalWatchedAmount()).c_str() << '\n'; + ts << MinutesToDateString(Anime::db.GetTotalPlannedAmount()).c_str() << '\n'; + ts << Anime::db.GetAverageScore() << '\n'; + ts << Anime::db.GetScoreDeviation(); UiUtils::SetPlainTextEditData(anime_list_data, string); /* Application */ @@ -108,4 +106,4 @@ UiUtils::SetPlainTextEditData(application_data, QString(SecondsToDateString(session.uptime() / 1000).c_str())); } -#include "gui/pages/moc_statistics.h" +#include "gui/pages/moc_statistics.cpp"