master
Tomasz Golinski 2022-07-14 14:47:15 +02:00
rodzic d00a852295
commit 70499296d7
4 zmienionych plików z 53 dodań i 52 usunięć

Wyświetl plik

@ -199,7 +199,7 @@ int main(int argc, char** argv) {
std::unordered_map<int, const Powertrail*> tt_map; // Needed to deduplicate trails std::unordered_map<int, const Powertrail*> tt_map; // Needed to deduplicate trails
for ( auto& c : tmp ) { for (auto& c : tmp) {
if (tc.data.count(c.code) > 0) { if (tc.data.count(c.code) > 0) {
c.trail = tc.data[c.code]; c.trail = tc.data[c.code];
t.data[c.trail].found++; t.data[c.trail].found++;
@ -681,7 +681,7 @@ int main(int argc, char** argv) {
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
/* /*
n = 1; n = 1;
std::cout << "<h2>Caches with highest rating</h2>\n"; std::cout << "<h2>Caches with highest rating</h2>\n";
@ -822,7 +822,7 @@ int main(int argc, char** argv) {
} }
} }
float perc; float perc;
switch(i) { switch (i) {
case 4: case 4:
case 6: case 6:
case 9: case 9:
@ -872,8 +872,7 @@ int main(int argc, char** argv) {
std::cout << "<td class=\"dt_null\"></td>"; std::cout << "<td class=\"dt_null\"></td>";
else else
std::cout << "<td class=\"dt_zero\">" << 0 << "</td>"; std::cout << "<td class=\"dt_zero\">" << 0 << "</td>";
} } else {
else {
std::cout << "<td codes=\"" << codes << "\">" << count << "</td>"; std::cout << "<td codes=\"" << codes << "\">" << count << "</td>";
n++; n++;
m++; m++;
@ -894,12 +893,12 @@ int main(int argc, char** argv) {
int m_count = (now_tm->tm_year - 106 - 1) * 12 + 8 + now_tm->tm_mon + 1; // 106 corresponds to 2006, 8 is no. of months since may till dec, +1 since tm_mon starts at 0 int m_count = (now_tm->tm_year - 106 - 1) * 12 + 8 + now_tm->tm_mon + 1; // 106 corresponds to 2006, 8 is no. of months since may till dec, +1 since tm_mon starts at 0
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total <span class=\"value\">" << n << "</span> months out of " << m_count << " (" << std::setprecision(3) << n * 100.0 / m_count << "%).\n"; std::cout << "Total <span class=\"value\">" << n << "</span> months out of " << m_count << " (" << std::setprecision(3) << n * 100.0 / m_count << "%).\n";
std::cout << "</div>\n"; std::cout << "</div>\n";
} else if (!ocde_user_uuid.empty()) { } else if (!ocde_user_uuid.empty()) {
int m_count = (now_tm->tm_year - 105 - 1) * 12 + 5 + now_tm->tm_mon + 1; // 106 corresponds to 2005, 8 is no. of months since aug till dec, +1 since tm_mon starts at 0 int m_count = (now_tm->tm_year - 105 - 1) * 12 + 5 + now_tm->tm_mon + 1; // 106 corresponds to 2005, 8 is no. of months since aug till dec, +1 since tm_mon starts at 0
std::cout << "<div class=\"basic_stats\">\n"; std::cout << "<div class=\"basic_stats\">\n";
std::cout << "Total <span class=\"value\">" << n << "</span> months out of " << m_count << " (" << std::setprecision(3) << n * 100.0 / m_count << "%).\n"; std::cout << "Total <span class=\"value\">" << n << "</span> months out of " << m_count << " (" << std::setprecision(3) << n * 100.0 / m_count << "%).\n";
std::cout << "</div>\n"; std::cout << "</div>\n";
} }
} }
@ -1114,7 +1113,7 @@ int main(int argc, char** argv) {
} }
std::cout << "</table>\n"; std::cout << "</table>\n";
/* /*
n = 1; n = 1;
std::cout << "<h2>Caches with highest rating</h2>\n"; std::cout << "<h2>Caches with highest rating</h2>\n";

Wyświetl plik

@ -162,10 +162,14 @@ bool OCdb::update_cache(const json& j) {
fields["type"] = j["data"]["type"].get<std::string>(); fields["type"] = j["data"]["type"].get<std::string>();
if (j["data"].count("status") && !j["data"]["status"].is_null()) { if (j["data"].count("status") && !j["data"]["status"].is_null()) {
std::string tmp = j["data"]["status"].get<std::string>(); std::string tmp = j["data"]["status"].get<std::string>();
if (tmp == "Available") fields2["status"] = ok; if (tmp == "Available")
else if (tmp == "Archived") fields2["status"] = archived; fields2["status"] = ok;
else if (tmp == "Temporarily unavailable") fields2["status"] = disabled; else if (tmp == "Archived")
else fields2["status"] = unknown; fields2["status"] = archived;
else if (tmp == "Temporarily unavailable")
fields2["status"] = disabled;
else
fields2["status"] = unknown;
} }
if (j["data"].count("size2") && !j["data"]["size2"].is_null()) if (j["data"].count("size2") && !j["data"]["size2"].is_null())
fields["size"] = j["data"]["size2"].get<std::string>(); fields["size"] = j["data"]["size2"].get<std::string>();
@ -406,8 +410,10 @@ Caches OCdb::parse_sql_caches() const {
//c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6)); //c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 6));
if (sqlite3_column_text(stmt, 7)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7)); if (sqlite3_column_text(stmt, 7)) c.region = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 7));
if (sqlite3_column_text(stmt, 8)) c.owner_uuid = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8)); // TODO: we don't know owner's nick if (sqlite3_column_text(stmt, 8)) c.owner_uuid = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 8)); // TODO: we don't know owner's nick
if (sqlite3_column_text(stmt, 9)) c.status = static_cast<Status>(sqlite3_column_int(stmt, 9)); if (sqlite3_column_text(stmt, 9))
else c.status = unknown; c.status = static_cast<Status>(sqlite3_column_int(stmt, 9));
else
c.status = unknown;
if (sqlite3_column_text(stmt, 10)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 10)); if (sqlite3_column_text(stmt, 10)) c.name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 10));
if (sqlite3_column_text(stmt, 11)) c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 11)); if (sqlite3_column_text(stmt, 11)) c.country = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 11));

Wyświetl plik

@ -17,15 +17,15 @@ static const std::regex regex_perc("<span id=\"powerTrailpercent\">(.*?)</span>"
static const std::regex regex_cache("<a href=\"(OP.*?)\">"); static const std::regex regex_cache("<a href=\"(OP.*?)\">");
void to_json(json& j, const Powertrail& item) { void to_json(json& j, const Powertrail& item) {
j = json{ { "name", item.name }, { "date", item.date_str }, { "treshold", item.treshold_perc }, { "caches", item.caches } }; j = json{ { "name", item.name }, { "date", item.date_str }, { "treshold", item.treshold_perc }, { "caches", item.caches } };
} }
void from_json(const json& j, Powertrail& item) { void from_json(const json& j, Powertrail& item) {
j.at("name").get_to(item.name); j.at("name").get_to(item.name);
j.at("date").get_to(item.date_str); j.at("date").get_to(item.date_str);
j.at("treshold").get_to(item.treshold_perc); j.at("treshold").get_to(item.treshold_perc);
j.at("caches").get_to(item.caches); j.at("caches").get_to(item.caches);
strptime(item.date_str.c_str(), "%d-%m-%Y", &item.date); strptime(item.date_str.c_str(), "%d-%m-%Y", &item.date);
} }
std::string Powertrail::link() const { std::string Powertrail::link() const {
@ -78,7 +78,8 @@ void PowertrailDB::get_trail(uint n) {
T.name = res[1].str(); T.name = res[1].str();
if (T.name.empty()) return; if (T.name.empty()) return;
Debug(2) << "Read name: " << T.name; Debug(2) << "Read name: " << T.name;
} else return; } else
return;
if (std::regex_search(curl_output, res, regex_date) && res.size() == 2) { if (std::regex_search(curl_output, res, regex_date) && res.size() == 2) {
strptime(res[1].str().c_str(), "%d-%m-%Y", &T.date); strptime(res[1].str().c_str(), "%d-%m-%Y", &T.date);
T.date_str = res[1].str(); T.date_str = res[1].str();
@ -99,17 +100,17 @@ void PowertrailDB::get_trail(uint n) {
} }
auto caches_begin = std::sregex_iterator(curl_output.begin(), curl_output.end(), regex_cache); auto caches_begin = std::sregex_iterator(curl_output.begin(), curl_output.end(), regex_cache);
auto caches_end = std::sregex_iterator(); auto caches_end = std::sregex_iterator();
Debug(2) << "Found " << std::distance(caches_begin, caches_end) << " caches.\n";
for (std::sregex_iterator i = caches_begin; i!= caches_end; i++) {
std::smatch match = *i;
T.caches.insert(match[1].str());
// Debug(2) << match[1].str();
}
data.insert({n, T}); Debug(2) << "Found " << std::distance(caches_begin, caches_end) << " caches.\n";
for (std::sregex_iterator i = caches_begin; i != caches_end; i++) {
std::smatch match = *i;
T.caches.insert(match[1].str());
// Debug(2) << match[1].str();
}
data.insert({ n, T });
} }
// Callback for cURL easy interface used to save received output to std::string object // Callback for cURL easy interface used to save received output to std::string object
@ -126,14 +127,14 @@ void PowertrailDB::read_from_json(std::string file) {
json j; json j;
datafile >> j; datafile >> j;
data = j.get<std::unordered_map<uint, Powertrail>>(); data = j.get<std::unordered_map<uint, Powertrail>>();
} }
catch (...) { catch (...) {
Debug(1) << "Cache file: " << file << " corrupted."; Debug(1) << "Cache file: " << file << " corrupted.";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
for (auto& p: data) for (auto& p : data)
p.second.number = p.first; p.second.number = p.first;
}; };
void PowertrailDB::save_to_json(std::string file) { void PowertrailDB::save_to_json(std::string file) {
@ -143,9 +144,9 @@ void PowertrailDB::save_to_json(std::string file) {
}; };
Caches_in_Powertrails::Caches_in_Powertrails(PowertrailDB db) { Caches_in_Powertrails::Caches_in_Powertrails(PowertrailDB db) {
for ( auto& t : db.data ) { for (auto& t : db.data) {
for ( auto& c : t.second.caches ) { for (auto& c : t.second.caches) {
data.insert( {c, t.second.number} ); data.insert({ c, t.second.number });
} }
} }
} }
@ -157,12 +158,11 @@ void Caches_in_Powertrails::read_from_json(std::string file) {
json j; json j;
datafile >> j; datafile >> j;
data = j.get<std::unordered_map<std::string, int>>(); data = j.get<std::unordered_map<std::string, int>>();
// data = j.get<Caches_in_Powertrails>(); }
} catch (...) {
catch (...) { Debug(1) << "Cache file: " << file << " corrupted.";
Debug(1) << "Cache file: " << file << " corrupted."; std::exit(EXIT_FAILURE);
std::exit(EXIT_FAILURE); }
}
}; };
void Caches_in_Powertrails::save_to_json(std::string file) { void Caches_in_Powertrails::save_to_json(std::string file) {
@ -170,6 +170,3 @@ void Caches_in_Powertrails::save_to_json(std::string file) {
json j(data); json j(data);
datafile << j; datafile << j;
}; };
// void Caches_in_Powertrails::update_caches(Caches& cc) {
// };

Wyświetl plik

@ -54,11 +54,10 @@ public:
std::unordered_map<std::string, int> data; std::unordered_map<std::string, int> data;
Caches_in_Powertrails(PowertrailDB db); Caches_in_Powertrails(PowertrailDB db);
Caches_in_Powertrails() {}; Caches_in_Powertrails(){};
void read_from_json(std::string file); void read_from_json(std::string file);
void save_to_json(std::string file); void save_to_json(std::string file);
// void update_caches(Caches& cc);
private: private:
}; };