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