Mercurial > minori
comparison src/core/anime_db.cpp @ 11:fc1bf97c528b
*: use C++11 standard
I've been meaning to do this for a while, but I didn't want to reimplement
the filesystem code. Now we are on C++11 and most compilers from the past 5 centuries should support this now
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 17 Sep 2023 06:14:30 -0400 |
| parents | 4b198a111713 |
| children | fe719c109dbc |
comparison
equal
deleted
inserted
replaced
| 10:4b198a111713 | 11:fc1bf97c528b |
|---|---|
| 3 | 3 |
| 4 namespace Anime { | 4 namespace Anime { |
| 5 | 5 |
| 6 int Database::GetTotalAnimeAmount() { | 6 int Database::GetTotalAnimeAmount() { |
| 7 int total = 0; | 7 int total = 0; |
| 8 for (const auto& [id, anime] : items) { | 8 for (const auto& a : items) { |
| 9 if (anime.IsInUserList()) | 9 if (a.second.IsInUserList()) |
| 10 total++; | 10 total++; |
| 11 } | 11 } |
| 12 return total; | 12 return total; |
| 13 } | 13 } |
| 14 | 14 |
| 15 int Database::GetListsAnimeAmount(ListStatus status) { | 15 int Database::GetListsAnimeAmount(ListStatus status) { |
| 16 if (status == ListStatus::NOT_IN_LIST) | 16 if (status == ListStatus::NOT_IN_LIST) |
| 17 return 0; | 17 return 0; |
| 18 int total = 0; | 18 int total = 0; |
| 19 for (const auto& [id, anime] : items) { | 19 for (const auto& a : items) { |
| 20 if (anime.IsInUserList() && anime.GetUserStatus() == status) | 20 if (a.second.IsInUserList() && a.second.GetUserStatus() == status) |
| 21 total++; | 21 total++; |
| 22 } | 22 } |
| 23 return total; | 23 return total; |
| 24 } | 24 } |
| 25 | 25 |
| 26 int Database::GetTotalEpisodeAmount() { | 26 int Database::GetTotalEpisodeAmount() { |
| 27 int total = 0; | 27 int total = 0; |
| 28 for (const auto& [id, anime] : items) { | 28 for (const auto& a : items) { |
| 29 if (anime.IsInUserList()) { | 29 if (a.second.IsInUserList()) { |
| 30 total += anime.GetUserRewatchedTimes() * anime.GetEpisodes(); | 30 total += a.second.GetUserRewatchedTimes() * a.second.GetEpisodes(); |
| 31 total += anime.GetUserProgress(); | 31 total += a.second.GetUserProgress(); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 return total; | 34 return total; |
| 35 } | 35 } |
| 36 | 36 |
| 37 /* Returns the total watched amount in minutes. */ | 37 /* Returns the total watched amount in minutes. */ |
| 38 int Database::GetTotalWatchedAmount() { | 38 int Database::GetTotalWatchedAmount() { |
| 39 int total = 0; | 39 int total = 0; |
| 40 for (const auto& [id, anime] : items) { | 40 for (const auto& a : items) { |
| 41 if (anime.IsInUserList()) { | 41 if (a.second.IsInUserList()) { |
| 42 total += anime.GetDuration() * anime.GetUserProgress(); | 42 total += a.second.GetDuration() * a.second.GetUserProgress(); |
| 43 total += anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes(); | 43 total += a.second.GetEpisodes() * a.second.GetDuration() * a.second.GetUserRewatchedTimes(); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 return total; | 46 return total; |
| 47 } | 47 } |
| 48 | 48 |
| 51 amount of episodes, as AniList will let you | 51 amount of episodes, as AniList will let you |
| 52 set episode counts up to 32768. But that should | 52 set episode counts up to 32768. But that should |
| 53 rather be handled elsewhere. */ | 53 rather be handled elsewhere. */ |
| 54 int Database::GetTotalPlannedAmount() { | 54 int Database::GetTotalPlannedAmount() { |
| 55 int total = 0; | 55 int total = 0; |
| 56 for (const auto& [id, anime] : items) { | 56 for (const auto& a : items) { |
| 57 if (anime.IsInUserList()) | 57 if (a.second.IsInUserList()) |
| 58 total += anime.GetDuration() * (anime.GetEpisodes() - anime.GetUserProgress()); | 58 total += a.second.GetDuration() * (a.second.GetEpisodes() - a.second.GetUserProgress()); |
| 59 } | 59 } |
| 60 return total; | 60 return total; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /* I'm sure many will appreciate this being called an | 63 /* I'm sure many will appreciate this being called an |
| 64 "average" instead of a "mean" */ | 64 "average" instead of a "mean" */ |
| 65 double Database::GetAverageScore() { | 65 double Database::GetAverageScore() { |
| 66 double avg = 0; | 66 double avg = 0; |
| 67 int amt = 0; | 67 int amt = 0; |
| 68 for (const auto& [id, anime] : items) { | 68 for (const auto& a : items) { |
| 69 if (anime.IsInUserList() && anime.GetUserScore()) { | 69 if (a.second.IsInUserList() && a.second.GetUserScore()) { |
| 70 avg += anime.GetUserScore(); | 70 avg += a.second.GetUserScore(); |
| 71 amt++; | 71 amt++; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 return avg / amt; | 74 return avg / amt; |
| 75 } | 75 } |
| 76 | 76 |
| 77 double Database::GetScoreDeviation() { | 77 double Database::GetScoreDeviation() { |
| 78 double squares_sum = 0, avg = GetAverageScore(); | 78 double squares_sum = 0, avg = GetAverageScore(); |
| 79 int amt = 0; | 79 int amt = 0; |
| 80 for (const auto& [id, anime] : items) { | 80 for (const auto& a : items) { |
| 81 if (anime.GetUserScore()) { | 81 if (a.second.IsInUserList() && a.second.GetUserScore()) { |
| 82 squares_sum += std::pow((double)anime.GetUserScore() - avg, 2); | 82 squares_sum += std::pow((double)a.second.GetUserScore() - avg, 2); |
| 83 amt++; | 83 amt++; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; | 86 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 Database db; | |
| 90 | |
| 89 } // namespace Anime | 91 } // namespace Anime |
