annotate src/core/anime_db.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/anime_db.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
2 #include "core/anime.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
3
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
4 namespace Anime {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
5
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 int Database::GetTotalAnimeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
8 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
9 if (anime.IsInUserList())
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 total++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
11 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
12 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 int Database::GetListsAnimeAmount(ListStatus status) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16 if (status == ListStatus::NOT_IN_LIST)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 return 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 if (anime.IsInUserList() && anime.GetUserStatus() == status)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
21 total++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
22 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
23 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
24 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
25
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
26 int Database::GetTotalEpisodeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
28 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
29 if (anime.IsInUserList()) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30 total += anime.GetUserRewatchedTimes() * anime.GetEpisodes();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 total += anime.GetUserProgress();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
32 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
33 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
34 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
35 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
36
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
37 /* Returns the total watched amount in minutes. */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
38 int Database::GetTotalWatchedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
40 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41 if (anime.IsInUserList()) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42 total += anime.GetDuration() * anime.GetUserProgress();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
43 total += anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
44 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
45 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
46 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
47 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
48
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49 /* Returns the total planned amount in minutes.
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 Note that we should probably limit progress to the
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51 amount of episodes, as AniList will let you
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52 set episode counts up to 32768. But that should
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 rather be handled elsewhere. */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54 int Database::GetTotalPlannedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
55 int total = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
56 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57 if (anime.IsInUserList())
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58 total += anime.GetDuration() * (anime.GetEpisodes() - anime.GetUserProgress());
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
59 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
60 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
61 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
62
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63 /* I'm sure many will appreciate this being called an
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
64 "average" instead of a "mean" */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
65 double Database::GetAverageScore() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
66 double avg = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
67 int amt = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
68 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
69 if (anime.IsInUserList() && anime.GetUserScore()) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
70 avg += anime.GetUserScore();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
71 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
72 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
73 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
74 return avg / amt;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
75 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
76
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77 double Database::GetScoreDeviation() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78 double squares_sum = 0, avg = GetAverageScore();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 int amt = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
80 for (const auto& [id, anime] : items) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
81 if (anime.GetUserScore()) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 squares_sum += std::pow((double)anime.GetUserScore() - avg, 2);
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
83 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
84 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
85 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
86 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
87 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
88
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 } // namespace Anime