json output mode for shapevl

This commit is contained in:
Patrick Brosi 2022-01-09 23:58:18 +01:00
parent f10397db41
commit 6473dcdb52
3 changed files with 67 additions and 8 deletions

View file

@ -364,6 +364,32 @@ void Collector::printStats(std::ostream* os) const {
(*os) << std::endl;
}
// _____________________________________________________________________________
util::json::Dict Collector::getJSONStats() const {
util::json::Dict stats = {};
stats["num-trips"] = _trips;
stats["num-trips-matched"] = _results.size();
stats["num-trips-wo-shapes"] = _noOrigShp;
stats["avg-fr"] = getAvgDist();
stats["an-0"] =
(static_cast<double>(_an0) / static_cast<double>(_results.size())) * 100;
stats["an-5"] =
(static_cast<double>(_an5) / static_cast<double>(_results.size())) * 100;
stats["an-10"] =
(static_cast<double>(_an10) / static_cast<double>(_results.size())) * 100;
stats["an-30"] =
(static_cast<double>(_an30) / static_cast<double>(_results.size())) * 100;
stats["an-50"] =
(static_cast<double>(_an50) / static_cast<double>(_results.size())) * 100;
stats["an-70"] =
(static_cast<double>(_an70) / static_cast<double>(_results.size())) * 100;
stats["an-90"] =
(static_cast<double>(_an90) / static_cast<double>(_results.size())) * 100;
return stats;
}
// _____________________________________________________________________________
std::pair<size_t, double> Collector::getDa(const std::vector<LINE>& a,
const std::vector<LINE>& b) {

View file

@ -16,6 +16,7 @@
#include "pfaedle/Def.h"
#include "shapevl/Result.h"
#include "util/geo/Geo.h"
#include "util/json/Writer.h"
using ad::cppgtfs::gtfs::Shape;
using ad::cppgtfs::gtfs::Trip;
@ -57,6 +58,9 @@ class Collector {
// Print general stats to os
void printShortStats(std::ostream* os) const;
// Get JSON stats
util::json::Dict getJSONStats() const;
// Print a CSV for the results to os
void printCsv(std::ostream* os, const std::set<Result>& result) const;

View file

@ -12,6 +12,7 @@
#include "ad/cppgtfs/Parser.h"
#include "shapevl/Collector.h"
#include "util/Misc.h"
#include "util/json/Writer.h"
#include "util/log/Log.h"
std::atomic<int> count(0);
@ -25,6 +26,7 @@ void printHelp(int argc, char** argv) {
std::cout
<< "\nAllowed arguments:\n -g <gtfs> Ground truth GTFS file\n";
std::cout << " -s Only output summary\n";
std::cout << " --json Output JSON\n";
std::cout << " -f <folder> Output full reports (per feed) to <folder>\n";
std::cout
<< " -m MOTs to match (GTFS MOT or string, default: all)\n";
@ -84,6 +86,7 @@ int main(int argc, char** argv) {
std::vector<pfaedle::eval::Collector> evalColls;
std::vector<std::ofstream> reportStreams;
bool summarize = false;
bool json = false;
for (int i = 1; i < argc; i++) {
std::string cur = argv[i];
@ -98,6 +101,8 @@ int main(int argc, char** argv) {
groundTruthFeedPath = argv[i];
} else if (cur == "-s") {
summarize = true;
} else if (cur == "--json") {
json = true;
} else if (cur == "-f") {
if (++i >= argc) {
LOG(ERROR) << "Missing argument for full reports (-f).";
@ -164,15 +169,39 @@ int main(int argc, char** argv) {
for (auto& thr : thrds) thr.join();
for (size_t i = 0; i < evalColls.size(); i++) {
if (summarize) {
std::cout << evlFeedPaths[i] << ": ";
evalColls[i].printShortStats(&std::cout);
std::cout << std::endl;
if (json) {
util::json::Dict stats = {};
for (size_t i = 0; i < evalColls.size(); i++) {
stats[evlFeedPaths[i]] = evalColls[i].getJSONStats();
}
util::json::Dict jsonStats;
if (evalColls.size() == 1) {
jsonStats = {
{"statistics", stats[evlFeedPaths[0]]
}};
} else {
std::cout << " == Evaluation results for " << evlFeedPaths[i]
<< " ===" << std::endl;
evalColls[i].printStats(&std::cout);
jsonStats = {
{"statistics", stats
}};
}
util::json::Writer wr(&std::cout, 10, true);
wr.val(jsonStats);
wr.closeAll();
} else {
for (size_t i = 0; i < evalColls.size(); i++) {
if (summarize) {
std::cout << evlFeedPaths[i] << ": ";
evalColls[i].printShortStats(&std::cout);
std::cout << std::endl;
} else {
std::cout << " == Evaluation results for " << evlFeedPaths[i]
<< " ===" << std::endl;
evalColls[i].printStats(&std::cout);
}
}
}
}