diff 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
line wrap: on
line diff
--- a/src/core/anime_db.cpp	Sat Sep 16 02:06:01 2023 -0400
+++ b/src/core/anime_db.cpp	Sun Sep 17 06:14:30 2023 -0400
@@ -5,8 +5,8 @@
 
 int Database::GetTotalAnimeAmount() {
 	int total = 0;
-	for (const auto& [id, anime] : items) {
-		if (anime.IsInUserList())
+	for (const auto& a : items) {
+		if (a.second.IsInUserList())
 			total++;
 	}
 	return total;
@@ -16,8 +16,8 @@
 	if (status == ListStatus::NOT_IN_LIST)
 		return 0;
 	int total = 0;
-	for (const auto& [id, anime] : items) {
-		if (anime.IsInUserList() && anime.GetUserStatus() == status)
+	for (const auto& a : items) {
+		if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
 			total++;
 	}
 	return total;
@@ -25,10 +25,10 @@
 
 int Database::GetTotalEpisodeAmount() {
 	int total = 0;
-	for (const auto& [id, anime] : items) {
-		if (anime.IsInUserList()) {
-			total += anime.GetUserRewatchedTimes() * anime.GetEpisodes();
-			total += anime.GetUserProgress();
+	for (const auto& a : items) {
+		if (a.second.IsInUserList()) {
+			total += a.second.GetUserRewatchedTimes() * a.second.GetEpisodes();
+			total += a.second.GetUserProgress();
 		}
 	}
 	return total;
@@ -37,10 +37,10 @@
 /* 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();
+	for (const auto& a : items) {
+		if (a.second.IsInUserList()) {
+			total += a.second.GetDuration() * a.second.GetUserProgress();
+			total += a.second.GetEpisodes() * a.second.GetDuration() * a.second.GetUserRewatchedTimes();
 		}
 	}
 	return total;
@@ -53,9 +53,9 @@
    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());
+	for (const auto& a : items) {
+		if (a.second.IsInUserList())
+			total += a.second.GetDuration() * (a.second.GetEpisodes() - a.second.GetUserProgress());
 	}
 	return total;
 }
@@ -65,9 +65,9 @@
 double Database::GetAverageScore() {
 	double avg = 0;
 	int amt = 0;
-	for (const auto& [id, anime] : items) {
-		if (anime.IsInUserList() && anime.GetUserScore()) {
-			avg += anime.GetUserScore();
+	for (const auto& a : items) {
+		if (a.second.IsInUserList() && a.second.GetUserScore()) {
+			avg += a.second.GetUserScore();
 			amt++;
 		}
 	}
@@ -77,13 +77,15 @@
 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);
+	for (const auto& a : items) {
+		if (a.second.IsInUserList() && a.second.GetUserScore()) {
+			squares_sum += std::pow((double)a.second.GetUserScore() - avg, 2);
 			amt++;
 		}
 	}
 	return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
 }
 
+Database db;
+
 } // namespace Anime
\ No newline at end of file