comparison src/core/anime_db.cpp @ 64:fe719c109dbc

*: update 1. add media tracking ability, and it displays info on the `now playing` page 2. the `now playing` page now actually shows something 3. renamed every page class to be more accurate to what it is 4. ...
author Paper <mrpapersonic@gmail.com>
date Sun, 01 Oct 2023 23:15:43 -0400
parents fc1bf97c528b
children
comparison
equal deleted inserted replaced
63:3d2decf093bb 64:fe719c109dbc
1 #include "core/anime_db.h" 1 #include "core/anime_db.h"
2 #include "core/anime.h" 2 #include "core/anime.h"
3 #include "core/strings.h"
4 #include <QDebug>
3 5
4 namespace Anime { 6 namespace Anime {
5 7
6 int Database::GetTotalAnimeAmount() { 8 int Database::GetTotalAnimeAmount() {
7 int total = 0; 9 int total = 0;
77 double Database::GetScoreDeviation() { 79 double Database::GetScoreDeviation() {
78 double squares_sum = 0, avg = GetAverageScore(); 80 double squares_sum = 0, avg = GetAverageScore();
79 int amt = 0; 81 int amt = 0;
80 for (const auto& a : items) { 82 for (const auto& a : items) {
81 if (a.second.IsInUserList() && a.second.GetUserScore()) { 83 if (a.second.IsInUserList() && a.second.GetUserScore()) {
82 squares_sum += std::pow((double)a.second.GetUserScore() - avg, 2); 84 squares_sum += std::pow(static_cast<double>(a.second.GetUserScore()) - avg, 2);
83 amt++; 85 amt++;
84 } 86 }
85 } 87 }
86 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; 88 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
87 } 89 }
88 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
89 Database db; 106 Database db;
90 107
91 } // namespace Anime 108 } // namespace Anime