kopia lustrzana https://gitlab.com/tomaszg/geostat
clang-format
rodzic
d00a852295
commit
70499296d7
11
geostat.cpp
11
geostat.cpp
|
@ -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++;
|
||||||
|
@ -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";
|
||||||
|
|
18
ocdb.cpp
18
ocdb.cpp
|
@ -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));
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
@ -103,13 +104,13 @@ void PowertrailDB::get_trail(uint n) {
|
||||||
|
|
||||||
Debug(2) << "Found " << std::distance(caches_begin, caches_end) << " caches.\n";
|
Debug(2) << "Found " << std::distance(caches_begin, caches_end) << " caches.\n";
|
||||||
|
|
||||||
for (std::sregex_iterator i = caches_begin; i!= caches_end; i++) {
|
for (std::sregex_iterator i = caches_begin; i != caches_end; i++) {
|
||||||
std::smatch match = *i;
|
std::smatch match = *i;
|
||||||
T.caches.insert(match[1].str());
|
T.caches.insert(match[1].str());
|
||||||
// Debug(2) << match[1].str();
|
// Debug(2) << match[1].str();
|
||||||
}
|
}
|
||||||
|
|
||||||
data.insert({n, T});
|
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
|
||||||
|
@ -132,7 +133,7 @@ void PowertrailDB::read_from_json(std::string file) {
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,7 +158,6 @@ 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.";
|
||||||
|
@ -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) {
|
|
||||||
// };
|
|
||||||
|
|
|
@ -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:
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue