comparison src/gui/pages/statistics.cpp @ 15:cde8f67a7c7d

*: update, megacommit :)
author Paper <mrpapersonic@gmail.com>
date Tue, 19 Sep 2023 22:36:08 -0400
parents fc1bf97c528b
children 9ae9365dd4ea
comparison
equal deleted inserted replaced
14:a29c9402faf0 15:cde8f67a7c7d
1 #include "gui/pages/statistics.h" 1 #include "gui/pages/statistics.h"
2 #include "core/anime_db.h"
3 #include "core/session.h"
2 #include "gui/pages/anime_list.h" 4 #include "gui/pages/anime_list.h"
3 #include "gui/ui_utils.h" 5 #include "gui/ui_utils.h"
4 #include "core/session.h"
5 #include "core/anime_db.h"
6 #include <QString> 6 #include <QString>
7 #include <QTextDocument> 7 #include <QTextDocument>
8 #include <QTextStream> 8 #include <QTextStream>
9 #include <QTimer> 9 #include <QTimer>
10 #include <QVBoxLayout> 10 #include <QVBoxLayout>
16 16
17 setFrameShape(QFrame::Panel); 17 setFrameShape(QFrame::Panel);
18 setFrameShadow(QFrame::Sunken); 18 setFrameShadow(QFrame::Sunken);
19 19
20 UiUtils::LabelledTextParagraph* anime_list_paragraph = new UiUtils::LabelledTextParagraph( 20 UiUtils::LabelledTextParagraph* anime_list_paragraph = new UiUtils::LabelledTextParagraph(
21 "Anime list", 21 "Anime list",
22 "Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:", "", 22 "Anime count:\nEpisode count:\nTime spent watching:\nTime to complete:\nAverage score:\nScore deviation:", "\n\n\n\n\n",
23 this); 23 this);
24 anime_list_data = anime_list_paragraph->GetParagraph(); 24 anime_list_data = anime_list_paragraph->GetParagraph();
25 25
26 UiUtils::LabelledTextParagraph* application_paragraph = 26 UiUtils::LabelledTextParagraph* application_paragraph =
27 new UiUtils::LabelledTextParagraph("Minori", "Uptime:", "", this); 27 new UiUtils::LabelledTextParagraph("Minori", "Uptime:", "", this);
28 application_data = application_paragraph->GetParagraph(); 28 application_data = application_paragraph->GetParagraph();
29 29
30 layout()->addWidget(anime_list_paragraph); 30 layout()->addWidget(anime_list_paragraph);
31 layout()->addWidget(application_paragraph); 31 layout()->addWidget(application_paragraph);
32 ((QBoxLayout*)layout())->addStretch(); 32 ((QBoxLayout*)layout())->addStretch();
47 void StatisticsWidget::showEvent(QShowEvent*) { 47 void StatisticsWidget::showEvent(QShowEvent*) {
48 UpdateStatistics(); 48 UpdateStatistics();
49 } 49 }
50 50
51 /* me abusing macros :) */ 51 /* me abusing macros :) */
52 #define ADD_TIME_SEGMENT(r, x, s, p) { \ 52 #define ADD_TIME_SEGMENT(r, x, s, p) \
53 if (x > 0) \ 53 { \
54 r << x << ((x == 1) ? s : p); } 54 if (x > 0) \
55 r << x << ((x == 1) ? s : p); \
56 }
55 std::string StatisticsWidget::MinutesToDateString(int minutes) { 57 std::string StatisticsWidget::MinutesToDateString(int minutes) {
56 /* ew */ 58 /* ew */
57 int years = (minutes * (1 / 525949.2F)); 59 int years = (minutes * (1 / 525949.2F));
58 int months = (minutes * (1 / 43829.1F)) - (years * 12); 60 int months = (minutes * (1 / 43829.1F)) - (years * 12);
59 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F); 61 int days = (minutes * (1 / 1440.0F)) - (years * 365.2425F) - (months * 30.436875F);
74 int years = sec * (1 / 31556952.0F); 76 int years = sec * (1 / 31556952.0F);
75 int months = sec * (1 / 2629746.0F) - (years * 12); 77 int months = sec * (1 / 2629746.0F) - (years * 12);
76 int days = sec * (1 / 86400.0F) - (years * 365.2425F) - (months * 30.436875F); 78 int days = sec * (1 / 86400.0F) - (years * 365.2425F) - (months * 30.436875F);
77 int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24); 79 int hours = sec * (1 / 3600.0F) - (years * 8765.82F) - (months * 730.485F) - (days * 24);
78 int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F); 80 int minutes = (sec) * (1 / 60.0F) - (years * 525949.2F) - (months * 43829.1F) - (days * 1440.0F) - (hours * 60.0F);
79 int seconds = sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F); 81 int seconds =
82 sec - (years * 31556952.0F) - (months * 2629746.0F) - (days * 86400.0F) - (hours * 3600.0F) - (minutes * 60.0F);
80 std::ostringstream return_stream; 83 std::ostringstream return_stream;
81 ADD_TIME_SEGMENT(return_stream, years, " year ", " years "); 84 ADD_TIME_SEGMENT(return_stream, years, " year ", " years ");
82 ADD_TIME_SEGMENT(return_stream, months, " month ", " months "); 85 ADD_TIME_SEGMENT(return_stream, months, " month ", " months ");
83 ADD_TIME_SEGMENT(return_stream, days, " day ", " days "); 86 ADD_TIME_SEGMENT(return_stream, days, " day ", " days ");
84 ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours "); 87 ADD_TIME_SEGMENT(return_stream, hours, " hour ", " hours ");