annotate src/core/anime_db.cc @ 173:de0a8d2f28b3

WILL NOT COMPILE: sample export ability for anime db
author Paper <mrpapersonic@gmail.com>
date Tue, 28 Nov 2023 13:53:54 -0500
parents d02fdf1d6708
children f88eda79c60a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/anime_db.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
2 #include "core/anime.h"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
3 #include "core/strings.h"
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
4 #include "core/json.h"
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
5
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
6 #include <QDebug>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
8 namespace Anime {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
9
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
10 int Database::GetTotalAnimeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
11 int total = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
12 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
13 if (a.second.IsInUserList())
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
14 total++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
15 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
16 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19 int Database::GetListsAnimeAmount(ListStatus status) {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 if (status == ListStatus::NOT_IN_LIST)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
21 return 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
22 int total = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
23 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
24 if (a.second.IsInUserList() && a.second.GetUserStatus() == status)
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
25 total++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
26 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
28 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
29
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
30 int Database::GetTotalEpisodeAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 int total = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
32 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
33 if (a.second.IsInUserList()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
34 total += a.second.GetUserRewatchedTimes() * a.second.GetEpisodes();
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
35 total += a.second.GetUserProgress();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
36 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
37 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
38 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
40
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41 /* Returns the total watched amount in minutes. */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
42 int Database::GetTotalWatchedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
43 int total = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
44 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
45 if (a.second.IsInUserList()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
46 total += a.second.GetDuration() * a.second.GetUserProgress();
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
47 total += a.second.GetEpisodes() * a.second.GetDuration() * a.second.GetUserRewatchedTimes();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
48 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
53 /* Returns the total planned amount in minutes.
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
54 Note that we should probably limit progress to the
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
55 amount of episodes, as AniList will let you
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
56 set episode counts up to 32768. But that should
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
57 rather be handled elsewhere. */
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
58 int Database::GetTotalPlannedAmount() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
59 int total = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
60 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
61 if (a.second.IsInUserList())
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
62 total += a.second.GetDuration() * (a.second.GetEpisodes() - a.second.GetUserProgress());
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
64 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
65 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
66
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
67 /* In Taiga this is called a mean, but "average" is
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
68 what's primarily used in conversation, at least
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
69 in the U.S. */
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
70 double Database::GetAverageScore() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
71 double avg = 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
72 int amt = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
73 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
74 if (a.second.IsInUserList() && a.second.GetUserScore()) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
75 avg += a.second.GetUserScore();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
76 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
79 return avg / amt;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
80 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
81
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 double Database::GetScoreDeviation() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
83 double squares_sum = 0, avg = GetAverageScore();
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
84 int amt = 0;
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
85 for (const auto& a : items) {
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
86 if (a.second.IsInUserList() && a.second.GetUserScore()) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
87 squares_sum += std::pow(static_cast<double>(a.second.GetUserScore()) - avg, 2);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
88 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
89 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
91 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
92 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
93
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
94 template <typename T, typename U>
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
95 static T get_lowest_in_map(const std::unordered_map<T, U>& map) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
96 if (map.size() <= 0)
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
97 return 0;
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
98
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
99 T id = 0;
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
100 U ret = std::numeric_limits<U>::max();
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
101 for (const auto& t : map) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
102 if (t.second < ret) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
103 ret = t.second;
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
104 id = t.first;
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
105 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
106 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
107 return id;
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
108 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
109
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
110 /* This is really fugly but WHO CARES :P
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
111
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
112 This fairly basic algorithm is only in effect because
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
113 there are some special cases, e.g. Another and Re:ZERO, where
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
114 we get the wrong match, so we have to create Advanced Techniques
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
115 to solve this
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
116
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
117 This algorithm:
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
118 1. searches each anime item for a match to the preferred title
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
119 AND all synonyms and marks those matches with
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
120 `synonym.length() - (synonym.find(needle) + needle.length());`
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
121 which should never be less than zero and will be zero if, and only if
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
122 the titles match exactly.
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
123 2. returns the id of the match that is the lowest, which will most
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
124 definitely match anything that exactly matches the title of the
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
125 filename */
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
126 int Database::GetAnimeFromTitle(const std::string& title) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
127 if (title.empty())
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
128 return 0;
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
129
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
130 std::unordered_map<int, size_t> map;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
131
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
132 auto process_title = [&map](const Anime& anime, const std::string& title, const std::string& needle) -> bool {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
133 size_t ret = title.find(needle);
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
134 if (ret == std::string::npos)
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
135 return false;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
136
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
137 map[anime.GetId()] = title.length() - (ret + needle.length());
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
138 return true;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
139 };
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
140
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
141 for (const auto& [id, anime] : items) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
142 if (process_title(anime, anime.GetUserPreferredTitle(), title))
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
143 continue;
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
144
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
145 for (const auto& synonym : anime.GetTitleSynonyms())
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
146 if (process_title(anime, synonym, title))
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
147 continue;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
148 }
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
149
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
150 return get_lowest_in_map(map);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
151 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
152
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
153 static bool GetListDataAsJSON(const Anime& anime, nlohmann::json& json) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
154 if (!anime.IsInUserList())
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
155 return false;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
156
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
157 json = {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
158 {"status", Translate::ToString(anime.GetUserStatus())},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
159 {"progress", anime.GetUserProgress()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
160 {"score", anime.GetUserScore()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
161 //{"started", anime.GetUserDateStarted()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
162 //{"completed", anime.GetUserDateCompleted()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
163 {"private", anime.GetUserIsPrivate()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
164 {"rewatched_times", anime.GetUserRewatchedTimes()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
165 {"rewatching", anime.GetUserIsRewatching()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
166 {"updated", anime.GetUserTimeUpdated()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
167 {"notes", anime.GetUserNotes()}
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
168 };
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
169 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
170
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
171 static bool GetAnimeAsJSON(const Anime& anime, nlohmann::json& json) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
172 json = {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
173 {"id", anime.GetId()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
174 {"title", {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
175 {"native", anime.GetNativeTitle()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
176 {"romaji", anime.GetRomajiTitle()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
177 {"english", anime.GetEnglishTitle()}
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
178 }},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
179 {"synonyms", anime.GetTitleSynonyms()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
180 {"episodes", anime.GetEpisodes()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
181 {"airing_status", anime.GetAiringStatus()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
182 {"air_date", anime.GetAirDate()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
183 {"genres", anime.GetGenres()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
184 {"producers", anime.GetProducers()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
185 {"format", anime.GetFormat()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
186 {"season", anime.GetSeason()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
187 {"audience_score", anime.GetAudienceScore()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
188 {"synopsis", anime.GetSynopsis()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
189 {"duration", anime.GetDuration()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
190 {"poster_url", anime.GetPosterUrl()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
191 {"service_url", anime.GetServiceUrl()}
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
192 };
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
193
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
194 nlohmann::json user;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
195 if (GetListDataAsJSON(anime, user))
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
196 json.push_back({"list_data", user});
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
197
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
198 return true;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
199 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
200
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
201 bool Database::GetDatabaseAsJSON(nlohmann::json& json) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
202 for (const auto& [id, anime] : items) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
203 nlohmann::json anime_json;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
204 GetAnimeAsJSON(anime, anime_json);
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
205 json.push_back(anime_json);
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
206 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
207 return true;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
208 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
209
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
210 Database db;
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
211
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
212 } // namespace Anime