Mercurial > minori
comparison src/pages/statistics.cpp @ 1:1ae666fdf9e2
*: initial commit
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 08 Aug 2023 19:49:15 -0400 |
parents | |
children | 23d0d9319a00 |
comparison
equal
deleted
inserted
replaced
0:5a76e1b94163 | 1:1ae666fdf9e2 |
---|---|
1 #include "window.h" | |
2 #include "ui_utils.h" | |
3 #include <sstream> | |
4 | |
5 StatisticsTimer::StatisticsTimer(Statistics* caller) { | |
6 statistics = caller; | |
7 } | |
8 | |
9 void StatisticsTimer::Notify() { | |
10 if (status.current_page == PAGE_STATISTICS) | |
11 statistics->UpdateStatistics(); | |
12 } | |
13 | |
14 Statistics::Statistics(page_t* page, wxPanel* frame) { | |
15 page->panel = new wxPanel(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 600)); | |
16 page->panel->Show(false); | |
17 panel = new wxPanel(page->panel, wxID_ANY, wxPoint(12, 12), wxSize(376, 576)); | |
18 anime_list = ((WeeabooFrame*)frame->GetParent())->GetAnimeList(); | |
19 | |
20 /* FIXME: this should be moved to a separate function, it's also used in information.cpp */ | |
21 // wxWindow* parent, const char* title, const char* label, const char* data, int width, int height, int x = 0, int y = 0, int selectable = 0 | |
22 anime_list_data = UiUtils::CreateTextParagraphWithLabels(panel, L"Anime list", L"Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:", L"", 376, 94); | |
23 | |
24 UpdateStatistics(); // load in statistics as soon as possible | |
25 timer = new StatisticsTimer(this); | |
26 timer->Start(1000); // update statistics every second | |
27 } | |
28 | |
29 std::string Statistics::MinutesToDateString(int minutes) { | |
30 /* NOTE: these duration_casts may not be needed... */ | |
31 std::chrono::duration<int, std::ratio<60>> int_total_mins(minutes); | |
32 auto int_years = std::chrono::duration_cast<std::chrono::years>(int_total_mins); | |
33 auto int_months = std::chrono::duration_cast<std::chrono::months>(int_total_mins-int_years); | |
34 auto int_days = std::chrono::duration_cast<std::chrono::days>(int_total_mins-int_years-int_months); | |
35 auto int_hours = std::chrono::duration_cast<std::chrono::hours>(int_total_mins-int_years-int_months-int_days); | |
36 auto int_minutes = std::chrono::duration_cast<std::chrono::minutes>(int_total_mins-int_years-int_months-int_days-int_hours); | |
37 std::ostringstream return_stream; | |
38 if (int_years.count() > 0) { | |
39 return_stream << int_years.count() << " years "; | |
40 } | |
41 if (int_months.count() > 0) { | |
42 return_stream << int_months.count() << " months "; | |
43 } | |
44 if (int_days.count() > 0) { | |
45 return_stream << int_days.count() << " days "; | |
46 } | |
47 if (int_hours.count() > 0) { | |
48 return_stream << int_hours.count() << " hours "; | |
49 } | |
50 return_stream << int_minutes.count() << " minutes"; // return minutes anyway | |
51 return return_stream.str(); | |
52 } | |
53 | |
54 void Statistics::UpdateStatistics() { | |
55 wxString string = ""; | |
56 string << anime_list->GetTotalAnimeAmount() << '\n'; | |
57 string << anime_list->GetTotalEpisodeAmount() << '\n'; | |
58 string << MinutesToDateString(anime_list->GetTotalWatchedAmount()) << '\n'; | |
59 string << MinutesToDateString(anime_list->GetTotalPlannedAmount()) << '\n'; | |
60 string << anime_list->GetAverageScore() << '\n'; | |
61 string << anime_list->GetScoreDeviation() << '\n'; | |
62 anime_list_data->SetLabel(string); | |
63 } |