Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -39,8 +39,8 @@ void LogIfNotConsistent(RoutesBuilder::Result const & oldRes, RoutesBuilder::Res
bool const sameDistance = AlmostEqualAbs(oldRoute.m_distance, newRoute.m_distance, 1.0);
if (!sameETA || !sameDistance)
{
LOG(LINFO, ("old ETA:", oldRoute.m_eta, "old distance:", oldRoute.m_distance, "new ETA:",
newRoute.m_eta, "new distance:", newRoute.m_distance, start, finish));
LOG(LINFO, ("old ETA:", oldRoute.m_eta, "old distance:", oldRoute.m_distance, "new ETA:", newRoute.m_eta,
"new distance:", newRoute.m_distance, start, finish));
}
}
@@ -52,9 +52,7 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
bars.clear();
labels.clear();
std::sort(times.begin(), times.end(), [](auto const & a, auto const & b) {
return a.m_oldTime < b.m_oldTime;
});
std::sort(times.begin(), times.end(), [](auto const & a, auto const & b) { return a.m_oldTime < b.m_oldTime; });
size_t constexpr kSteps = 10;
size_t const step = times.size() / kSteps;
@@ -78,8 +76,8 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
startFrom = i + 1;
double const curRight = times[i].m_oldTime;
labels.emplace_back("[" + strings::to_string_dac(curLeft, 2 /* dac */) + "s, " +
strings::to_string_dac(curRight, 2 /* dac */) + "s]\\n" +
"Routes count:\\n" + std::to_string(curCount));
strings::to_string_dac(curRight, 2 /* dac */) + "s]\\n" + "Routes count:\\n" +
std::to_string(curCount));
if (curCount != 0)
{
curSumOld /= curCount;
@@ -92,8 +90,7 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
}
}
std::vector<double> GetBoostPercents(BenchmarkResults const & oldResults,
BenchmarkResults const & newResults)
std::vector<double> GetBoostPercents(BenchmarkResults const & oldResults, BenchmarkResults const & newResults)
{
std::vector<double> boostPercents;
for (size_t i = 0; i < oldResults.GetBuildTimes().size(); ++i)
@@ -135,9 +132,8 @@ static std::string const kPythonEtaDiffPercent = "eta_diff_percent.py";
// see here: https://github.com/mapsme/omim/pull/12401
static std::string const kPythonSmartDistr = "show_smart_boost_distr.py";
void RunBenchmarkStat(
std::vector<std::pair<RoutesBuilder::Result, std::string>> const & mapsmeResults,
std::string const & dirForResults)
void RunBenchmarkStat(std::vector<std::pair<RoutesBuilder::Result, std::string>> const & mapsmeResults,
std::string const & dirForResults)
{
BenchmarkResults benchmarkResults;
ErrorTypeCounter errorTypeCounter;
@@ -153,8 +149,7 @@ void RunBenchmarkStat(
}
auto pythonScriptPath = base::JoinPath(dirForResults, kPythonDistTimeBuilding);
CreatePythonScriptForDistribution(pythonScriptPath, "Route building time, seconds",
benchmarkResults.GetBuildTimes());
CreatePythonScriptForDistribution(pythonScriptPath, "Route building time, seconds", benchmarkResults.GetBuildTimes());
LOG(LINFO, ("Average route time building:", benchmarkResults.GetAverageBuildTime(), "seconds."));
@@ -168,10 +163,9 @@ void RunBenchmarkStat(
}
pythonScriptPath = base::JoinPath(dirForResults, kPythonGraphTimeAndCount);
CreatePythonGraphByPointsXY(pythonScriptPath,
"Building time, seconds" /* xlabel */,
"Percent of routes built less than" /* ylabel */,
{countToTimes}, {"mapsme"} /* legends */);
CreatePythonGraphByPointsXY(pythonScriptPath, "Building time, seconds" /* xlabel */,
"Percent of routes built less than" /* ylabel */, {countToTimes},
{"mapsme"} /* legends */);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarError);
@@ -179,14 +173,13 @@ void RunBenchmarkStat(
std::vector<double> heights;
FillLabelsAndErrorTypeDistribution(labels, heights, errorTypeCounter);
CreatePythonBarByMap(pythonScriptPath, labels, {heights}, {"mapsme"} /* legends */,
"Type of errors" /* xlabel */, "Number of errors" /* ylabel */);
CreatePythonBarByMap(pythonScriptPath, labels, {heights}, {"mapsme"} /* legends */, "Type of errors" /* xlabel */,
"Number of errors" /* ylabel */);
}
void RunBenchmarkComparison(
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeResults,
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeOldResults,
std::string const & dirForResults)
void RunBenchmarkComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeResults,
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeOldResults,
std::string const & dirForResults)
{
BenchmarkResults benchmarkResults;
BenchmarkResults benchmarkOldResults;
@@ -227,8 +220,7 @@ void RunBenchmarkComparison(
LogIfNotConsistent(mapsmeOldResult, mapsmeResult);
CHECK(!mapsmeOldResult.m_routes.empty() && !mapsmeResult.m_routes.empty(), ());
auto const etaDiff =
(mapsmeOldResult.m_routes.back().m_eta - mapsmeResult.m_routes.back().m_eta);
auto const etaDiff = (mapsmeOldResult.m_routes.back().m_eta - mapsmeResult.m_routes.back().m_eta);
auto const etaDiffPercent = etaDiff / mapsmeOldResult.m_routes.back().m_eta * 100.0;
etaDiffs.emplace_back(etaDiff);
@@ -258,9 +250,8 @@ void RunBenchmarkComparison(
auto const newAverage = benchmarkResults.GetAverageBuildTime();
auto const averageTimeDiff = (oldAverage - newAverage) / oldAverage * 100.0;
LOG(LINFO, ("Average route time building. "
"Old version:", oldAverage,
"New version:", newAverage,
"(", -averageTimeDiff, "% )"));
"Old version:",
oldAverage, "New version:", newAverage, "(", -averageTimeDiff, "% )"));
std::vector<std::vector<m2::PointD>> graphics;
for (auto const & results : {benchmarkOldResults, benchmarkResults})
@@ -287,30 +278,26 @@ void RunBenchmarkComparison(
FillLabelsAndErrorTypeDistribution(labels, errorsCount, errorTypeCounter, errorTypeCounterOld);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarError);
CreatePythonBarByMap(pythonScriptPath, labels, errorsCount,
{"old mapsme", "new mapsme"} /* legends */, "Type of errors" /* xlabel */,
"Number of errors" /* ylabel */);
CreatePythonBarByMap(pythonScriptPath, labels, errorsCount, {"old mapsme", "new mapsme"} /* legends */,
"Type of errors" /* xlabel */, "Number of errors" /* ylabel */);
auto const boostPercents = GetBoostPercents(benchmarkOldResults, benchmarkResults);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarBoostPercentDistr);
CreatePythonScriptForDistribution(pythonScriptPath, "Boost percent" /* title */, boostPercents);
pythonScriptPath = base::JoinPath(dirForResults, kPythonEtaDiff);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff distribution" /* title */,
etaDiffs);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff distribution" /* title */, etaDiffs);
pythonScriptPath = base::JoinPath(dirForResults, kPythonEtaDiffPercent);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff percent distribution" /* title */,
etaDiffsPercent);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff percent distribution" /* title */, etaDiffsPercent);
std::vector<std::vector<double>> bars;
FillInfoAboutBuildTimeGroupByPreviousResults(labels, bars, std::move(times));
pythonScriptPath = base::JoinPath(dirForResults, kPythonSmartDistr);
CreatePythonBarByMap(
pythonScriptPath, labels, bars, {"old mapsme", "new mapsme"} /* legends */,
"Intervals of groups (build time in old mapsme)" /* xlabel */,
"Boost\\nRight column is so lower/higher than the left\\n how much the average build time "
"has decreased in each group)" /* ylabel */,
false /* drawPercents */);
CreatePythonBarByMap(pythonScriptPath, labels, bars, {"old mapsme", "new mapsme"} /* legends */,
"Intervals of groups (build time in old mapsme)" /* xlabel */,
"Boost\\nRight column is so lower/higher than the left\\n how much the average build time "
"has decreased in each group)" /* ylabel */,
false /* drawPercents */);
}
} // namespace routing_quality::routing_quality_tool

View File

@@ -12,8 +12,7 @@ using RouteResult = routing::routes_builder::RoutesBuilder::Result;
void RunBenchmarkStat(std::vector<std::pair<RouteResult, std::string>> const & mapsmeResults,
std::string const & dirForResults);
void RunBenchmarkComparison(
std::vector<std::pair<RouteResult, std::string>> && mapsmeResults,
std::vector<std::pair<RouteResult, std::string>> && mapsmeOldResults,
std::string const & dirForResults);
void RunBenchmarkComparison(std::vector<std::pair<RouteResult, std::string>> && mapsmeResults,
std::vector<std::pair<RouteResult, std::string>> && mapsmeOldResults,
std::string const & dirForResults);
} // namespace routing_quality::routing_quality_tool

View File

@@ -22,8 +22,7 @@ void ErrorTypeCounter::PushError(api::ResultCode code)
PushError(routingCode);
}
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<double> & errorsTypeDistribution,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels, std::vector<double> & errorsTypeDistribution,
ErrorTypeCounter const & counter)
{
errorsTypeDistribution.clear();
@@ -37,8 +36,7 @@ void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<std::vector<double>> & errorsTypeDistribution,
ErrorTypeCounter const & counter,
ErrorTypeCounter const & counterOld)
ErrorTypeCounter const & counter, ErrorTypeCounter const & counterOld)
{
errorsTypeDistribution.clear();
errorsTypeDistribution.resize(2);

View File

@@ -22,12 +22,10 @@ private:
std::map<std::string, size_t> m_errorCounter;
};
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<double> & errorsTypeDistribution,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels, std::vector<double> & errorsTypeDistribution,
ErrorTypeCounter const & counter);
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<std::vector<double>> & errorsTypeDistribution,
ErrorTypeCounter const & counter,
ErrorTypeCounter const & counterOld);
ErrorTypeCounter const & counter, ErrorTypeCounter const & counterOld);
} // namespace routing_quality::routing_quality_tool

View File

@@ -1,6 +1,6 @@
#include "routing/routing_quality/routing_quality_tool/utils.hpp"
#include "routing/routing_quality/routing_quality_tool/benchmark_stat.hpp"
#include "routing/routing_quality/routing_quality_tool/error_type_counter.hpp"
#include "routing/routing_quality/routing_quality_tool/utils.hpp"
#include "routing/routing_quality/api/api.hpp"
@@ -28,8 +28,9 @@ DEFINE_string(api_results, "", "Path to directory with api router results.");
DEFINE_string(save_results, "", "The directory where results of tool will be saved.");
DEFINE_double(kml_percent, 0.0, "The percent of routes for which kml file will be generated."
"With kml files you can make screenshots with a desktop app");
DEFINE_double(kml_percent, 0.0,
"The percent of routes for which kml file will be generated."
"With kml files you can make screenshots with a desktop app");
DEFINE_bool(benchmark_stat, false, "Dump statistics about route time building.");
@@ -60,7 +61,8 @@ This tool takes two paths to directory with routes, that were dumped by routes_b
--kml_percent may be used in non-benchamrk mode for dumping kmls and visual comparison different routes.
)";
auto const addStringInfo = [&usage](auto const & arg, auto const & argValue) {
auto const addStringInfo = [&usage](auto const & arg, auto const & argValue)
{
using T = decltype(argValue);
usage << "\n\t" << arg << " is";
if (argValue == T{})
@@ -91,7 +93,7 @@ bool HasHelpFlags(int argc, char ** argv)
}
return false;
}
} // namespace
} // namespace
using namespace routing;
using namespace routes_builder;
@@ -166,8 +168,7 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
{
ErrorTypeCounter mapsmeErrorCounter;
ErrorTypeCounter anotherErrorCounter;
ComparisonType type = IsMapsmeVsApi() ? ComparisonType::MapsmeVsApi
: ComparisonType::MapsmeVsMapsme;
ComparisonType type = IsMapsmeVsApi() ? ComparisonType::MapsmeVsApi : ComparisonType::MapsmeVsMapsme;
RoutesSaver routesSaver(FLAGS_save_results, type);
std::vector<Result> results;
size_t apiErrors = 0;
@@ -212,16 +213,15 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
for (auto const & route : anotherResult.GetRoutes())
{
auto const similarity =
metrics::CompareByNumberOfMatchedWaypoints(mapsmeRoute.m_followedPolyline,
route.GetWaypoints());
metrics::CompareByNumberOfMatchedWaypoints(mapsmeRoute.m_followedPolyline, route.GetWaypoints());
if (maxSimilarity < similarity)
{
maxSimilarity = similarity;
if (maxSimilarity == 1.0)
{
etaDiff = 100.0 * std::abs(route.GetETA() - mapsmeRoute.GetETA()) /
std::max(route.GetETA(), mapsmeRoute.GetETA());
etaDiff =
100.0 * std::abs(route.GetETA() - mapsmeRoute.GetETA()) / std::max(route.GetETA(), mapsmeRoute.GetETA());
}
}
}
@@ -236,8 +236,7 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
std::vector<std::string> errorLabels;
std::vector<std::vector<double>> errorsCount;
FillLabelsAndErrorTypeDistribution(errorLabels, errorsCount, mapsmeErrorCounter,
anotherErrorCounter);
FillLabelsAndErrorTypeDistribution(errorLabels, errorsCount, mapsmeErrorCounter, anotherErrorCounter);
auto const pythonScriptPath = base::JoinPath(FLAGS_save_results, kPythonBarDistributionError);
CreatePythonBarByMap(pythonScriptPath, errorLabels, errorsCount,
@@ -247,14 +246,13 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
void CheckArgs()
{
bool const modeIsChosen = IsMapsmeVsApi() || IsMapsmeVsMapsme() || IsMapsmeBenchmarkStat() ||
IsMapsmeVsMapsmeBenchmarkStat();
bool const modeIsChosen =
IsMapsmeVsApi() || IsMapsmeVsMapsme() || IsMapsmeBenchmarkStat() || IsMapsmeVsMapsmeBenchmarkStat();
if (!modeIsChosen)
PrintHelpAndExit();
CHECK(!FLAGS_save_results.empty(),
("\n\n\t--save_results is required. Tool will save results there.",
"\n\nType --help for usage."));
("\n\n\t--save_results is required. Tool will save results there.", "\n\nType --help for usage."));
}
int Main(int argc, char ** argv)
@@ -269,12 +267,11 @@ int Main(int argc, char ** argv)
if (Platform::IsFileExistsByFullPath(FLAGS_save_results))
CheckDirExistence(FLAGS_save_results);
else
CHECK_EQUAL(Platform::MkDir(FLAGS_save_results), Platform::EError::ERR_OK,());
CHECK_EQUAL(Platform::MkDir(FLAGS_save_results), Platform::EError::ERR_OK, ());
CheckDirExistence(FLAGS_mapsme_results);
CHECK(0.0 <= FLAGS_kml_percent && FLAGS_kml_percent <= 100.0,
("--kml_percent should be in interval: [0.0, 100.0]."));
CHECK(0.0 <= FLAGS_kml_percent && FLAGS_kml_percent <= 100.0, ("--kml_percent should be in interval: [0.0, 100.0]."));
LOG(LINFO, ("Start loading mapsme results."));
auto mapsmeResults = LoadResults<RoutesBuilder::Result>(FLAGS_mapsme_results);
@@ -292,8 +289,7 @@ int Main(int argc, char ** argv)
LOG(LINFO, ("Benchmark different mapsme versions. Start loading old mapsme results."));
auto oldMapsmeResults = LoadResults<RoutesBuilder::Result>(FLAGS_mapsme_old_results);
LOG(LINFO, ("Receive:", oldMapsmeResults.size(), "routes from --mapsme_old_results."));
RunBenchmarkComparison(std::move(mapsmeResults), std::move(oldMapsmeResults),
FLAGS_save_results);
RunBenchmarkComparison(std::move(mapsmeResults), std::move(oldMapsmeResults), FLAGS_save_results);
}
else if (IsMapsmeVsMapsme())
{

View File

@@ -30,8 +30,7 @@ void PrintWithSpaces(std::string const & str, size_t maxN)
std::cout << " ";
}
std::vector<geometry::PointWithAltitude> ConvertToPointsWithAltitudes(
std::vector<ms::LatLon> const & latlons)
std::vector<geometry::PointWithAltitude> ConvertToPointsWithAltitudes(std::vector<ms::LatLon> const & latlons)
{
std::vector<geometry::PointWithAltitude> result;
result.reserve(latlons.size());
@@ -63,8 +62,7 @@ kml::BookmarkData CreateBookmark(m2::PointD const & point, bool isStart)
}
template <typename AnotherResult>
void SaveKmlFileDataTo(RoutesBuilder::Result const & mapsmeResult,
AnotherResult const & apiResult,
void SaveKmlFileDataTo(RoutesBuilder::Result const & mapsmeResult, AnotherResult const & apiResult,
std::string const & kmlFile)
{
static std::array<uint32_t, 5> const kColors = {
@@ -140,15 +138,15 @@ namespace routing_quality
{
namespace routing_quality_tool
{
Result::Result(std::string mapsmeDumpPath, std::string anotherDumpPath,
ms::LatLon const & start, ms::LatLon const & finish, double similarity,
double etaDiffPercent)
Result::Result(std::string mapsmeDumpPath, std::string anotherDumpPath, ms::LatLon const & start,
ms::LatLon const & finish, double similarity, double etaDiffPercent)
: m_mapsmeDumpPath(std::move(mapsmeDumpPath))
, m_anotherDumpPath(std::move(anotherDumpPath))
, m_start(start)
, m_finish(finish)
, m_similarity(similarity)
, m_etaDiffPercent(etaDiffPercent) {}
, m_etaDiffPercent(etaDiffPercent)
{}
bool Result::operator<(Result const & rhs) const
{
@@ -168,17 +166,14 @@ void RoutesSaver::PushRoute(Result const & result)
m_output << result.m_mapsmeDumpPath << " " << result.m_anotherDumpPath << std::endl;
}
void RoutesSaver::PushError(routing::RouterResultCode code,
ms::LatLon const & start,
ms::LatLon const & finish)
void RoutesSaver::PushError(routing::RouterResultCode code, ms::LatLon const & start, ms::LatLon const & finish)
{
CHECK_NOT_EQUAL(code, routing::RouterResultCode::NoError, ("Only errors codes."));
auto & ofstream = m_errorRoutes[code];
if (!ofstream.is_open())
{
std::string const fullpath =
base::JoinPath(m_targetDir, DebugPrint(code) + ".routes");
std::string const fullpath = base::JoinPath(m_targetDir, DebugPrint(code) + ".routes");
ofstream.open(fullpath);
CHECK(ofstream.good(), ("Can not open:", fullpath, "for writing."));
@@ -217,8 +212,7 @@ void RoutesSaver::TurnToNextFile()
std::string RoutesSaver::GetCurrentPath() const
{
std::string const fullpath =
base::JoinPath(m_targetDir, std::to_string(m_fileNumber) + ".routes");
std::string const fullpath = base::JoinPath(m_targetDir, std::to_string(m_fileNumber) + ".routes");
return fullpath;
}
@@ -241,18 +235,13 @@ void RoutesSaver::OpenOutputStream()
m_output << std::setprecision(20);
}
void RoutesSaver::WriteStartAndFinish(std::ofstream & output,
ms::LatLon const & start,
ms::LatLon const & finish)
void RoutesSaver::WriteStartAndFinish(std::ofstream & output, ms::LatLon const & start, ms::LatLon const & finish)
{
output << start.m_lat << " " << start.m_lon << " "
<< finish.m_lat << " " << finish.m_lon
<< std::endl;
output << start.m_lat << " " << start.m_lon << " " << finish.m_lat << " " << finish.m_lon << std::endl;
}
// This function creates python script that shows the distribution error.
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
std::string const & title,
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath, std::string const & title,
std::vector<double> const & values)
{
std::ofstream python(pythonScriptPath);
@@ -271,19 +260,19 @@ void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
import numpy as np
import matplotlib.pyplot as plt
a = np.hstack()" + pythonArray + R"()
a = np.hstack()" +
pythonArray + R"()
plt.hist(a, bins='auto') # arguments are passed to np.histogram
plt.title(")" + title + R"(")
plt.title(")" + title +
R"(")
plt.show()
)";
LOG(LINFO, ("Run: python", pythonScriptPath, "to look at:", title));
}
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
std::string const & xlabel,
std::string const & ylabel,
std::vector<std::vector<m2::PointD>> const & graphics,
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath, std::string const & xlabel,
std::string const & ylabel, std::vector<std::vector<m2::PointD>> const & graphics,
std::vector<std::string> const & legends)
{
CHECK_EQUAL(legends.size(), graphics.size(), ());
@@ -316,14 +305,19 @@ void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
python << R"(
import pylab
legends = )" + legendsArray + R"(
xlist = )" + pythonArrayX + R"(
ylist = )" + pythonArrayY + R"(
legends = )" + legendsArray +
R"(
xlist = )" + pythonArrayX +
R"(
ylist = )" + pythonArrayY +
R"(
for (x, y, l) in zip(xlist, ylist, legends):
pylab.plot(x, y, label=l)
pylab.xlabel(")" + xlabel + R"(")
pylab.ylabel(")" + ylabel + R"(")
pylab.xlabel(")" +
xlabel + R"(")
pylab.ylabel(")" +
ylabel + R"(")
pylab.legend()
pylab.tight_layout()
pylab.show()
@@ -332,13 +326,9 @@ pylab.show()
LOG(LINFO, ("Run: python", pythonScriptPath, "to look at:", ylabel, "versus", xlabel));
}
void CreatePythonBarByMap(std::string const & pythonScriptPath,
std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights,
std::vector<std::string> const & legends,
std::string const & xlabel,
std::string const & ylabel,
bool drawPercents)
void CreatePythonBarByMap(std::string const & pythonScriptPath, std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights, std::vector<std::string> const & legends,
std::string const & xlabel, std::string const & ylabel, bool drawPercents)
{
std::ofstream python(pythonScriptPath);
CHECK(python.good(), ("Can not open:", pythonScriptPath, "for writing."));
@@ -354,9 +344,8 @@ void CreatePythonBarByMap(std::string const & pythonScriptPath,
else
counts.back() = ']';
std::string const formatString = drawPercents
? "f'{round(height, 2)}({round(height / summ * 100, 2)}%)'"
: "f'{round(height, 2)}'";
std::string const formatString =
drawPercents ? "f'{round(height, 2)}({round(height / summ * 100, 2)}%)'" : "f'{round(height, 2)}'";
python << R"(
import matplotlib
@@ -364,9 +353,12 @@ import matplotlib.pyplot as plt
import numpy as np
bar_width = 0.35
labels = )" + labelsArray + R"(
legends = )" + legendsArray + R"(
counts = )" + counts + R"(
labels = )" + labelsArray +
R"(
legends = )" + legendsArray +
R"(
counts = )" + counts +
R"(
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
@@ -377,8 +369,10 @@ for i in range(len(counts)):
bar = ax.bar(x + i * bar_width, counts[i], bar_width, label=legends[i])
bars.append(bar)
ax.set_ylabel(')" + ylabel + R"(')
ax.set_title(')" + xlabel + R"(')
ax.set_ylabel(')" +
ylabel + R"(')
ax.set_title(')" +
xlabel + R"(')
pos = (bar_width * (len(counts) - 1)) / 2
ax.set_xticks(x + pos)
ax.set_xticklabels(labels)
@@ -391,7 +385,8 @@ def autolabel(rects, counts_ith):
for rect in rects:
height = rect.get_height()
ax.annotate()" + formatString + R"(,
ax.annotate()" +
formatString + R"(,
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
@@ -408,19 +403,12 @@ plt.show()
/// \brief |SimilarityCounter| groups routes that we compare by similarity, here we tune these groups.
// static
std::vector<SimilarityCounter::Interval> const SimilarityCounter::kIntervals = {
{"[0.0, 0.0]", 0, 0 + 1e-5},
{"[0.0, 0.1)", 0, 0.1},
{"[0.1, 0.2)", 0.1, 0.2},
{"[0.2, 0.3)", 0.2, 0.3},
{"[0.3, 0.6)", 0.3, 0.6},
{"[0.6, 0.8)", 0.6, 0.8},
{"[0.8, 1.0)", 0.8, 1.0},
{"[1.0, 1.0]", 1.0, 1.0 + 1e-5},
std::vector<SimilarityCounter::Interval> const SimilarityCounter::kIntervals = {
{"[0.0, 0.0]", 0, 0 + 1e-5}, {"[0.0, 0.1)", 0, 0.1}, {"[0.1, 0.2)", 0.1, 0.2}, {"[0.2, 0.3)", 0.2, 0.3},
{"[0.3, 0.6)", 0.3, 0.6}, {"[0.6, 0.8)", 0.6, 0.8}, {"[0.8, 1.0)", 0.8, 1.0}, {"[1.0, 1.0]", 1.0, 1.0 + 1e-5},
};
SimilarityCounter::SimilarityCounter(RoutesSaver & routesSaver)
: m_routesSaver(routesSaver)
SimilarityCounter::SimilarityCounter(RoutesSaver & routesSaver) : m_routesSaver(routesSaver)
{
for (auto const & interval : kIntervals)
m_routesCounter.emplace_back(interval.m_name, 0);
@@ -466,9 +454,8 @@ void SimilarityCounter::Push(Result const & result)
CHECK_LESS(m_currentInterval, m_routesCounter.size(), ());
if (m_routesCounter[m_currentInterval].m_routesNumber == 0)
{
LOG(LINFO,
("Save routes with:", m_routesCounter[m_currentInterval].m_intervalName,
"similarity to:", m_routesSaver.GetCurrentPath()));
LOG(LINFO, ("Save routes with:", m_routesCounter[m_currentInterval].m_intervalName,
"similarity to:", m_routesSaver.GetCurrentPath()));
}
CHECK_LESS(m_currentInterval, m_routesCounter.size(), ());
@@ -481,8 +468,7 @@ void SimilarityCounter::CreateKmlFiles(double percent, std::vector<Result> const
size_t realResultIndex = 0;
for (size_t intervalId = 0; intervalId < m_routesCounter.size(); ++intervalId)
{
std::string savePath =
base::JoinPath(m_routesSaver.GetTargetDir(), std::to_string(intervalId));
std::string savePath = base::JoinPath(m_routesSaver.GetTargetDir(), std::to_string(intervalId));
auto const currentSize = m_routesCounter[intervalId].m_routesNumber;
auto const resultSize = static_cast<size_t>(currentSize * percent / 100.0);
@@ -490,13 +476,10 @@ void SimilarityCounter::CreateKmlFiles(double percent, std::vector<Result> const
continue;
auto const mkdirRes = Platform::MkDir(savePath);
CHECK(mkdirRes == Platform::EError::ERR_OK ||
mkdirRes == Platform::EError::ERR_FILE_ALREADY_EXISTS,
CHECK(mkdirRes == Platform::EError::ERR_OK || mkdirRes == Platform::EError::ERR_FILE_ALREADY_EXISTS,
("Cannot create dir:", savePath));
LOG(LINFO, ("Saving", resultSize,
"kmls for:", m_routesCounter[intervalId].m_intervalName,
"to:", savePath));
LOG(LINFO, ("Saving", resultSize, "kmls for:", m_routesCounter[intervalId].m_intervalName, "to:", savePath));
auto const step = static_cast<size_t>(currentSize / resultSize);

View File

@@ -1,7 +1,7 @@
#pragma once
#include "routing/routing_quality/api/api.hpp"
#include "routing/routes_builder/routes_builder.hpp"
#include "routing/routing_quality/api/api.hpp"
#include "routing/routing_callbacks.hpp"
@@ -72,8 +72,7 @@ bool AreRoutesWithSameEnds(routing::routes_builder::RoutesBuilder::Result const
auto const & anotherFinish = anotherResult.GetFinishPoint();
double constexpr kEps = 1e-10;
return AlmostEqualAbs(start, anotherStart, kEps) &&
AlmostEqualAbs(finish, anotherFinish, kEps);
return AlmostEqualAbs(start, anotherStart, kEps) && AlmostEqualAbs(finish, anotherFinish, kEps);
}
template <typename AnotherResult>
@@ -95,8 +94,7 @@ bool FindAnotherResponse(routing::routes_builder::RoutesBuilder::Result const &
struct Result
{
Result(std::string mapsmeDumpPath, std::string anotherDumpPath,
ms::LatLon const & start, ms::LatLon const & finish,
Result(std::string mapsmeDumpPath, std::string anotherDumpPath, ms::LatLon const & start, ms::LatLon const & finish,
double similarity, double etaDiffPercent);
bool operator<(Result const & rhs) const;
@@ -170,24 +168,17 @@ private:
std::vector<Item> m_routesCounter;
};
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
std::string const & title,
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath, std::string const & title,
std::vector<double> const & values);
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
std::string const & xlabel,
std::string const & ylabel,
std::vector<std::vector<m2::PointD>> const & graphics,
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath, std::string const & xlabel,
std::string const & ylabel, std::vector<std::vector<m2::PointD>> const & graphics,
std::vector<std::string> const & legends);
/// \brief Create python file, that show bar graph, where labels of bars are keys of |stat| and
/// heights area values of |stat|.
void CreatePythonBarByMap(std::string const & pythonScriptPath,
std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights,
std::vector<std::string> const & legends,
std::string const & xlabel,
std::string const & ylabel,
bool drawPercents = true);
void CreatePythonBarByMap(std::string const & pythonScriptPath, std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights, std::vector<std::string> const & legends,
std::string const & xlabel, std::string const & ylabel, bool drawPercents = true);
} // namespace routing_quality_tool
} // namespace routing_quality