diff --git a/src/shapevl/Collector.cpp b/src/shapevl/Collector.cpp index dffe9c9..16f4401 100644 --- a/src/shapevl/Collector.cpp +++ b/src/shapevl/Collector.cpp @@ -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(_an0) / static_cast(_results.size())) * 100; + stats["an-5"] = + (static_cast(_an5) / static_cast(_results.size())) * 100; + stats["an-10"] = + (static_cast(_an10) / static_cast(_results.size())) * 100; + stats["an-30"] = + (static_cast(_an30) / static_cast(_results.size())) * 100; + stats["an-50"] = + (static_cast(_an50) / static_cast(_results.size())) * 100; + stats["an-70"] = + (static_cast(_an70) / static_cast(_results.size())) * 100; + stats["an-90"] = + (static_cast(_an90) / static_cast(_results.size())) * 100; + + return stats; +} + // _____________________________________________________________________________ std::pair Collector::getDa(const std::vector& a, const std::vector& b) { diff --git a/src/shapevl/Collector.h b/src/shapevl/Collector.h index 27fae1f..ee17544 100644 --- a/src/shapevl/Collector.h +++ b/src/shapevl/Collector.h @@ -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) const; diff --git a/src/shapevl/ShapevlMain.cpp b/src/shapevl/ShapevlMain.cpp index 2945299..c20b951 100644 --- a/src/shapevl/ShapevlMain.cpp +++ b/src/shapevl/ShapevlMain.cpp @@ -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 count(0); @@ -25,6 +26,7 @@ void printHelp(int argc, char** argv) { std::cout << "\nAllowed arguments:\n -g Ground truth GTFS file\n"; std::cout << " -s Only output summary\n"; + std::cout << " --json Output JSON\n"; std::cout << " -f Output full reports (per feed) to \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 evalColls; std::vector 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); + } } } }