Mercurial > minori
comparison src/core/anime_db.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Mon, 23 Oct 2023 12:07:27 -0400 |
| parents | src/core/anime_db.cpp@fe719c109dbc |
| children | d02fdf1d6708 |
comparison
equal
deleted
inserted
replaced
| 80:825506f0e221 | 81:9b2b41f83a5e |
|---|---|
| 1 #include "core/anime_db.h" | |
| 2 #include "core/anime.h" | |
| 3 #include "core/strings.h" | |
| 4 #include <QDebug> | |
| 5 | |
| 6 namespace Anime { | |
| 7 | |
| 8 int Database::GetTotalAnimeAmount() { | |
| 9 int total = 0; | |
| 10 for (const auto& a : items) { | |
| 11 if (a.second.IsInUserList()) | |
| 12 total++; | |
| 13 } | |
| 14 return total; | |
| 15 } | |
| 16 | |
| 17 int Database::GetListsAnimeAmount(ListStatus status) { | |
| 18 if (status == ListStatus::NOT_IN_LIST) | |
| 19 return 0; | |
| 20 int total = 0; | |
| 21 for (const auto& a : items) { | |
| 22 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) | |
| 23 total++; | |
| 24 } | |
| 25 return total; | |
| 26 } | |
| 27 | |
| 28 int Database::GetTotalEpisodeAmount() { | |
| 29 int total = 0; | |
| 30 for (const auto& a : items) { | |
| 31 if (a.second.IsInUserList()) { | |
| 32 total += a.second.GetUserRewatchedTimes() * a.second.GetEpisodes(); | |
| 33 total += a.second.GetUserProgress(); | |
| 34 } | |
| 35 } | |
| 36 return total; | |
| 37 } | |
| 38 | |
| 39 /* Returns the total watched amount in minutes. */ | |
| 40 int Database::GetTotalWatchedAmount() { | |
| 41 int total = 0; | |
| 42 for (const auto& a : items) { | |
| 43 if (a.second.IsInUserList()) { | |
| 44 total += a.second.GetDuration() * a.second.GetUserProgress(); | |
| 45 total += a.second.GetEpisodes() * a.second.GetDuration() * a.second.GetUserRewatchedTimes(); | |
| 46 } | |
| 47 } | |
| 48 return total; | |
| 49 } | |
| 50 | |
| 51 /* Returns the total planned amount in minutes. | |
| 52 Note that we should probably limit progress to the | |
| 53 amount of episodes, as AniList will let you | |
| 54 set episode counts up to 32768. But that should | |
| 55 rather be handled elsewhere. */ | |
| 56 int Database::GetTotalPlannedAmount() { | |
| 57 int total = 0; | |
| 58 for (const auto& a : items) { | |
| 59 if (a.second.IsInUserList()) | |
| 60 total += a.second.GetDuration() * (a.second.GetEpisodes() - a.second.GetUserProgress()); | |
| 61 } | |
| 62 return total; | |
| 63 } | |
| 64 | |
| 65 /* I'm sure many will appreciate this being called an | |
| 66 "average" instead of a "mean" */ | |
| 67 double Database::GetAverageScore() { | |
| 68 double avg = 0; | |
| 69 int amt = 0; | |
| 70 for (const auto& a : items) { | |
| 71 if (a.second.IsInUserList() && a.second.GetUserScore()) { | |
| 72 avg += a.second.GetUserScore(); | |
| 73 amt++; | |
| 74 } | |
| 75 } | |
| 76 return avg / amt; | |
| 77 } | |
| 78 | |
| 79 double Database::GetScoreDeviation() { | |
| 80 double squares_sum = 0, avg = GetAverageScore(); | |
| 81 int amt = 0; | |
| 82 for (const auto& a : items) { | |
| 83 if (a.second.IsInUserList() && a.second.GetUserScore()) { | |
| 84 squares_sum += std::pow(static_cast<double>(a.second.GetUserScore()) - avg, 2); | |
| 85 amt++; | |
| 86 } | |
| 87 } | |
| 88 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; | |
| 89 } | |
| 90 | |
| 91 int Database::GetAnimeFromTitle(std::string title) { | |
| 92 if (title.empty()) | |
| 93 return 0; | |
| 94 for (const auto& a : items) { | |
| 95 if (a.second.GetUserPreferredTitle().find(title) != std::string::npos) | |
| 96 return a.second.GetId(); | |
| 97 for (const auto& t : a.second.GetTitleSynonyms()) { | |
| 98 if (t.find(title) != std::string::npos) { | |
| 99 return a.second.GetId(); | |
| 100 } | |
| 101 } | |
| 102 } | |
| 103 return 0; | |
| 104 } | |
| 105 | |
| 106 Database db; | |
| 107 | |
| 108 } // namespace Anime |
