diff src/core/anime_db.cpp @ 10:4b198a111713

Update things actually compile now btw qttest wants to fuck over the model but that might be my fault so /shrug
author Paper <mrpapersonic@gmail.com>
date Sat, 16 Sep 2023 02:06:01 -0400
parents 5c0397762b53
children fc1bf97c528b
line wrap: on
line diff
--- a/src/core/anime_db.cpp	Sun Sep 10 03:59:16 2023 -0400
+++ b/src/core/anime_db.cpp	Sat Sep 16 02:06:01 2023 -0400
@@ -1,78 +1,89 @@
-#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;
-}
-
+#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::GetListsAnimeAmount(ListStatus status) {
+	if (status == ListStatus::NOT_IN_LIST)
+		return 0;
+	int total = 0;
+	for (const auto& [id, anime] : items) {
+		if (anime.IsInUserList() && anime.GetUserStatus() == status)
+			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