json output mode for shapevl
This commit is contained in:
parent
f10397db41
commit
6473dcdb52
3 changed files with 67 additions and 8 deletions
|
@ -364,6 +364,32 @@ void Collector::printStats(std::ostream* os) const {
|
||||||
(*os) << std::endl;
|
(*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,
|
std::pair<size_t, double> Collector::getDa(const std::vector<LINE>& a,
|
||||||
const std::vector<LINE>& b) {
|
const std::vector<LINE>& b) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "pfaedle/Def.h"
|
#include "pfaedle/Def.h"
|
||||||
#include "shapevl/Result.h"
|
#include "shapevl/Result.h"
|
||||||
#include "util/geo/Geo.h"
|
#include "util/geo/Geo.h"
|
||||||
|
#include "util/json/Writer.h"
|
||||||
|
|
||||||
using ad::cppgtfs::gtfs::Shape;
|
using ad::cppgtfs::gtfs::Shape;
|
||||||
using ad::cppgtfs::gtfs::Trip;
|
using ad::cppgtfs::gtfs::Trip;
|
||||||
|
@ -57,6 +58,9 @@ class Collector {
|
||||||
// Print general stats to os
|
// Print general stats to os
|
||||||
void printShortStats(std::ostream* os) const;
|
void printShortStats(std::ostream* os) const;
|
||||||
|
|
||||||
|
// Get JSON stats
|
||||||
|
util::json::Dict getJSONStats() const;
|
||||||
|
|
||||||
// Print a CSV for the results to os
|
// Print a CSV for the results to os
|
||||||
void printCsv(std::ostream* os, const std::set<Result>& result) const;
|
void printCsv(std::ostream* os, const std::set<Result>& result) const;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "ad/cppgtfs/Parser.h"
|
#include "ad/cppgtfs/Parser.h"
|
||||||
#include "shapevl/Collector.h"
|
#include "shapevl/Collector.h"
|
||||||
#include "util/Misc.h"
|
#include "util/Misc.h"
|
||||||
|
#include "util/json/Writer.h"
|
||||||
#include "util/log/Log.h"
|
#include "util/log/Log.h"
|
||||||
|
|
||||||
std::atomic<int> count(0);
|
std::atomic<int> count(0);
|
||||||
|
@ -25,6 +26,7 @@ void printHelp(int argc, char** argv) {
|
||||||
std::cout
|
std::cout
|
||||||
<< "\nAllowed arguments:\n -g <gtfs> Ground truth GTFS file\n";
|
<< "\nAllowed arguments:\n -g <gtfs> Ground truth GTFS file\n";
|
||||||
std::cout << " -s Only output summary\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 << " -f <folder> Output full reports (per feed) to <folder>\n";
|
||||||
std::cout
|
std::cout
|
||||||
<< " -m MOTs to match (GTFS MOT or string, default: all)\n";
|
<< " -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<pfaedle::eval::Collector> evalColls;
|
||||||
std::vector<std::ofstream> reportStreams;
|
std::vector<std::ofstream> reportStreams;
|
||||||
bool summarize = false;
|
bool summarize = false;
|
||||||
|
bool json = false;
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
std::string cur = argv[i];
|
std::string cur = argv[i];
|
||||||
|
@ -98,6 +101,8 @@ int main(int argc, char** argv) {
|
||||||
groundTruthFeedPath = argv[i];
|
groundTruthFeedPath = argv[i];
|
||||||
} else if (cur == "-s") {
|
} else if (cur == "-s") {
|
||||||
summarize = true;
|
summarize = true;
|
||||||
|
} else if (cur == "--json") {
|
||||||
|
json = true;
|
||||||
} else if (cur == "-f") {
|
} else if (cur == "-f") {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
LOG(ERROR) << "Missing argument for full reports (-f).";
|
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 (auto& thr : thrds) thr.join();
|
||||||
|
|
||||||
for (size_t i = 0; i < evalColls.size(); i++) {
|
if (json) {
|
||||||
if (summarize) {
|
util::json::Dict stats = {};
|
||||||
std::cout << evlFeedPaths[i] << ": ";
|
|
||||||
evalColls[i].printShortStats(&std::cout);
|
for (size_t i = 0; i < evalColls.size(); i++) {
|
||||||
std::cout << std::endl;
|
stats[evlFeedPaths[i]] = evalColls[i].getJSONStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
util::json::Dict jsonStats;
|
||||||
|
|
||||||
|
if (evalColls.size() == 1) {
|
||||||
|
jsonStats = {
|
||||||
|
{"statistics", stats[evlFeedPaths[0]]
|
||||||
|
}};
|
||||||
} else {
|
} else {
|
||||||
std::cout << " == Evaluation results for " << evlFeedPaths[i]
|
jsonStats = {
|
||||||
<< " ===" << std::endl;
|
{"statistics", stats
|
||||||
evalColls[i].printStats(&std::cout);
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue