Mercurial > minori
diff src/core/anime_db.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 10 Sep 2023 03:59:16 -0400 |
parents | |
children | 4b198a111713 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/anime_db.cpp Sun Sep 10 03:59:16 2023 -0400 @@ -0,0 +1,78 @@ +#include "core/anime_db.h" +#include "core/anime.h" + +namespace Anime { + +int Database::GetTotalAnimeAmount() { + int total = 0; + for (const auto& [id, anime] : items) { + if (anime.IsInUserList()) + total++; + } + return total; +} + +int Database::GetTotalEpisodeAmount() { + int total = 0; + for (const auto& [id, anime] : items) { + if (anime.IsInUserList()) { + total += anime.GetUserRewatchedTimes() * anime.GetEpisodes(); + total += anime.GetUserProgress(); + } + } + return total; +} + +/* Returns the total watched amount in minutes. */ +int Database::GetTotalWatchedAmount() { + int total = 0; + for (const auto& [id, anime] : items) { + if (anime.IsInUserList()) { + total += anime.GetDuration() * anime.GetUserProgress(); + total += anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes(); + } + } + return total; +} + +/* Returns the total planned amount in minutes. + Note that we should probably limit progress to the + amount of episodes, as AniList will let you + set episode counts up to 32768. But that should + rather be handled elsewhere. */ +int Database::GetTotalPlannedAmount() { + int total = 0; + for (const auto& [id, anime] : items) { + if (anime.IsInUserList()) + total += anime.GetDuration() * (anime.GetEpisodes() - anime.GetUserProgress()); + } + return total; +} + +/* I'm sure many will appreciate this being called an + "average" instead of a "mean" */ +double Database::GetAverageScore() { + double avg = 0; + int amt = 0; + for (const auto& [id, anime] : items) { + if (anime.IsInUserList() && anime.GetUserScore()) { + avg += anime.GetUserScore(); + amt++; + } + } + return avg / amt; +} + +double Database::GetScoreDeviation() { + double squares_sum = 0, avg = GetAverageScore(); + int amt = 0; + for (const auto& [id, anime] : items) { + if (anime.GetUserScore()) { + squares_sum += std::pow((double)anime.GetUserScore() - avg, 2); + amt++; + } + } + return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; +} + +} // namespace Anime \ No newline at end of file