comparison src/core/anime_db.cpp @ 9:5c0397762b53

INCOMPLETE: megacommit :)
author Paper <mrpapersonic@gmail.com>
date Sun, 10 Sep 2023 03:59:16 -0400
parents
children 4b198a111713
comparison
equal deleted inserted replaced
8:b1f73678ef61 9:5c0397762b53
1 #include "core/anime_db.h"
2 #include "core/anime.h"
3
4 namespace Anime {
5
6 int Database::GetTotalAnimeAmount() {
7 int total = 0;
8 for (const auto& [id, anime] : items) {
9 if (anime.IsInUserList())
10 total++;
11 }
12 return total;
13 }
14
15 int Database::GetTotalEpisodeAmount() {
16 int total = 0;
17 for (const auto& [id, anime] : items) {
18 if (anime.IsInUserList()) {
19 total += anime.GetUserRewatchedTimes() * anime.GetEpisodes();
20 total += anime.GetUserProgress();
21 }
22 }
23 return total;
24 }
25
26 /* Returns the total watched amount in minutes. */
27 int Database::GetTotalWatchedAmount() {
28 int total = 0;
29 for (const auto& [id, anime] : items) {
30 if (anime.IsInUserList()) {
31 total += anime.GetDuration() * anime.GetUserProgress();
32 total += anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes();
33 }
34 }
35 return total;
36 }
37
38 /* Returns the total planned amount in minutes.
39 Note that we should probably limit progress to the
40 amount of episodes, as AniList will let you
41 set episode counts up to 32768. But that should
42 rather be handled elsewhere. */
43 int Database::GetTotalPlannedAmount() {
44 int total = 0;
45 for (const auto& [id, anime] : items) {
46 if (anime.IsInUserList())
47 total += anime.GetDuration() * (anime.GetEpisodes() - anime.GetUserProgress());
48 }
49 return total;
50 }
51
52 /* I'm sure many will appreciate this being called an
53 "average" instead of a "mean" */
54 double Database::GetAverageScore() {
55 double avg = 0;
56 int amt = 0;
57 for (const auto& [id, anime] : items) {
58 if (anime.IsInUserList() && anime.GetUserScore()) {
59 avg += anime.GetUserScore();
60 amt++;
61 }
62 }
63 return avg / amt;
64 }
65
66 double Database::GetScoreDeviation() {
67 double squares_sum = 0, avg = GetAverageScore();
68 int amt = 0;
69 for (const auto& [id, anime] : items) {
70 if (anime.GetUserScore()) {
71 squares_sum += std::pow((double)anime.GetUserScore() - avg, 2);
72 amt++;
73 }
74 }
75 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
76 }
77
78 } // namespace Anime