annotate src/core/anime_db.cpp @ 38:1a34fd7469b9

ci/osx: take a different approach
author Paper <mrpapersonic@gmail.com>
date Fri, 22 Sep 2023 09:29:20 -0400
parents fc1bf97c528b
children fe719c109dbc
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
8 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
9 if (a.second.IsInUserList())
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
19 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
20 if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
28 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
29 if (a.second.IsInUserList()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
30 total += a.second.GetUserRewatchedTimes() * a.second.GetEpisodes();
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
31 total += a.second.GetUserProgress();
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
40 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
41 if (a.second.IsInUserList()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
42 total += a.second.GetDuration() * a.second.GetUserProgress();
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
43 total += a.second.GetEpisodes() * a.second.GetDuration() * a.second.GetUserRewatchedTimes();
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
56 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
57 if (a.second.IsInUserList())
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
58 total += a.second.GetDuration() * (a.second.GetEpisodes() - a.second.GetUserProgress());
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
68 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
69 if (a.second.IsInUserList() && a.second.GetUserScore()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
70 avg += a.second.GetUserScore();
10
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;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
80 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
81 if (a.second.IsInUserList() && a.second.GetUserScore()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
82 squares_sum += std::pow((double)a.second.GetUserScore() - avg, 2);
10
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
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
89 Database db;
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
90
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 } // namespace Anime