kopia lustrzana https://gitlab.com/tomaszg/geostat
Protect timeline computation from division by zero
rodzic
3ad92da629
commit
c7d0ae948a
30
geostat.cpp
30
geostat.cpp
|
@ -405,14 +405,6 @@ int main(int argc, char** argv) {
|
|||
std::cout << "Average distance between caches: <span class=\"value\">" << tot_dist / (sorted_fcaches.size() - 1) << "</span> km<br>\n";
|
||||
std::cout << "</div>\n";
|
||||
|
||||
std::cout << "<h2>Caching timeline</h2>\n";
|
||||
std::cout << "<table class=\"calendar_tab\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
for (int j = 1; j <= 12; j++) { // print table month headers
|
||||
std::cout << "<th>" << j << "</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
short y_min = std::min_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_tm.tm_year < b.date_tm.tm_year; })->date_tm.tm_year;
|
||||
short y_max = std::max_element(cc.begin(), cc.end(), [&](const Cache& a, const Cache& b) { return a.date_tm.tm_year < b.date_tm.tm_year; })->date_tm.tm_year;
|
||||
|
||||
|
@ -421,15 +413,25 @@ int main(int argc, char** argv) {
|
|||
for (int j = 1; j <= 12; j++)
|
||||
max = std::max(max, std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); }));
|
||||
|
||||
for (int i = y_min; i <= y_max; i++) { // i -> years in rows
|
||||
std::cout << "<tr><th>" << i + 1900 << "</th> ";
|
||||
for (int j = 1; j <= 12; j++) { // j -> months in cols
|
||||
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); });
|
||||
std::cout << "<td style=\"--percent: " << count * 100 / max << "%\"><span>" << count << "</span></td>";
|
||||
if (max > 0) {
|
||||
std::cout << "<h2>Caching timeline</h2>\n";
|
||||
std::cout << "<table class=\"calendar_tab\">\n";
|
||||
std::cout << "<tr><th></th>";
|
||||
for (int j = 1; j <= 12; j++) { // print table month headers
|
||||
std::cout << "<th>" << j << "</th>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
|
||||
for (int i = y_min; i <= y_max; i++) { // i -> years in rows
|
||||
std::cout << "<tr><th>" << i + 1900 << "</th> ";
|
||||
for (int j = 1; j <= 12; j++) { // j -> months in cols
|
||||
count = std::count_if(cc.begin(), cc.end(), [i, j](Cache c) { return (c.date_tm.tm_year == i && c.date_tm.tm_mon == j - 1); });
|
||||
std::cout << "<td style=\"--percent: " << count * 100 / max << "%\"><span>" << count << "</span></td>";
|
||||
}
|
||||
std::cout << "</tr>\n";
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
}
|
||||
std::cout << "</table>\n";
|
||||
|
||||
std::cout << "<h2>Caching days per month</h2>\n";
|
||||
std::cout << "<table class=\"calendar_tab\">\n";
|
||||
|
|
Ładowanie…
Reference in New Issue