put stats in json file
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,3 +3,6 @@ build
|
||||
.DS_Store
|
||||
uwu2x-large.sql
|
||||
uwu2x-large.db
|
||||
uwu2x-small.sql
|
||||
uwu2x-small.db
|
||||
activity.json
|
||||
22
src/main.cpp
22
src/main.cpp
@@ -4,6 +4,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
|
||||
#include "sqlite3pp.h"
|
||||
|
||||
@@ -14,24 +15,13 @@ int main(int argc, char const *argv[])
|
||||
sqlite3pp::database db("../uwu2x.db");
|
||||
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)
|
||||
{
|
||||
std::string 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())
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user