put stats in json file

This commit is contained in:
2025-10-18 21:25:32 +02:00
parent 2191a940c4
commit 7a89c18d8e
2 changed files with 12 additions and 15 deletions

5
.gitignore vendored
View File

@@ -2,4 +2,7 @@
build build
.DS_Store .DS_Store
uwu2x-large.sql uwu2x-large.sql
uwu2x-large.db uwu2x-large.db
uwu2x-small.sql
uwu2x-small.db
activity.json

View File

@@ -4,6 +4,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include <chrono> #include <chrono>
#include <fstream>
#include "sqlite3pp.h" #include "sqlite3pp.h"
@@ -14,24 +15,13 @@ int main(int argc, char const *argv[])
sqlite3pp::database db("../uwu2x.db"); sqlite3pp::database db("../uwu2x.db");
sqlite3pp::query q(db, "SELECT DISTINCT identifier, strftime('%Y-%m-%d', date) FROM interaction ORDER BY date ASC;"); sqlite3pp::query q(db, "SELECT DISTINCT identifier, strftime('%Y-%m-%d', date) FROM interaction ORDER BY date ASC;");
std::vector<std::vector<std::string>> interactions; std::set<std::string> identifiers;
std::map<std::string, std::map<std::string, int>> activity;
for (auto r : q) for (auto r : q)
{ {
std::string identifier, date; std::string identifier, date;
r.getter() >> identifier >> date; r.getter() >> identifier >> date;
interactions.emplace_back(std::vector<std::string>{identifier, date});
}
std::cout << interactions.size() << std::endl;
std::set<std::string> identifiers;
std::map<std::string, std::map<std::string, int>> activity;
for (size_t i = 0; i < interactions.size(); ++i)
{
const std::string &identifier = interactions[i][0];
const std::string &date = interactions[i][1];
if (activity.find(date) == activity.end()) if (activity.find(date) == activity.end())
{ {
@@ -47,10 +37,14 @@ int main(int argc, char const *argv[])
} }
} }
std::ofstream f("../activity.json");
f << "{" << std::endl;
for (const auto &[key, val] : activity) for (const auto &[key, val] : activity)
{ {
std::cout << key << " : u=" << val.at("u") << " n=" << val.at("n") << std::endl; f << "\t\"" << key << "\": {\"u\": " << val.at("u") << ", \"n\": " << val.at("n") << "}," << std::endl;
} }
f.seekp((long)f.tellp() - 2);
f << std::endl << "}" << std::endl;
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();