mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-07 13:03:54 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -33,8 +33,7 @@ vector<DataPoint> ReadDataPoints(string const & data)
|
||||
|
||||
try
|
||||
{
|
||||
coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src,
|
||||
points);
|
||||
coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, points);
|
||||
}
|
||||
catch (Reader::SizeException const & e)
|
||||
{
|
||||
@@ -48,11 +47,12 @@ vector<DataPoint> ReadDataPoints(string const & data)
|
||||
class PointToMwmId final
|
||||
{
|
||||
public:
|
||||
PointToMwmId(shared_ptr<m4::Tree<routing::NumMwmId>> mwmTree,
|
||||
routing::NumMwmIds const & numMwmIds, string const & dataDir)
|
||||
PointToMwmId(shared_ptr<m4::Tree<routing::NumMwmId>> mwmTree, routing::NumMwmIds const & numMwmIds,
|
||||
string const & dataDir)
|
||||
: m_mwmTree(mwmTree)
|
||||
{
|
||||
numMwmIds.ForEachId([&](routing::NumMwmId numMwmId) {
|
||||
numMwmIds.ForEachId([&](routing::NumMwmId numMwmId)
|
||||
{
|
||||
string const & mwmName = numMwmIds.GetFile(numMwmId).GetName();
|
||||
string const polyFile = base::JoinPath(dataDir, BORDERS_DIR, mwmName + BORDERS_EXTENSION);
|
||||
borders::LoadBorders(polyFile, m_borders[numMwmId]);
|
||||
@@ -66,7 +66,8 @@ public:
|
||||
|
||||
routing::NumMwmId result = routing::kFakeNumMwmId;
|
||||
m2::RectD const rect = mercator::RectByCenterXYAndSizeInMeters(point, 1);
|
||||
m_mwmTree->ForEachInRect(rect, [&](routing::NumMwmId numMwmId) {
|
||||
m_mwmTree->ForEachInRect(rect, [&](routing::NumMwmId numMwmId)
|
||||
{
|
||||
if (result == routing::kFakeNumMwmId && m2::RegionsContain(GetBorders(numMwmId), point))
|
||||
result = numMwmId;
|
||||
});
|
||||
@@ -89,9 +90,11 @@ private:
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
LogParser::LogParser(shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
unique_ptr<m4::Tree<routing::NumMwmId>> mwmTree, string const & dataDir)
|
||||
: m_numMwmIds(std::move(numMwmIds)), m_mwmTree(std::move(mwmTree)), m_dataDir(dataDir)
|
||||
LogParser::LogParser(shared_ptr<routing::NumMwmIds> numMwmIds, unique_ptr<m4::Tree<routing::NumMwmId>> mwmTree,
|
||||
string const & dataDir)
|
||||
: m_numMwmIds(std::move(numMwmIds))
|
||||
, m_mwmTree(std::move(mwmTree))
|
||||
, m_dataDir(dataDir)
|
||||
{
|
||||
CHECK(m_numMwmIds, ());
|
||||
CHECK(m_mwmTree, ());
|
||||
@@ -145,10 +148,9 @@ void LogParser::ParseUserTracks(string const & logFile, UserToTrack & userToTrac
|
||||
pointsCount += packet.size();
|
||||
};
|
||||
|
||||
LOG(LINFO, ("Tracks parsing finished, elapsed:", timer.ElapsedSeconds(), "seconds, lines:",
|
||||
linesCount, ", points", pointsCount));
|
||||
LOG(LINFO, ("Users with current version:", userToTrack.size(), ", old version:",
|
||||
usersWithOldVersion.size()));
|
||||
LOG(LINFO, ("Tracks parsing finished, elapsed:", timer.ElapsedSeconds(), "seconds, lines:", linesCount, ", points",
|
||||
pointsCount));
|
||||
LOG(LINFO, ("Users with current version:", userToTrack.size(), ", old version:", usersWithOldVersion.size()));
|
||||
}
|
||||
|
||||
void LogParser::SplitIntoMwms(UserToTrack const & userToTrack, MwmToTracks & mwmToTracks) const
|
||||
@@ -173,7 +175,6 @@ void LogParser::SplitIntoMwms(UserToTrack const & userToTrack, MwmToTracks & mwm
|
||||
}
|
||||
}
|
||||
|
||||
LOG(LINFO, ("Data was split into", mwmToTracks.size(), "mwms, elapsed:", timer.ElapsedSeconds(),
|
||||
"seconds"));
|
||||
LOG(LINFO, ("Data was split into", mwmToTracks.size(), "mwms, elapsed:", timer.ElapsedSeconds(), "seconds"));
|
||||
}
|
||||
} // namespace track_analyzing
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace track_analyzing
|
||||
class LogParser final
|
||||
{
|
||||
public:
|
||||
LogParser(std::shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
std::unique_ptr<m4::Tree<routing::NumMwmId>> mwmTree, std::string const & dataDir);
|
||||
LogParser(std::shared_ptr<routing::NumMwmIds> numMwmIds, std::unique_ptr<m4::Tree<routing::NumMwmId>> mwmTree,
|
||||
std::string const & dataDir);
|
||||
|
||||
void Parse(std::string const & logFile, MwmToTracks & mwmToTracks) const;
|
||||
|
||||
|
||||
@@ -27,10 +27,7 @@ namespace track_analyzing
|
||||
class MwmToMatchedTracksSerializer final
|
||||
{
|
||||
public:
|
||||
MwmToMatchedTracksSerializer(std::shared_ptr<routing::NumMwmIds> numMwmIds)
|
||||
: m_numMwmIds(std::move(numMwmIds))
|
||||
{
|
||||
}
|
||||
MwmToMatchedTracksSerializer(std::shared_ptr<routing::NumMwmIds> numMwmIds) : m_numMwmIds(std::move(numMwmIds)) {}
|
||||
|
||||
template <typename Sink>
|
||||
void Serialize(MwmToMatchedTracks const & mwmToMatchedTracks, Sink & sink)
|
||||
@@ -68,8 +65,8 @@ public:
|
||||
|
||||
std::vector<uint8_t> buffer;
|
||||
MemWriter<decltype(buffer)> memWriter(buffer);
|
||||
coding::TrafficGPSEncoder::SerializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion,
|
||||
memWriter, dataPoints);
|
||||
coding::TrafficGPSEncoder::SerializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, memWriter,
|
||||
dataPoints);
|
||||
|
||||
WriteSize(sink, buffer.size());
|
||||
sink.Write(buffer.data(), buffer.size());
|
||||
@@ -123,8 +120,8 @@ public:
|
||||
ReaderSource<MemReader> memSrc(memReader);
|
||||
|
||||
std::vector<DataPoint> dataPoints;
|
||||
coding::TrafficGPSEncoder::DeserializeDataPoints(
|
||||
coding::TrafficGPSEncoder::kLatestVersion, memSrc, dataPoints);
|
||||
coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, memSrc,
|
||||
dataPoints);
|
||||
CHECK_EQUAL(numSegments, dataPoints.size(), ("mwm:", mwmName, "user:", user));
|
||||
|
||||
MatchedTrack & track = tracks[iTrack];
|
||||
|
||||
@@ -10,8 +10,7 @@ TemporaryFile::TemporaryFile() : m_filePath(GetPlatform().TmpPathForFile()) {}
|
||||
|
||||
TemporaryFile::TemporaryFile(std::string const & namePrefix, std::string const & nameSuffix)
|
||||
: m_filePath(GetPlatform().TmpPathForFile(namePrefix, nameSuffix))
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
TemporaryFile::~TemporaryFile()
|
||||
{
|
||||
|
||||
@@ -13,10 +13,7 @@ public:
|
||||
|
||||
~TemporaryFile();
|
||||
|
||||
std::string const & GetFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
std::string const & GetFilePath() const { return m_filePath; }
|
||||
|
||||
void WriteData(std::string const & data);
|
||||
|
||||
|
||||
@@ -2,18 +2,15 @@
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
TrackFilter::TrackFilter(uint64_t minDuration, double minLength, double minSpeed, double maxSpeed,
|
||||
bool ignoreTraffic)
|
||||
TrackFilter::TrackFilter(uint64_t minDuration, double minLength, double minSpeed, double maxSpeed, bool ignoreTraffic)
|
||||
: m_minDuration(minDuration)
|
||||
, m_minLength(minLength)
|
||||
, m_minSpeed(minSpeed)
|
||||
, m_maxSpeed(maxSpeed)
|
||||
, m_ignoreTraffic(ignoreTraffic)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool TrackFilter::Passes(uint64_t duration, double length, double speed,
|
||||
bool hasTrafficPoints) const
|
||||
bool TrackFilter::Passes(uint64_t duration, double length, double speed, bool hasTrafficPoints) const
|
||||
{
|
||||
if (duration < m_minDuration)
|
||||
return false;
|
||||
|
||||
@@ -21,9 +21,9 @@ class MatchedTrackPoint final
|
||||
{
|
||||
public:
|
||||
MatchedTrackPoint(DataPoint const & dataPoint, routing::Segment const & segment)
|
||||
: m_dataPoint(dataPoint), m_segment(segment)
|
||||
{
|
||||
}
|
||||
: m_dataPoint(dataPoint)
|
||||
, m_segment(segment)
|
||||
{}
|
||||
|
||||
DataPoint const & GetDataPoint() const { return m_dataPoint; }
|
||||
routing::Segment const & GetSegment() const { return m_segment; }
|
||||
@@ -40,8 +40,7 @@ using MwmToMatchedTracks = std::unordered_map<routing::NumMwmId, UserToMatchedTr
|
||||
class TrackFilter final
|
||||
{
|
||||
public:
|
||||
TrackFilter(uint64_t minDuration, double minLength, double minSpeed, double maxSpeed,
|
||||
bool ignoreTraffic);
|
||||
TrackFilter(uint64_t minDuration, double minLength, double minSpeed, double maxSpeed, bool ignoreTraffic);
|
||||
|
||||
bool Passes(uint64_t duration, double length, double speed, bool hasTrafficPoints) const;
|
||||
|
||||
|
||||
@@ -26,11 +26,10 @@ namespace track_analyzing
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
void FillTable(basic_istream<char> & tableCsvStream, MwmToDataPoints & matchedDataPoints,
|
||||
vector<TableRow> & table)
|
||||
void FillTable(basic_istream<char> & tableCsvStream, MwmToDataPoints & matchedDataPoints, vector<TableRow> & table)
|
||||
{
|
||||
for (auto const & row : coding::CSVRunner(
|
||||
coding::CSVReader(tableCsvStream, true /* hasHeader */, ',' /* delimiter */)))
|
||||
for (auto const & row :
|
||||
coding::CSVRunner(coding::CSVReader(tableCsvStream, true /* hasHeader */, ',' /* delimiter */)))
|
||||
{
|
||||
CHECK_EQUAL(row.size(), kTableColumns, (row));
|
||||
auto const & mwmName = row[kMwmNameCsvColumn];
|
||||
@@ -39,13 +38,12 @@ void FillTable(basic_istream<char> & tableCsvStream, MwmToDataPoints & matchedDa
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveKeysSmallValue(MwmToDataPoints & checkedMap, MwmToDataPoints & additionalMap,
|
||||
uint64_t ignoreDataPointNumber)
|
||||
void RemoveKeysSmallValue(MwmToDataPoints & checkedMap, MwmToDataPoints & additionalMap, uint64_t ignoreDataPointNumber)
|
||||
{
|
||||
CHECK(AreKeysEqual(additionalMap, checkedMap),
|
||||
("Mwms in |checkedMap| and in |additionalMap| should have the same set of keys."));
|
||||
|
||||
for (auto it = checkedMap.begin() ; it != checkedMap.end();)
|
||||
for (auto it = checkedMap.begin(); it != checkedMap.end();)
|
||||
{
|
||||
auto const dataPointNumberAfterMatching = it->second;
|
||||
if (dataPointNumberAfterMatching > ignoreDataPointNumber)
|
||||
@@ -72,14 +70,13 @@ MwmToDataPointFraction GetMwmToDataPointFraction(MwmToDataPoints const & numberM
|
||||
return fractionMapping;
|
||||
}
|
||||
|
||||
MwmToDataPoints CalcsMatchedDataPointsToKeepDistribution(
|
||||
MwmToDataPoints const & matchedDataPoints, MwmToDataPointFraction const & distributionFractions)
|
||||
MwmToDataPoints CalcsMatchedDataPointsToKeepDistribution(MwmToDataPoints const & matchedDataPoints,
|
||||
MwmToDataPointFraction const & distributionFractions)
|
||||
{
|
||||
CHECK(!matchedDataPoints.empty(), ());
|
||||
CHECK(AreKeysEqual(matchedDataPoints, distributionFractions),
|
||||
("Mwms in |matchedDataPoints| and in |distributionFractions| should have the same set of keys."));
|
||||
CHECK(AlmostEqualAbs(ValueSum(distributionFractions), 1.0, kSumFractionEps),
|
||||
(ValueSum(distributionFractions)));
|
||||
CHECK(AlmostEqualAbs(ValueSum(distributionFractions), 1.0, kSumFractionEps), (ValueSum(distributionFractions)));
|
||||
|
||||
auto const matchedFractions = GetMwmToDataPointFraction(matchedDataPoints);
|
||||
|
||||
@@ -137,17 +134,14 @@ MwmToDataPoints CalcsMatchedDataPointsToKeepDistribution(
|
||||
|
||||
if (matchedDataPointsToKeepDistributionForMwm == 0)
|
||||
{
|
||||
LOG(LWARNING, ("Zero points should be put to", mwm,
|
||||
"to keep the distribution. Distribution fraction:", fraction,
|
||||
"totalMatchedPointNumberToKeepDistribution:",
|
||||
totalMatchedPointNumberToKeepDistribution));
|
||||
LOG(LWARNING, ("Zero points should be put to", mwm, "to keep the distribution. Distribution fraction:", fraction,
|
||||
"totalMatchedPointNumberToKeepDistribution:", totalMatchedPointNumberToKeepDistribution));
|
||||
}
|
||||
}
|
||||
return matchedDataPointsToKeepDistribution;
|
||||
}
|
||||
|
||||
MwmToDataPoints BalancedDataPointNumber(MwmToDataPoints && matchedDataPoints,
|
||||
MwmToDataPoints && distribution,
|
||||
MwmToDataPoints BalancedDataPointNumber(MwmToDataPoints && matchedDataPoints, MwmToDataPoints && distribution,
|
||||
uint64_t ignoreDataPointsNumber)
|
||||
{
|
||||
// Removing every mwm from |distribution| and |matchedDataPoints| if it has
|
||||
@@ -188,7 +182,7 @@ void FilterTable(MwmToDataPoints const & balancedDataPointNumbers, vector<TableR
|
||||
auto it = balancedDataPointNumbers.find(mwmName);
|
||||
if (it == balancedDataPointNumbers.end())
|
||||
{
|
||||
mwmRecordsIndices.resize(0); // No indices.
|
||||
mwmRecordsIndices.resize(0); // No indices.
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -201,16 +195,13 @@ void FilterTable(MwmToDataPoints const & balancedDataPointNumbers, vector<TableR
|
||||
// Refilling |table| with part of its items to corresponds |balancedDataPointNumbers| distribution.
|
||||
vector<TableRow> balancedTable;
|
||||
for (auto const & kv : tableIdx)
|
||||
{
|
||||
for (auto const idx : kv.second)
|
||||
balancedTable.emplace_back(std::move(table[idx]));
|
||||
}
|
||||
table = std::move(balancedTable);
|
||||
}
|
||||
|
||||
void BalanceDataPoints(basic_istream<char> & tableCsvStream,
|
||||
basic_istream<char> & distributionCsvStream, uint64_t ignoreDataPointsNumber,
|
||||
vector<TableRow> & balancedTable)
|
||||
void BalanceDataPoints(basic_istream<char> & tableCsvStream, basic_istream<char> & distributionCsvStream,
|
||||
uint64_t ignoreDataPointsNumber, vector<TableRow> & balancedTable)
|
||||
{
|
||||
LOG(LINFO, ("Balancing data points..."));
|
||||
// Filling a map mwm to DataPoints number according to distribution csv file.
|
||||
@@ -232,15 +223,14 @@ void BalanceDataPoints(basic_istream<char> & tableCsvStream,
|
||||
|
||||
// Removing every mwm from |distribution| if there is no such mwm in |matchedDataPoints|.
|
||||
for (auto it = distribution.begin(); it != distribution.end();)
|
||||
{
|
||||
if (matchedDataPoints.count(it->first) == 0)
|
||||
it = distribution.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
CHECK(AreKeysEqual(distribution, matchedDataPoints),
|
||||
("Mwms in |distribution| and in |matchedDataPoints| should have the same set of keys.", distribution, matchedDataPoints));
|
||||
("Mwms in |distribution| and in |matchedDataPoints| should have the same set of keys.", distribution,
|
||||
matchedDataPoints));
|
||||
|
||||
// Calculating how many points should have every mwm to keep the |distribution|.
|
||||
MwmToDataPoints const balancedDataPointNumber =
|
||||
@@ -252,18 +242,15 @@ void BalanceDataPoints(basic_istream<char> & tableCsvStream,
|
||||
// Removing some items form |tableCsvStream| (if it's necessary) to correspond to
|
||||
// the distribution.
|
||||
FilterTable(balancedDataPointNumber, balancedTable);
|
||||
LOG(LINFO, ("Data points have balanced. Total distribution data points number:",
|
||||
totalDistributionDataPointsNumber,
|
||||
LOG(LINFO, ("Data points have balanced. Total distribution data points number:", totalDistributionDataPointsNumber,
|
||||
"Total matched data points number:", totalMatchedDataPointsNumber,
|
||||
"Total balanced data points number:", totalBalancedDataPointsNumber));
|
||||
}
|
||||
|
||||
void CmdBalanceCsv(string const & csvPath, string const & distributionPath,
|
||||
uint64_t ignoreDataPointsNumber)
|
||||
void CmdBalanceCsv(string const & csvPath, string const & distributionPath, uint64_t ignoreDataPointsNumber)
|
||||
{
|
||||
LOG(LINFO, ("Balancing csv file", csvPath, "with distribution set in", distributionPath,
|
||||
". If an mwm has", ignoreDataPointsNumber,
|
||||
"data points or less it will not be considered."));
|
||||
LOG(LINFO, ("Balancing csv file", csvPath, "with distribution set in", distributionPath, ". If an mwm has",
|
||||
ignoreDataPointsNumber, "data points or less it will not be considered."));
|
||||
ifstream table(csvPath);
|
||||
CHECK(table.is_open(), ("Cannot open", csvPath));
|
||||
ifstream distribution(distributionPath);
|
||||
|
||||
@@ -32,17 +32,17 @@ typename MapCont::mapped_type ValueSum(MapCont const & mapCont)
|
||||
}
|
||||
|
||||
/// \returns true if |map1| and |map2| have the same key and false otherwise.
|
||||
template<typename Map1, typename Map2>
|
||||
template <typename Map1, typename Map2>
|
||||
bool AreKeysEqual(Map1 const & map1, Map2 const & map2)
|
||||
{
|
||||
if (map1.size() != map2.size())
|
||||
{
|
||||
LOG(LINFO,
|
||||
("AreKeysEqual() returns false. map1.size():", map1.size(), "map2.size()", map2.size()));
|
||||
LOG(LINFO, ("AreKeysEqual() returns false. map1.size():", map1.size(), "map2.size()", map2.size()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::equal(map1.begin(), map1.end(), map2.begin(), [](auto const & kv1, auto const & kv2) {
|
||||
return std::equal(map1.begin(), map1.end(), map2.begin(), [](auto const & kv1, auto const & kv2)
|
||||
{
|
||||
if (kv1.first == kv2.first)
|
||||
return true;
|
||||
|
||||
@@ -68,13 +68,11 @@ MwmToDataPointFraction GetMwmToDataPointFraction(MwmToDataPoints const & numberM
|
||||
/// * number of data points in the returned mapping is less than or equal to
|
||||
/// number of data points in |matchedDataPoints| for every mwm
|
||||
/// * distribution defined by |distributionFraction| is kept
|
||||
MwmToDataPoints CalcsMatchedDataPointsToKeepDistribution(
|
||||
MwmToDataPoints const & matchedDataPoints,
|
||||
MwmToDataPointFraction const & distributionFractions);
|
||||
MwmToDataPoints CalcsMatchedDataPointsToKeepDistribution(MwmToDataPoints const & matchedDataPoints,
|
||||
MwmToDataPointFraction const & distributionFractions);
|
||||
|
||||
/// \returns mapping with number of matched data points for every mwm to correspond to |distribution|.
|
||||
MwmToDataPoints BalancedDataPointNumber(MwmToDataPoints && matchedDataPoints,
|
||||
MwmToDataPoints && distribution,
|
||||
MwmToDataPoints BalancedDataPointNumber(MwmToDataPoints && matchedDataPoints, MwmToDataPoints && distribution,
|
||||
uint64_t ignoreDataPointsNumber);
|
||||
|
||||
/// \breif Leaves in |table| only number of items according to |balancedDataPointNumbers|.
|
||||
@@ -83,13 +81,11 @@ void FilterTable(MwmToDataPoints const & balancedDataPointNumbers, std::vector<T
|
||||
|
||||
/// \brief Fills |balancedTable| with TableRow(s) according to the distribution set in
|
||||
/// |distributionCsvStream|.
|
||||
void BalanceDataPoints(std::basic_istream<char> & tableCsvStream,
|
||||
std::basic_istream<char> & distributionCsvStream,
|
||||
void BalanceDataPoints(std::basic_istream<char> & tableCsvStream, std::basic_istream<char> & distributionCsvStream,
|
||||
uint64_t ignoreDataPointsNumber, std::vector<TableRow> & balancedTable);
|
||||
|
||||
/// \brief Removes some data point for every mwm from |csvPath| to correspond distribution
|
||||
/// set in |distributionPath|. If an mwm in |csvPath| contains data points less of equal to
|
||||
/// |ignoreDataPointsNumber| than the mwm will not be taken into acount while balancing.
|
||||
void CmdBalanceCsv(std::string const & csvPath, std::string const & distributionPath,
|
||||
uint64_t ignoreDataPointsNumber);
|
||||
void CmdBalanceCsv(std::string const & csvPath, std::string const & distributionPath, uint64_t ignoreDataPointsNumber);
|
||||
} // namespace track_analyzing
|
||||
|
||||
@@ -9,24 +9,19 @@ using namespace std;
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
void CmdCppTrack(string const & trackFile, string const & mwmName, string const & user,
|
||||
size_t trackIdx)
|
||||
void CmdCppTrack(string const & trackFile, string const & mwmName, string const & user, size_t trackIdx)
|
||||
{
|
||||
storage::Storage storage;
|
||||
auto const numMwmIds = CreateNumMwmIds(storage);
|
||||
MwmToMatchedTracks mwmToMatchedTracks;
|
||||
ReadTracks(numMwmIds, trackFile, mwmToMatchedTracks);
|
||||
|
||||
MatchedTrack const & track =
|
||||
GetMatchedTrack(mwmToMatchedTracks, *numMwmIds, mwmName, user, trackIdx);
|
||||
MatchedTrack const & track = GetMatchedTrack(mwmToMatchedTracks, *numMwmIds, mwmName, user, trackIdx);
|
||||
|
||||
auto const backupPrecision = cout.precision();
|
||||
cout.precision(8);
|
||||
for (MatchedTrackPoint const & point : track)
|
||||
{
|
||||
cout << " {" << point.GetDataPoint().m_latLon.m_lat << ", " << point.GetDataPoint().m_latLon.m_lon
|
||||
<< "}," << endl;
|
||||
}
|
||||
cout << " {" << point.GetDataPoint().m_latLon.m_lat << ", " << point.GetDataPoint().m_latLon.m_lon << "}," << endl;
|
||||
cout.precision(backupPrecision);
|
||||
}
|
||||
} // namespace track_analyzing
|
||||
|
||||
@@ -48,10 +48,7 @@ void CmdGPX(string const & logFile, string const & outputDirName, string const &
|
||||
ofs << "</metadata>\n";
|
||||
for (auto const & point : track.second)
|
||||
{
|
||||
ofs << "<wpt lat=\""
|
||||
<< point.m_latLon.m_lat
|
||||
<< "\" lon=\""
|
||||
<< point.m_latLon.m_lon << "\">"
|
||||
ofs << "<wpt lat=\"" << point.m_latLon.m_lat << "\" lon=\"" << point.m_latLon.m_lon << "\">"
|
||||
<< "</wpt>\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace
|
||||
{
|
||||
using Iter = typename vector<string>::iterator;
|
||||
|
||||
void MatchTracks(MwmToTracks const & mwmToTracks, storage::Storage const & storage,
|
||||
NumMwmIds const & numMwmIds, MwmToMatchedTracks & mwmToMatchedTracks)
|
||||
void MatchTracks(MwmToTracks const & mwmToTracks, storage::Storage const & storage, NumMwmIds const & numMwmIds,
|
||||
MwmToMatchedTracks & mwmToMatchedTracks)
|
||||
{
|
||||
base::Timer timer;
|
||||
|
||||
@@ -46,7 +46,8 @@ void MatchTracks(MwmToTracks const & mwmToTracks, storage::Storage const & stora
|
||||
uint64_t pointsCount = 0;
|
||||
uint64_t nonMatchedPointsCount = 0;
|
||||
|
||||
auto processMwm = [&](string const & mwmName, UserToTrack const & userToTrack) {
|
||||
auto processMwm = [&](string const & mwmName, UserToTrack const & userToTrack)
|
||||
{
|
||||
auto const countryFile = platform::CountryFile(mwmName);
|
||||
auto const mwmId = numMwmIds.GetId(countryFile);
|
||||
TrackMatcher matcher(storage, mwmId, countryFile);
|
||||
@@ -78,23 +79,22 @@ void MatchTracks(MwmToTracks const & mwmToTracks, storage::Storage const & stora
|
||||
pointsCount += matcher.GetPointsCount();
|
||||
nonMatchedPointsCount += matcher.GetNonMatchedPointsCount();
|
||||
|
||||
LOG(LINFO, (numMwmIds.GetFile(mwmId).GetName(), ", users:", userToTrack.size(), ", tracks:",
|
||||
matcher.GetTracksCount(), ", points:", matcher.GetPointsCount(),
|
||||
", non matched points:", matcher.GetNonMatchedPointsCount()));
|
||||
LOG(LINFO,
|
||||
(numMwmIds.GetFile(mwmId).GetName(), ", users:", userToTrack.size(), ", tracks:", matcher.GetTracksCount(),
|
||||
", points:", matcher.GetPointsCount(), ", non matched points:", matcher.GetNonMatchedPointsCount()));
|
||||
};
|
||||
|
||||
ForTracksSortedByMwmName(mwmToTracks, numMwmIds, processMwm);
|
||||
|
||||
LOG(LINFO,
|
||||
("Matching finished, elapsed:", timer.ElapsedSeconds(), "seconds, tracks:", tracksCount,
|
||||
", points:", pointsCount, ", non matched points:", nonMatchedPointsCount));
|
||||
LOG(LINFO, ("Matching finished, elapsed:", timer.ElapsedSeconds(), "seconds, tracks:", tracksCount,
|
||||
", points:", pointsCount, ", non matched points:", nonMatchedPointsCount));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
void CmdMatch(string const & logFile, string const & trackFile,
|
||||
shared_ptr<NumMwmIds> const & numMwmIds, Storage const & storage, Stats & stats)
|
||||
void CmdMatch(string const & logFile, string const & trackFile, shared_ptr<NumMwmIds> const & numMwmIds,
|
||||
Storage const & storage, Stats & stats)
|
||||
{
|
||||
MwmToTracks mwmToTracks;
|
||||
ParseTracks(logFile, numMwmIds, mwmToTracks);
|
||||
@@ -165,8 +165,7 @@ void UnzipAndMatch(Iter begin, Iter end, string const & trackExt, Stats & stats)
|
||||
|
||||
void CmdMatchDir(string const & logDir, string const & trackExt, string const & inputDistribution)
|
||||
{
|
||||
LOG(LINFO,
|
||||
("Matching dir:", logDir, ". Input distribution will be saved to:", inputDistribution));
|
||||
LOG(LINFO, ("Matching dir:", logDir, ". Input distribution will be saved to:", inputDistribution));
|
||||
Platform::EFileType fileType = Platform::EFileType::Unknown;
|
||||
Platform::EError const result = Platform::GetFileType(logDir, fileType);
|
||||
|
||||
|
||||
@@ -69,11 +69,9 @@ bool DayTimeToBool(DayTimeType type)
|
||||
switch (type)
|
||||
{
|
||||
case DayTimeType::Day:
|
||||
case DayTimeType::PolarDay:
|
||||
return true;
|
||||
case DayTimeType::PolarDay: return true;
|
||||
case DayTimeType::Night:
|
||||
case DayTimeType::PolarNight:
|
||||
return false;
|
||||
case DayTimeType::PolarNight: return false;
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
@@ -100,15 +98,9 @@ public:
|
||||
return tie(m_hwType, m_surfaceType) < tie(rhs.m_hwType, rhs.m_surfaceType);
|
||||
}
|
||||
|
||||
bool operator==(Type const & rhs) const
|
||||
{
|
||||
return tie(m_hwType, m_surfaceType) == tie(rhs.m_hwType, m_surfaceType);
|
||||
}
|
||||
bool operator==(Type const & rhs) const { return tie(m_hwType, m_surfaceType) == tie(rhs.m_hwType, m_surfaceType); }
|
||||
|
||||
bool operator!=(Type const & rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
bool operator!=(Type const & rhs) const { return !(*this == rhs); }
|
||||
|
||||
string GetSummary() const
|
||||
{
|
||||
@@ -158,10 +150,7 @@ struct RoadInfo
|
||||
tie(rhs.m_type, rhs.m_maxspeedKMpH, rhs.m_isCityRoad, rhs.m_isOneWay);
|
||||
}
|
||||
|
||||
bool operator!=(RoadInfo const & rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
bool operator!=(RoadInfo const & rhs) const { return !(*this == rhs); }
|
||||
|
||||
bool operator<(RoadInfo const & rhs) const
|
||||
{
|
||||
@@ -172,11 +161,8 @@ struct RoadInfo
|
||||
string GetSummary() const
|
||||
{
|
||||
ostringstream out;
|
||||
out << TypeToString(m_type.m_hwType) << ","
|
||||
<< TypeToString(m_type.m_surfaceType) << ","
|
||||
<< m_maxspeedKMpH << ","
|
||||
<< m_isCityRoad << ","
|
||||
<< m_isOneWay;
|
||||
out << TypeToString(m_type.m_hwType) << "," << TypeToString(m_type.m_surfaceType) << "," << m_maxspeedKMpH << ","
|
||||
<< m_isCityRoad << "," << m_isOneWay;
|
||||
|
||||
return out.str();
|
||||
}
|
||||
@@ -193,7 +179,9 @@ public:
|
||||
MoveType() = default;
|
||||
|
||||
MoveType(RoadInfo const & roadType, traffic::SpeedGroup speedGroup, DataPoint const & dataPoint)
|
||||
: m_roadInfo(roadType), m_speedGroup(speedGroup), m_latLon(dataPoint.m_latLon)
|
||||
: m_roadInfo(roadType)
|
||||
, m_speedGroup(speedGroup)
|
||||
, m_latLon(dataPoint.m_latLon)
|
||||
{
|
||||
m_isDayTime = DayTimeToBool(GetDayTime(dataPoint.m_timestamp, m_latLon.m_lat, m_latLon.m_lon));
|
||||
}
|
||||
@@ -213,17 +201,14 @@ public:
|
||||
bool IsValid() const
|
||||
{
|
||||
// In order to collect cleaner data we don't use speed group lower than G5.
|
||||
return m_roadInfo.m_type.m_hwType != 0 &&
|
||||
m_roadInfo.m_type.m_surfaceType != 0 &&
|
||||
return m_roadInfo.m_type.m_hwType != 0 && m_roadInfo.m_type.m_surfaceType != 0 &&
|
||||
m_speedGroup == kValidTrafficValue;
|
||||
}
|
||||
|
||||
string GetSummary() const
|
||||
{
|
||||
ostringstream out;
|
||||
out << m_roadInfo.GetSummary() << ","
|
||||
<< m_isDayTime << ","
|
||||
<< m_latLon.m_lat << " " << m_latLon.m_lon;
|
||||
out << m_roadInfo.GetSummary() << "," << m_isDayTime << "," << m_latLon.m_lat << " " << m_latLon.m_lon;
|
||||
|
||||
return out.str();
|
||||
}
|
||||
@@ -250,9 +235,7 @@ public:
|
||||
string GetSummary() const
|
||||
{
|
||||
ostringstream out;
|
||||
out << m_totalDistance << ","
|
||||
<< m_totalTime << ","
|
||||
<< CalcSpeedKMpH(m_totalDistance, m_totalTime) << ",";
|
||||
out << m_totalDistance << "," << m_totalTime << "," << CalcSpeedKMpH(m_totalDistance, m_totalTime) << ",";
|
||||
|
||||
for (size_t i = 0; i < m_crossroads.size(); ++i)
|
||||
{
|
||||
@@ -276,8 +259,8 @@ private:
|
||||
class MoveTypeAggregator final
|
||||
{
|
||||
public:
|
||||
void Add(MoveType && moveType, IsCrossroadChecker::CrossroadInfo const & crossroads, MatchedTrack::const_iterator begin,
|
||||
MatchedTrack::const_iterator end, Geometry & geometry)
|
||||
void Add(MoveType && moveType, IsCrossroadChecker::CrossroadInfo const & crossroads,
|
||||
MatchedTrack::const_iterator begin, MatchedTrack::const_iterator end, Geometry & geometry)
|
||||
{
|
||||
if (begin + 1 >= end)
|
||||
return;
|
||||
@@ -288,9 +271,9 @@ public:
|
||||
|
||||
if (time == 0)
|
||||
{
|
||||
LOG(LWARNING, ("Track with the same time at the beginning and at the end. Beginning:",
|
||||
beginDataPoint.m_latLon, " End:", endDataPoint.m_latLon,
|
||||
" Timestamp:", beginDataPoint.m_timestamp, " Segment:", begin->GetSegment()));
|
||||
LOG(LWARNING, ("Track with the same time at the beginning and at the end. Beginning:", beginDataPoint.m_latLon,
|
||||
" End:", endDataPoint.m_latLon, " Timestamp:", beginDataPoint.m_timestamp,
|
||||
" Segment:", begin->GetSegment()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -298,8 +281,7 @@ public:
|
||||
m_moveInfos[moveType].Add(length, time, crossroads, static_cast<uint32_t>(distance(begin, end)));
|
||||
}
|
||||
|
||||
string GetSummary(string const & user, string const & mwmName, string const & countryName,
|
||||
Stats & stats) const
|
||||
string GetSummary(string const & user, string const & mwmName, string const & countryName, Stats & stats) const
|
||||
{
|
||||
ostringstream out;
|
||||
for (auto const & it : m_moveInfos)
|
||||
@@ -307,8 +289,7 @@ public:
|
||||
if (!it.first.IsValid())
|
||||
continue;
|
||||
|
||||
out << user << "," << mwmName << "," << it.first.GetSummary() << ","
|
||||
<< it.second.GetSummary() << '\n';
|
||||
out << user << "," << mwmName << "," << it.first.GetSummary() << "," << it.second.GetSummary() << '\n';
|
||||
|
||||
stats.AddDataPoints(mwmName, countryName, it.second.GetDataPointsNumber());
|
||||
}
|
||||
@@ -324,7 +305,8 @@ class MatchedTrackPointToMoveType final
|
||||
{
|
||||
public:
|
||||
MatchedTrackPointToMoveType(FilesContainerR const & container, VehicleModelInterface & vehicleModel)
|
||||
: m_featuresVector(container), m_vehicleModel(vehicleModel)
|
||||
: m_featuresVector(container)
|
||||
, m_vehicleModel(vehicleModel)
|
||||
{
|
||||
if (container.IsExist(CITY_ROADS_FILE_TAG))
|
||||
m_cityRoads.Load(container.GetReader(CITY_ROADS_FILE_TAG));
|
||||
@@ -336,9 +318,7 @@ public:
|
||||
MoveType GetMoveType(MatchedTrackPoint const & point)
|
||||
{
|
||||
auto const & dataPoint = point.GetDataPoint();
|
||||
return MoveType(GetRoadInfo(point.GetSegment()),
|
||||
static_cast<traffic::SpeedGroup>(dataPoint.m_traffic),
|
||||
dataPoint);
|
||||
return MoveType(GetRoadInfo(point.GetSegment()), static_cast<traffic::SpeedGroup>(dataPoint.m_traffic), dataPoint);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -352,15 +332,14 @@ private:
|
||||
CHECK(feature, ());
|
||||
|
||||
auto const maxspeed = m_maxspeeds.GetMaxspeed(featureId);
|
||||
auto const maxspeedValueKMpH = maxspeed.IsValid() ?
|
||||
min(maxspeed.GetSpeedKmPH(segment.IsForward()), kMaxspeedTopBound) :
|
||||
kInvalidSpeed;
|
||||
auto const maxspeedValueKMpH =
|
||||
maxspeed.IsValid() ? min(maxspeed.GetSpeedKmPH(segment.IsForward()), kMaxspeedTopBound) : kInvalidSpeed;
|
||||
|
||||
m_prevFeatureId = featureId;
|
||||
|
||||
feature::TypesHolder const types(*feature);
|
||||
m_prevRoadInfo = {m_carModelTypes.GetType(types), maxspeedValueKMpH,
|
||||
m_cityRoads.IsCityRoad(featureId), m_vehicleModel.IsOneWay(types)};
|
||||
m_prevRoadInfo = {m_carModelTypes.GetType(types), maxspeedValueKMpH, m_cityRoads.IsCityRoad(featureId),
|
||||
m_vehicleModel.IsOneWay(types)};
|
||||
return m_prevRoadInfo;
|
||||
}
|
||||
|
||||
@@ -374,7 +353,6 @@ private:
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
void CmdTagsTable(string const & filepath, string const & trackExtension, StringFilter mwmFilter,
|
||||
StringFilter userFilter)
|
||||
{
|
||||
@@ -393,18 +371,17 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String
|
||||
|
||||
auto const countryName = storage.GetTopmostParentFor(mwmName);
|
||||
auto const carModelFactory = make_shared<CarModelFactory>(VehicleModelFactory::CountryParentNameGetterFn{});
|
||||
shared_ptr<VehicleModelInterface> vehicleModel =
|
||||
carModelFactory->GetVehicleModelForCountry(mwmName);
|
||||
shared_ptr<VehicleModelInterface> vehicleModel = carModelFactory->GetVehicleModelForCountry(mwmName);
|
||||
string const mwmFile = GetCurrentVersionMwmFile(storage, mwmName);
|
||||
MatchedTrackPointToMoveType pointToMoveType(FilesContainerR(make_unique<FileReader>(mwmFile)), *vehicleModel);
|
||||
Geometry geometry(GeometryLoader::CreateFromFile(mwmFile, vehicleModel));
|
||||
auto const vehicleType = VehicleType::Car;
|
||||
auto const edgeEstimator = EdgeEstimator::Create(vehicleType, *vehicleModel,
|
||||
nullptr /* trafficStash */, &dataSource, numMwmIds);
|
||||
auto const edgeEstimator =
|
||||
EdgeEstimator::Create(vehicleType, *vehicleModel, nullptr /* trafficStash */, &dataSource, numMwmIds);
|
||||
|
||||
MwmDataSource routingSource(dataSource, numMwmIds);
|
||||
auto indexGraphLoader = IndexGraphLoader::Create(vehicleType, false /* loadAltitudes */,
|
||||
carModelFactory, edgeEstimator, routingSource);
|
||||
auto indexGraphLoader =
|
||||
IndexGraphLoader::Create(vehicleType, false /* loadAltitudes */, carModelFactory, edgeEstimator, routingSource);
|
||||
|
||||
platform::CountryFile const countryFile(mwmName);
|
||||
auto localCountryFile = storage.GetLatestLocalFile(countryFile);
|
||||
@@ -412,8 +389,7 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String
|
||||
if (!dataSource.IsLoaded(countryFile))
|
||||
{
|
||||
auto registerResult = dataSource.Register(*localCountryFile);
|
||||
CHECK_EQUAL(registerResult.second, MwmSet::RegResult::Success,
|
||||
("Can't register mwm", countryFile.GetName()));
|
||||
CHECK_EQUAL(registerResult.second, MwmSet::RegResult::Success, ("Can't register mwm", countryFile.GetName()));
|
||||
}
|
||||
|
||||
auto const mwmId = numMwmIds->GetId(countryFile);
|
||||
@@ -440,18 +416,14 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String
|
||||
// Splitting track with points where MoveType is changed.
|
||||
while (end != track.end() && pointToMoveType.GetMoveType(*end) == moveType)
|
||||
{
|
||||
IsCrossroadChecker::MergeCrossroads(checker(prev->GetSegment(), end->GetSegment()),
|
||||
info);
|
||||
IsCrossroadChecker::MergeCrossroads(checker(prev->GetSegment(), end->GetSegment()), info);
|
||||
prev = end;
|
||||
++end;
|
||||
}
|
||||
|
||||
// If it's not the end of the track than it could be a crossroad.
|
||||
if (end != track.end())
|
||||
{
|
||||
IsCrossroadChecker::MergeCrossroads(checker(prev->GetSegment(), end->GetSegment()),
|
||||
info);
|
||||
}
|
||||
IsCrossroadChecker::MergeCrossroads(checker(prev->GetSegment(), end->GetSegment()), info);
|
||||
|
||||
aggregator.Add(std::move(moveType), info, subtrackBegin, end, geometry);
|
||||
subtrackBegin = end;
|
||||
|
||||
@@ -23,28 +23,24 @@ using namespace std;
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
void CmdTrack(string const & trackFile, string const & mwmName, string const & user,
|
||||
size_t trackIdx)
|
||||
void CmdTrack(string const & trackFile, string const & mwmName, string const & user, size_t trackIdx)
|
||||
{
|
||||
storage::Storage storage;
|
||||
auto const numMwmIds = CreateNumMwmIds(storage);
|
||||
MwmToMatchedTracks mwmToMatchedTracks;
|
||||
ReadTracks(numMwmIds, trackFile, mwmToMatchedTracks);
|
||||
|
||||
MatchedTrack const & track =
|
||||
GetMatchedTrack(mwmToMatchedTracks, *numMwmIds, mwmName, user, trackIdx);
|
||||
MatchedTrack const & track = GetMatchedTrack(mwmToMatchedTracks, *numMwmIds, mwmName, user, trackIdx);
|
||||
|
||||
string const mwmFile = GetCurrentVersionMwmFile(storage, mwmName);
|
||||
shared_ptr<VehicleModelInterface> vehicleModel =
|
||||
CarModelFactory({}).GetVehicleModelForCountry(mwmName);
|
||||
shared_ptr<VehicleModelInterface> vehicleModel = CarModelFactory({}).GetVehicleModelForCountry(mwmName);
|
||||
Geometry geometry(GeometryLoader::CreateFromFile(mwmFile, vehicleModel));
|
||||
|
||||
uint64_t const duration =
|
||||
track.back().GetDataPoint().m_timestamp - track.front().GetDataPoint().m_timestamp;
|
||||
uint64_t const duration = track.back().GetDataPoint().m_timestamp - track.front().GetDataPoint().m_timestamp;
|
||||
double const length = CalcTrackLength(track, geometry);
|
||||
double const averageSpeed = CalcSpeedKMpH(length, duration);
|
||||
LOG(LINFO, ("Mwm:", mwmName, ", user:", user, ", points:", track.size(), "duration:", duration,
|
||||
"length:", length, ", speed:", averageSpeed, "km/h"));
|
||||
LOG(LINFO, ("Mwm:", mwmName, ", user:", user, ", points:", track.size(), "duration:", duration, "length:", length,
|
||||
", speed:", averageSpeed, "km/h"));
|
||||
|
||||
for (size_t i = 0; i < track.size(); ++i)
|
||||
{
|
||||
@@ -64,10 +60,9 @@ void CmdTrack(string const & trackFile, string const & mwmName, string const & u
|
||||
if (elapsed != 0)
|
||||
speed = CalcSpeedKMpH(distance, elapsed);
|
||||
|
||||
LOG(LINFO, (base::SecondsSinceEpochToString(point.GetDataPoint().m_timestamp),
|
||||
point.GetDataPoint().m_latLon, point.GetSegment(), ", traffic:",
|
||||
point.GetDataPoint().m_traffic, ", distance:", distance, ", elapsed:", elapsed,
|
||||
", speed:", speed));
|
||||
LOG(LINFO, (base::SecondsSinceEpochToString(point.GetDataPoint().m_timestamp), point.GetDataPoint().m_latLon,
|
||||
point.GetSegment(), ", traffic:", point.GetDataPoint().m_traffic, ", distance:", distance,
|
||||
", elapsed:", elapsed, ", speed:", speed));
|
||||
}
|
||||
}
|
||||
} // namespace track_analyzing
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
using namespace routing;
|
||||
@@ -105,8 +104,7 @@ bool TrackHasTrafficPoints(MatchedTrack const & track)
|
||||
return false;
|
||||
}
|
||||
|
||||
double EstimateDuration(MatchedTrack const & track, shared_ptr<EdgeEstimator> estimator,
|
||||
Geometry & geometry)
|
||||
double EstimateDuration(MatchedTrack const & track, shared_ptr<EdgeEstimator> estimator, Geometry & geometry)
|
||||
{
|
||||
double result = 0.0;
|
||||
Segment segment;
|
||||
@@ -117,16 +115,15 @@ double EstimateDuration(MatchedTrack const & track, shared_ptr<EdgeEstimator> es
|
||||
continue;
|
||||
|
||||
segment = point.GetSegment();
|
||||
result += estimator->CalcSegmentWeight(segment, geometry.GetRoad(segment.GetFeatureId()),
|
||||
EdgeEstimator::Purpose::ETA);
|
||||
result +=
|
||||
estimator->CalcSegmentWeight(segment, geometry.GetRoad(segment.GetFeatureId()), EdgeEstimator::Purpose::ETA);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CmdTracks(string const & filepath, string const & trackExtension, StringFilter mwmFilter,
|
||||
StringFilter userFilter, TrackFilter const & filter, bool noTrackLogs,
|
||||
bool noMwmLogs, bool noWorldLogs)
|
||||
void CmdTracks(string const & filepath, string const & trackExtension, StringFilter mwmFilter, StringFilter userFilter,
|
||||
TrackFilter const & filter, bool noTrackLogs, bool noMwmLogs, bool noWorldLogs)
|
||||
{
|
||||
storage::Storage storage;
|
||||
auto numMwmIds = CreateNumMwmIds(storage);
|
||||
@@ -135,21 +132,19 @@ void CmdTracks(string const & filepath, string const & trackExtension, StringFil
|
||||
ErrorStat absoluteError;
|
||||
ErrorStat relativeError;
|
||||
|
||||
auto processMwm = [&](string const & mwmName, UserToMatchedTracks const & userToMatchedTracks) {
|
||||
auto processMwm = [&](string const & mwmName, UserToMatchedTracks const & userToMatchedTracks)
|
||||
{
|
||||
if (mwmFilter(mwmName))
|
||||
return;
|
||||
|
||||
TrackStats & mwmStats = mwmToStats[mwmName];
|
||||
|
||||
shared_ptr<VehicleModelInterface> vehicleModel =
|
||||
CarModelFactory({}).GetVehicleModelForCountry(mwmName);
|
||||
shared_ptr<VehicleModelInterface> vehicleModel = CarModelFactory({}).GetVehicleModelForCountry(mwmName);
|
||||
|
||||
Geometry geometry(
|
||||
GeometryLoader::CreateFromFile(GetCurrentVersionMwmFile(storage, mwmName), vehicleModel));
|
||||
Geometry geometry(GeometryLoader::CreateFromFile(GetCurrentVersionMwmFile(storage, mwmName), vehicleModel));
|
||||
|
||||
shared_ptr<EdgeEstimator> estimator =
|
||||
EdgeEstimator::Create(VehicleType::Car, *vehicleModel,
|
||||
nullptr /* trafficStash */, nullptr /* dataSource */, nullptr /* numMwmIds */);
|
||||
shared_ptr<EdgeEstimator> estimator = EdgeEstimator::Create(
|
||||
VehicleType::Car, *vehicleModel, nullptr /* trafficStash */, nullptr /* dataSource */, nullptr /* numMwmIds */);
|
||||
|
||||
for (auto const & it : userToMatchedTracks)
|
||||
{
|
||||
@@ -181,13 +176,13 @@ void CmdTracks(string const & filepath, string const & trackExtension, StringFil
|
||||
if (!noTrackLogs)
|
||||
{
|
||||
cout << fixed << setprecision(1) << " points: " << track.size() << ", length: " << length
|
||||
<< ", duration: " << duration << ", estimated duration: " << estimatedDuration
|
||||
<< ", speed: " << speed << ", traffic: " << hasTrafficPoints
|
||||
<< ", duration: " << duration << ", estimated duration: " << estimatedDuration << ", speed: " << speed
|
||||
<< ", traffic: " << hasTrafficPoints
|
||||
<< ", departure: " << base::SecondsSinceEpochToString(start.m_timestamp)
|
||||
<< ", arrival: " << base::SecondsSinceEpochToString(finish.m_timestamp)
|
||||
<< setprecision(numeric_limits<double>::max_digits10)
|
||||
<< ", start: " << start.m_latLon.m_lat << ", " << start.m_latLon.m_lon
|
||||
<< ", finish: " << finish.m_latLon.m_lat << ", " << finish.m_latLon.m_lon << endl;
|
||||
<< setprecision(numeric_limits<double>::max_digits10) << ", start: " << start.m_latLon.m_lat << ", "
|
||||
<< start.m_latLon.m_lon << ", finish: " << finish.m_latLon.m_lat << ", " << finish.m_latLon.m_lon
|
||||
<< endl;
|
||||
}
|
||||
|
||||
mwmStats.AddTracks(1);
|
||||
@@ -202,7 +197,8 @@ void CmdTracks(string const & filepath, string const & trackExtension, StringFil
|
||||
}
|
||||
};
|
||||
|
||||
auto processFile = [&](string const & filename, MwmToMatchedTracks const & mwmToMatchedTracks) {
|
||||
auto processFile = [&](string const & filename, MwmToMatchedTracks const & mwmToMatchedTracks)
|
||||
{
|
||||
LOG(LINFO, ("Processing", filename));
|
||||
ForTracksSortedByMwmName(mwmToMatchedTracks, *numMwmIds, processMwm);
|
||||
};
|
||||
@@ -213,10 +209,8 @@ void CmdTracks(string const & filepath, string const & trackExtension, StringFil
|
||||
{
|
||||
cout << endl;
|
||||
for (auto const & it : mwmToStats)
|
||||
{
|
||||
if (!it.second.IsEmpty())
|
||||
cout << it.first << ": " << it.second.GetSummary() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!noWorldLogs)
|
||||
@@ -226,11 +220,9 @@ void CmdTracks(string const & filepath, string const & trackExtension, StringFil
|
||||
worldStats.Add(it.second);
|
||||
|
||||
cout << endl << "World: " << worldStats.GetSummary() << endl;
|
||||
cout << fixed << setprecision(1)
|
||||
<< "Absolute error: deviation: " << absoluteError.GetStdDevString()
|
||||
cout << fixed << setprecision(1) << "Absolute error: deviation: " << absoluteError.GetStdDevString()
|
||||
<< ", min: " << absoluteError.GetMin() << ", max: " << absoluteError.GetMax() << endl;
|
||||
cout << fixed << setprecision(3)
|
||||
<< "Relative error: deviation: " << relativeError.GetStdDevString()
|
||||
cout << fixed << setprecision(3) << "Relative error: deviation: " << relativeError.GetStdDevString()
|
||||
<< ", min: " << relativeError.GetMin() << ", max: " << relativeError.GetMax() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,8 @@ bool IsHighwayLink(HighwayType type)
|
||||
case HighwayType::HighwayTrunkLink:
|
||||
case HighwayType::HighwayPrimaryLink:
|
||||
case HighwayType::HighwaySecondaryLink:
|
||||
case HighwayType::HighwayTertiaryLink:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
case HighwayType::HighwayTertiaryLink: return true;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
@@ -40,10 +38,8 @@ bool IsBigHighway(HighwayType type)
|
||||
case HighwayType::HighwayTrunk:
|
||||
case HighwayType::HighwayPrimary:
|
||||
case HighwayType::HighwaySecondary:
|
||||
case HighwayType::HighwayTertiary:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
case HighwayType::HighwayTertiary: return true;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
@@ -54,12 +50,8 @@ bool FromSmallerToBigger(HighwayType lhs, HighwayType rhs)
|
||||
CHECK_NOT_EQUAL(lhs, rhs, ());
|
||||
|
||||
static std::array<HighwayType, 5> constexpr kHighwayTypes = {
|
||||
HighwayType::HighwayTertiary,
|
||||
HighwayType::HighwaySecondary,
|
||||
HighwayType::HighwayPrimary,
|
||||
HighwayType::HighwayTrunk,
|
||||
HighwayType::HighwayMotorway
|
||||
};
|
||||
HighwayType::HighwayTertiary, HighwayType::HighwaySecondary, HighwayType::HighwayPrimary,
|
||||
HighwayType::HighwayTrunk, HighwayType::HighwayMotorway};
|
||||
|
||||
auto const lhsIt = find(kHighwayTypes.begin(), kHighwayTypes.end(), lhs);
|
||||
auto const rhsIt = find(kHighwayTypes.begin(), kHighwayTypes.end(), rhs);
|
||||
@@ -112,7 +104,8 @@ IsCrossroadChecker::Type IsCrossroadChecker::operator()(Segment const & current,
|
||||
|
||||
Type retType = Type::Count;
|
||||
auto const nextRoadPoint = next.GetRoadPoint(false /* isFront */);
|
||||
m_indexGraph.ForEachPoint(jointId, [&](RoadPoint const & point) {
|
||||
m_indexGraph.ForEachPoint(jointId, [&](RoadPoint const & point)
|
||||
{
|
||||
if (retType != IsCrossroadChecker::Type::Count)
|
||||
return;
|
||||
|
||||
@@ -129,11 +122,8 @@ IsCrossroadChecker::Type IsCrossroadChecker::operator()(Segment const & current,
|
||||
if (pointHwType == nextSegmentHwType)
|
||||
{
|
||||
// Is the same road but parted on different features.
|
||||
if (roadGeometry.IsEndPointId(point.GetPointId()) &&
|
||||
roadGeometry.IsEndPointId(nextRoadPoint.GetPointId()))
|
||||
{
|
||||
if (roadGeometry.IsEndPointId(point.GetPointId()) && roadGeometry.IsEndPointId(nextRoadPoint.GetPointId()))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurrentLink && IsBigHighway(*pointHwType))
|
||||
|
||||
@@ -30,8 +30,7 @@ public:
|
||||
Type operator()(Segment const & current, Segment const & next) const;
|
||||
|
||||
static void MergeCrossroads(Type from, CrossroadInfo & to);
|
||||
static void MergeCrossroads(IsCrossroadChecker::CrossroadInfo const & from,
|
||||
IsCrossroadChecker::CrossroadInfo & to);
|
||||
static void MergeCrossroads(IsCrossroadChecker::CrossroadInfo const & from, IsCrossroadChecker::CrossroadInfo & to);
|
||||
|
||||
private:
|
||||
IndexGraph & m_indexGraph;
|
||||
|
||||
@@ -51,19 +51,17 @@ DEFINE_string_ext(output_dir, "", "output dir for gpx files");
|
||||
DEFINE_string_ext(mwm, "", "short mwm name");
|
||||
DEFINE_string_ext(user, "", "user id");
|
||||
DEFINE_int32(track, -1, "track index");
|
||||
DEFINE_string(
|
||||
input_distribution, "",
|
||||
"path to input data point distribution file. It's a csv file with data point count for "
|
||||
"some mwms. Usage:\n"
|
||||
"- It may be used with match and match_dir command. If so it's a path to save file with "
|
||||
"data point distribution by mwm. If it's empty no file is saved.\n"
|
||||
"- It may be used with balance_csv command. If so it's a path of a file with distribution which "
|
||||
"will be used for normalization (balancing) the result of the command. It should not be empty.");
|
||||
DEFINE_uint64(
|
||||
ignore_datapoints_number, 100,
|
||||
"The number of datapoints in an mwm to exclude the mwm from balancing process. If this number "
|
||||
"of datapoints or less number is in an mwm after matching and tabling, the mwm will not used "
|
||||
"for balancing. This param should be used with balance_csv command.");
|
||||
DEFINE_string(input_distribution, "",
|
||||
"path to input data point distribution file. It's a csv file with data point count for "
|
||||
"some mwms. Usage:\n"
|
||||
"- It may be used with match and match_dir command. If so it's a path to save file with "
|
||||
"data point distribution by mwm. If it's empty no file is saved.\n"
|
||||
"- It may be used with balance_csv command. If so it's a path of a file with distribution which "
|
||||
"will be used for normalization (balancing) the result of the command. It should not be empty.");
|
||||
DEFINE_uint64(ignore_datapoints_number, 100,
|
||||
"The number of datapoints in an mwm to exclude the mwm from balancing process. If this number "
|
||||
"of datapoints or less number is in an mwm after matching and tabling, the mwm will not used "
|
||||
"for balancing. This param should be used with balance_csv command.");
|
||||
|
||||
DEFINE_string(track_extension, ".track", "track files extension");
|
||||
DEFINE_bool(no_world_logs, false, "don't print world summary logs");
|
||||
@@ -86,7 +84,8 @@ size_t Checked_track()
|
||||
|
||||
StringFilter MakeFilter(string const & filter)
|
||||
{
|
||||
return [&](string const & value) {
|
||||
return [&](string const & value)
|
||||
{
|
||||
if (filter.empty())
|
||||
return false;
|
||||
return value != filter;
|
||||
@@ -97,8 +96,7 @@ StringFilter MakeFilter(string const & filter)
|
||||
namespace track_analyzing
|
||||
{
|
||||
// Print the specified track in C++ form that you can copy paste to C++ source for debugging.
|
||||
void CmdCppTrack(string const & trackFile, string const & mwmName, string const & user,
|
||||
size_t trackIdx);
|
||||
void CmdCppTrack(string const & trackFile, string const & mwmName, string const & user, size_t trackIdx);
|
||||
// Match raw gps logs to tracks.
|
||||
void CmdMatch(string const & logFile, string const & trackFile, string const & inputDistribution);
|
||||
// The same as match but applies for the directory with raw logs.
|
||||
@@ -106,15 +104,13 @@ void CmdMatchDir(string const & logDir, string const & trackExt, string const &
|
||||
// Parse |logFile| and save tracks (mwm name, aloha id, lats, lons, timestamps in seconds in csv).
|
||||
void CmdUnmatchedTracks(string const & logFile, string const & trackFileCsv);
|
||||
// Print aggregated tracks to csv table.
|
||||
void CmdTagsTable(string const & filepath, string const & trackExtension,
|
||||
StringFilter mwmIsFiltered, StringFilter userFilter);
|
||||
void CmdTagsTable(string const & filepath, string const & trackExtension, StringFilter mwmIsFiltered,
|
||||
StringFilter userFilter);
|
||||
// Print track information.
|
||||
void CmdTrack(string const & trackFile, string const & mwmName, string const & user,
|
||||
size_t trackIdx);
|
||||
void CmdTrack(string const & trackFile, string const & mwmName, string const & user, size_t trackIdx);
|
||||
// Print tracks statistics.
|
||||
void CmdTracks(string const & filepath, string const & trackExtension, StringFilter mwmFilter,
|
||||
StringFilter userFilter, TrackFilter const & filter, bool noTrackLogs,
|
||||
bool noMwmLogs, bool noWorldLogs);
|
||||
void CmdTracks(string const & filepath, string const & trackExtension, StringFilter mwmFilter, StringFilter userFilter,
|
||||
TrackFilter const & filter, bool noTrackLogs, bool noMwmLogs, bool noWorldLogs);
|
||||
|
||||
void CmdGPX(string const & logFile, string const & outputFilesDir, string const & userID);
|
||||
} // namespace track_analyzing
|
||||
@@ -145,10 +141,10 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
else if (cmd == "tracks")
|
||||
{
|
||||
TrackFilter const filter(FLAGS_min_duration, FLAGS_min_length, FLAGS_min_speed,
|
||||
FLAGS_max_speed, FLAGS_ignore_traffic);
|
||||
CmdTracks(Checked_in(), FLAGS_track_extension, MakeFilter(FLAGS_mwm), MakeFilter(FLAGS_user),
|
||||
filter, FLAGS_no_track_logs, FLAGS_no_mwm_logs, FLAGS_no_world_logs);
|
||||
TrackFilter const filter(FLAGS_min_duration, FLAGS_min_length, FLAGS_min_speed, FLAGS_max_speed,
|
||||
FLAGS_ignore_traffic);
|
||||
CmdTracks(Checked_in(), FLAGS_track_extension, MakeFilter(FLAGS_mwm), MakeFilter(FLAGS_user), filter,
|
||||
FLAGS_no_track_logs, FLAGS_no_mwm_logs, FLAGS_no_world_logs);
|
||||
}
|
||||
else if (cmd == "track")
|
||||
{
|
||||
@@ -160,8 +156,7 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
else if (cmd == "table")
|
||||
{
|
||||
CmdTagsTable(Checked_in(), FLAGS_track_extension, MakeFilter(FLAGS_mwm),
|
||||
MakeFilter(FLAGS_user));
|
||||
CmdTagsTable(Checked_in(), FLAGS_track_extension, MakeFilter(FLAGS_mwm), MakeFilter(FLAGS_user));
|
||||
}
|
||||
else if (cmd == "balance_csv")
|
||||
{
|
||||
@@ -171,8 +166,7 @@ int main(int argc, char ** argv)
|
||||
"distribution. Hint: this file may be saved by match or match_dir command."));
|
||||
return 1;
|
||||
}
|
||||
CmdBalanceCsv(FLAGS_in, FLAGS_input_distribution,
|
||||
base::checked_cast<uint64_t>(FLAGS_ignore_datapoints_number));
|
||||
CmdBalanceCsv(FLAGS_in, FLAGS_input_distribution, base::checked_cast<uint64_t>(FLAGS_ignore_datapoints_number));
|
||||
}
|
||||
else if (cmd == "gpx")
|
||||
{
|
||||
|
||||
@@ -31,8 +31,7 @@ namespace
|
||||
set<string> GetKeys(Stats::NameToCountMapping const & mapping)
|
||||
{
|
||||
set<string> keys;
|
||||
transform(mapping.begin(), mapping.end(), inserter(keys, keys.end()),
|
||||
[](auto const & kv) { return kv.first; });
|
||||
transform(mapping.begin(), mapping.end(), inserter(keys, keys.end()), [](auto const & kv) { return kv.first; });
|
||||
return keys;
|
||||
}
|
||||
|
||||
@@ -57,8 +56,8 @@ void Add(Stats::NameToCountMapping const & addition, Stats::NameToCountMapping &
|
||||
}
|
||||
}
|
||||
|
||||
void PrintMap(string const & keyName, string const & descr,
|
||||
Stats::NameToCountMapping const & mapping, ostringstream & ss)
|
||||
void PrintMap(string const & keyName, string const & descr, Stats::NameToCountMapping const & mapping,
|
||||
ostringstream & ss)
|
||||
{
|
||||
ss << descr << '\n';
|
||||
if (mapping.empty())
|
||||
@@ -74,17 +73,15 @@ void PrintMap(string const & keyName, string const & descr,
|
||||
namespace track_analyzing
|
||||
{
|
||||
// Stats ===========================================================================================
|
||||
Stats::Stats(NameToCountMapping const & mwmToTotalDataPoints,
|
||||
NameToCountMapping const & countryToTotalDataPoint)
|
||||
Stats::Stats(NameToCountMapping const & mwmToTotalDataPoints, NameToCountMapping const & countryToTotalDataPoint)
|
||||
: m_mwmToTotalDataPoints(mwmToTotalDataPoints)
|
||||
, m_countryToTotalDataPoints(countryToTotalDataPoint)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool Stats::operator==(Stats const & stats) const
|
||||
{
|
||||
return m_mwmToTotalDataPoints == stats.m_mwmToTotalDataPoints &&
|
||||
m_countryToTotalDataPoints == stats.m_countryToTotalDataPoints;
|
||||
m_countryToTotalDataPoints == stats.m_countryToTotalDataPoints;
|
||||
}
|
||||
|
||||
void Stats::Add(Stats const & stats)
|
||||
@@ -93,8 +90,7 @@ void Stats::Add(Stats const & stats)
|
||||
::Add(stats.m_countryToTotalDataPoints, m_countryToTotalDataPoints);
|
||||
}
|
||||
|
||||
void Stats::AddTracksStats(MwmToTracks const & mwmToTracks, NumMwmIds const & numMwmIds,
|
||||
Storage const & storage)
|
||||
void Stats::AddTracksStats(MwmToTracks const & mwmToTracks, NumMwmIds const & numMwmIds, Storage const & storage)
|
||||
{
|
||||
for (auto const & kv : mwmToTracks)
|
||||
{
|
||||
@@ -109,15 +105,13 @@ void Stats::AddTracksStats(MwmToTracks const & mwmToTracks, NumMwmIds const & nu
|
||||
}
|
||||
}
|
||||
|
||||
void Stats::AddDataPoints(string const & mwmName, string const & countryName,
|
||||
uint64_t dataPointNum)
|
||||
void Stats::AddDataPoints(string const & mwmName, string const & countryName, uint64_t dataPointNum)
|
||||
{
|
||||
m_mwmToTotalDataPoints[mwmName] += dataPointNum;
|
||||
m_countryToTotalDataPoints[countryName] += dataPointNum;
|
||||
}
|
||||
|
||||
void Stats::AddDataPoints(string const & mwmName, storage::Storage const & storage,
|
||||
uint64_t dataPointNum)
|
||||
void Stats::AddDataPoints(string const & mwmName, storage::Storage const & storage, uint64_t dataPointNum)
|
||||
{
|
||||
auto const countryName = storage.GetTopmostParentFor(mwmName);
|
||||
// Note. In case of disputed mwms |countryName| will be empty.
|
||||
@@ -126,8 +120,7 @@ void Stats::AddDataPoints(string const & mwmName, storage::Storage const & stora
|
||||
|
||||
void Stats::SaveMwmDistributionToCsv(string const & csvPath) const
|
||||
{
|
||||
LOG(LINFO, ("Saving mwm distribution to", csvPath, "m_mwmToTotalDataPoints size is",
|
||||
m_mwmToTotalDataPoints.size()));
|
||||
LOG(LINFO, ("Saving mwm distribution to", csvPath, "m_mwmToTotalDataPoints size is", m_mwmToTotalDataPoints.size()));
|
||||
if (csvPath.empty())
|
||||
return;
|
||||
|
||||
@@ -162,8 +155,8 @@ void Stats::LogCountries() const
|
||||
LogNameToCountMapping("country", "Country name to data points number:", m_countryToTotalDataPoints);
|
||||
}
|
||||
|
||||
void MappingToCsv(string const & keyName, Stats::NameToCountMapping const & mapping,
|
||||
bool printPercentage, basic_ostream<char> & ss)
|
||||
void MappingToCsv(string const & keyName, Stats::NameToCountMapping const & mapping, bool printPercentage,
|
||||
basic_ostream<char> & ss)
|
||||
{
|
||||
struct KeyValue
|
||||
{
|
||||
@@ -208,8 +201,7 @@ void MappingToCsv(string const & keyName, Stats::NameToCountMapping const & mapp
|
||||
|
||||
void MappingFromCsv(basic_istream<char> & ss, Stats::NameToCountMapping & mapping)
|
||||
{
|
||||
for (auto const & row :
|
||||
coding::CSVRunner(coding::CSVReader(ss, true /* hasHeader */, ',' /* kCsvDelimiter */)))
|
||||
for (auto const & row : coding::CSVRunner(coding::CSVReader(ss, true /* hasHeader */, ',' /* kCsvDelimiter */)))
|
||||
{
|
||||
CHECK_EQUAL(row.size(), 2, (row));
|
||||
auto const & key = row[0];
|
||||
@@ -220,8 +212,7 @@ void MappingFromCsv(basic_istream<char> & ss, Stats::NameToCountMapping & mappin
|
||||
}
|
||||
}
|
||||
|
||||
void ParseTracks(string const & logFile, shared_ptr<NumMwmIds> const & numMwmIds,
|
||||
MwmToTracks & mwmToTracks)
|
||||
void ParseTracks(string const & logFile, shared_ptr<NumMwmIds> const & numMwmIds, MwmToTracks & mwmToTracks)
|
||||
{
|
||||
Platform const & platform = GetPlatform();
|
||||
string const dataDir = platform.WritableDir();
|
||||
@@ -240,8 +231,7 @@ void WriteCsvTableHeader(basic_ostream<char> & stream)
|
||||
"intersection with big\n";
|
||||
}
|
||||
|
||||
void LogNameToCountMapping(string const & keyName, string const & descr,
|
||||
Stats::NameToCountMapping const & mapping)
|
||||
void LogNameToCountMapping(string const & keyName, string const & descr, Stats::NameToCountMapping const & mapping)
|
||||
{
|
||||
ostringstream ss;
|
||||
LOG(LINFO, ("\n"));
|
||||
|
||||
@@ -23,8 +23,7 @@ public:
|
||||
using NameToCountMapping = std::map<std::string, uint64_t>;
|
||||
|
||||
Stats() = default;
|
||||
Stats(NameToCountMapping const & mwmToTotalDataPoints,
|
||||
NameToCountMapping const & countryToTotalDataPoint);
|
||||
Stats(NameToCountMapping const & mwmToTotalDataPoints, NameToCountMapping const & countryToTotalDataPoint);
|
||||
|
||||
bool operator==(Stats const & stats) const;
|
||||
void Add(Stats const & stats);
|
||||
@@ -34,11 +33,9 @@ public:
|
||||
storage::Storage const & storage);
|
||||
|
||||
/// \brief Adds |dataPointNum| to |m_mwmToTotalDataPoints| and |m_countryToTotalDataPoints|.
|
||||
void AddDataPoints(std::string const & mwmName, std::string const & countryName,
|
||||
uint64_t dataPointNum);
|
||||
void AddDataPoints(std::string const & mwmName, std::string const & countryName, uint64_t dataPointNum);
|
||||
|
||||
void AddDataPoints(std::string const & mwmName, storage::Storage const & storage,
|
||||
uint64_t dataPointNum);
|
||||
void AddDataPoints(std::string const & mwmName, storage::Storage const & storage, uint64_t dataPointNum);
|
||||
|
||||
/// \brief Saves csv file with numbers of DataPoints for each mwm to |csvPath|.
|
||||
/// If |csvPath| is empty it does nothing.
|
||||
@@ -60,8 +57,8 @@ private:
|
||||
};
|
||||
|
||||
/// \brief Saves |mapping| as csv to |ss|.
|
||||
void MappingToCsv(std::string const & keyName, Stats::NameToCountMapping const & mapping,
|
||||
bool printPercentage, std::basic_ostream<char> & ss);
|
||||
void MappingToCsv(std::string const & keyName, Stats::NameToCountMapping const & mapping, bool printPercentage,
|
||||
std::basic_ostream<char> & ss);
|
||||
/// \breif Fills |mapping| according to csv in |ss|. Csv header is skipped.
|
||||
void MappingFromCsv(std::basic_istream<char> & ss, Stats::NameToCountMapping & mapping);
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace
|
||||
using namespace std;
|
||||
using namespace track_analyzing;
|
||||
|
||||
string const csv = R"(user,mwm,hw type,surface type,maxspeed km/h,is city road,is one way,is day,lat lon,distance,time,mean speed km/h,turn from smaller to bigger,turn from bigger to smaller,from link,to link,intersection with big,intersection with small,intersection with link
|
||||
string const csv =
|
||||
R"(user,mwm,hw type,surface type,maxspeed km/h,is city road,is one way,is day,lat lon,distance,time,mean speed km/h,turn from smaller to bigger,turn from bigger to smaller,from link,to link,intersection with big,intersection with small,intersection with link
|
||||
I:D923B4DC-09E0-4B0B-B7F8-153965396B55,New Zealand,highway-trunk,psurface-paved_good,80,0,0,1,-41.4832 173.844,163.984,6,98.3902,0,0,0,0,0,1,0
|
||||
I:D923B4DC-09E0-4B0B-B7F8-153965396B55,New Zealand,highway-trunk,psurface-paved_good,80,0,0,1,-41.4831 173.845,2274.59,108,75.8196,0,0,0,0,0,4,0
|
||||
A:b6e31294-5c90-4105-9f7b-51a382eabfa0,Poland,highway-primary,psurface-paved_good,50,0,0,0,53.8524 21.3061,1199.34,60,71.9604,0,0,0,0,0,10,0)";
|
||||
@@ -48,15 +49,12 @@ UNIT_TEST(FillTableTest)
|
||||
MwmToDataPoints const expectedMatchedDataPoints = {{"New Zealand", 2 /* data points */},
|
||||
{"Poland", 1 /* data points */}};
|
||||
std::vector<TableRow> expectedTable = {
|
||||
{"I:D923B4DC-09E0-4B0B-B7F8-153965396B55", "New Zealand", "highway-trunk",
|
||||
"psurface-paved_good", "80", "0", "0", "1", "-41.4832 173.844", "163.984", "6", "98.3902",
|
||||
"0", "0", "0", "0", "0", "1", "0"},
|
||||
{"I:D923B4DC-09E0-4B0B-B7F8-153965396B55", "New Zealand", "highway-trunk",
|
||||
"psurface-paved_good", "80", "0", "0", "1", "-41.4831 173.845", "2274.59", "108", "75.8196",
|
||||
"0", "0", "0", "0", "0", "4", "0"},
|
||||
{"A:b6e31294-5c90-4105-9f7b-51a382eabfa0", "Poland", "highway-primary", "psurface-paved_good",
|
||||
"50", "0", "0", "0", "53.8524 21.3061", "1199.34", "60", "71.9604", "0", "0", "0", "0", "0",
|
||||
"10", "0"}};
|
||||
{"I:D923B4DC-09E0-4B0B-B7F8-153965396B55", "New Zealand", "highway-trunk", "psurface-paved_good", "80", "0", "0",
|
||||
"1", "-41.4832 173.844", "163.984", "6", "98.3902", "0", "0", "0", "0", "0", "1", "0"},
|
||||
{"I:D923B4DC-09E0-4B0B-B7F8-153965396B55", "New Zealand", "highway-trunk", "psurface-paved_good", "80", "0", "0",
|
||||
"1", "-41.4831 173.845", "2274.59", "108", "75.8196", "0", "0", "0", "0", "0", "4", "0"},
|
||||
{"A:b6e31294-5c90-4105-9f7b-51a382eabfa0", "Poland", "highway-primary", "psurface-paved_good", "50", "0", "0",
|
||||
"0", "53.8524 21.3061", "1199.34", "60", "71.9604", "0", "0", "0", "0", "0", "10", "0"}};
|
||||
|
||||
TEST_EQUAL(matchedDataPoints, expectedMatchedDataPoints, ());
|
||||
TEST_EQUAL(table, expectedTable, ());
|
||||
@@ -69,10 +67,8 @@ UNIT_TEST(AreKeysEqualEmptyMapsTest)
|
||||
|
||||
UNIT_TEST(AreKeysEqualTest)
|
||||
{
|
||||
MwmToDataPoints const map1 = {{"Russia_Moscow", 5 /* data points */},
|
||||
{"San Marino", 7 /* data points */}};
|
||||
MwmToDataPoints map2 = {{"Russia_Moscow", 7 /* data points*/},
|
||||
{"San Marino", 9 /* data points */}};
|
||||
MwmToDataPoints const map1 = {{"Russia_Moscow", 5 /* data points */}, {"San Marino", 7 /* data points */}};
|
||||
MwmToDataPoints map2 = {{"Russia_Moscow", 7 /* data points*/}, {"San Marino", 9 /* data points */}};
|
||||
TEST(AreKeysEqual(map1, map2), ());
|
||||
|
||||
map2["Slovakia"] = 3;
|
||||
@@ -90,10 +86,8 @@ UNIT_TEST(RemoveKeysSmallValueEmptyTest)
|
||||
|
||||
UNIT_TEST(RemoveKeysSmallValueTest)
|
||||
{
|
||||
MwmToDataPoints checkedMap = {{"Russia_Moscow", 3 /* data points */},
|
||||
{"San Marino", 5 /* data points */}};
|
||||
MwmToDataPoints additionalMap = {{"Russia_Moscow", 7 /* data points*/},
|
||||
{"San Marino", 9 /* data points */}};
|
||||
MwmToDataPoints checkedMap = {{"Russia_Moscow", 3 /* data points */}, {"San Marino", 5 /* data points */}};
|
||||
MwmToDataPoints additionalMap = {{"Russia_Moscow", 7 /* data points*/}, {"San Marino", 9 /* data points */}};
|
||||
RemoveKeysSmallValue(checkedMap, additionalMap, 4 /* ignoreDataPointNumber */);
|
||||
|
||||
MwmToDataPoints expectedCheckedMap = {{"San Marino", 5 /* data points */}};
|
||||
@@ -110,9 +104,8 @@ UNIT_TEST(GetMwmToDataPointFractionTest)
|
||||
{"Slovakia", 50 /* data points */}};
|
||||
auto const fractionMapping = GetMwmToDataPointFraction(numberMapping);
|
||||
|
||||
MwmToDataPointFraction expectedFractionMapping{{"Russia_Moscow", 0.5 /* fraction */},
|
||||
{"San Marino", 0.25 /* fraction */},
|
||||
{"Slovakia", 0.25 /* fraction */}};
|
||||
MwmToDataPointFraction expectedFractionMapping{
|
||||
{"Russia_Moscow", 0.5 /* fraction */}, {"San Marino", 0.25 /* fraction */}, {"Slovakia", 0.25 /* fraction */}};
|
||||
TEST_EQUAL(fractionMapping, expectedFractionMapping, ());
|
||||
}
|
||||
|
||||
@@ -153,9 +146,8 @@ UNIT_TEST(BalancedDataPointNumberTheSameTest)
|
||||
MwmToDataPoints const distribution = {{"Russia_Moscow", 100 /* data points */},
|
||||
{"San Marino", 50 /* data points */},
|
||||
{"Slovakia", 50 /* data points */}};
|
||||
MwmToDataPoints const matchedDataPoints = {{"Russia_Moscow", 10 /* data points */},
|
||||
{"San Marino", 5 /* data points */},
|
||||
{"Slovakia", 5 /* data points */}};
|
||||
MwmToDataPoints const matchedDataPoints = {
|
||||
{"Russia_Moscow", 10 /* data points */}, {"San Marino", 5 /* data points */}, {"Slovakia", 5 /* data points */}};
|
||||
{
|
||||
// Case when the distribution is not changed. All mwms lose the same percent of data points.
|
||||
auto distr = distribution;
|
||||
@@ -226,7 +218,8 @@ UNIT_TEST(FilterTableTest)
|
||||
ss << csv;
|
||||
FillTable(ss, matchedDataPoints, csvTable);
|
||||
|
||||
auto const calcRecords = [](vector<TableRow> const & t, string const & mwmName) {
|
||||
auto const calcRecords = [](vector<TableRow> const & t, string const & mwmName)
|
||||
{
|
||||
return count_if(t.cbegin(), t.cend(),
|
||||
[&mwmName](TableRow const & row) { return row[kMwmNameCsvColumn] == mwmName; });
|
||||
};
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
#include "geometry/latlon.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -43,27 +43,24 @@ UNIT_TEST(AddDataPointsTest)
|
||||
stats.AddDataPoints("mwm2", "country1", 5);
|
||||
stats.AddDataPoints("mwm3", "country3", 7);
|
||||
|
||||
Stats const expected = {
|
||||
{{"mwm1", 4}, {"mwm2", 5}, {"mwm3", 7} /* Mwm to number */},
|
||||
{{"country1", 9}, {"country3", 7} /* Country to number */}};
|
||||
Stats const expected = {{{"mwm1", 4}, {"mwm2", 5}, {"mwm3", 7} /* Mwm to number */},
|
||||
{{"country1", 9}, {"country3", 7} /* Country to number */}};
|
||||
|
||||
TEST_EQUAL(stats, expected, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(AddStatTest)
|
||||
{
|
||||
Stats stats1 = {
|
||||
{{"Belarus_Minsk Region", 1}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */},
|
||||
{{"Russian Federation", 10}, {"Poland", 5} /* Country to number */}};
|
||||
Stats stats1 = {{{"Belarus_Minsk Region", 1}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */},
|
||||
{{"Russian Federation", 10}, {"Poland", 5} /* Country to number */}};
|
||||
|
||||
Stats const stats2 = {{{"Belarus_Minsk Region", 2} /* Mwm to number */},
|
||||
{{"Russian Federation", 1}, {"Belarus", 8} /* Country to number */}};
|
||||
|
||||
stats1.Add(stats2);
|
||||
|
||||
Stats const expected = {
|
||||
{{"Belarus_Minsk Region", 3}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */},
|
||||
{{"Russian Federation", 11}, {"Poland", 5}, {"Belarus", 8} /* Country to number */}};
|
||||
Stats const expected = {{{"Belarus_Minsk Region", 3}, {"Uzbekistan", 7}, {"Russia_Moscow", 5} /* Mwm to number */},
|
||||
{{"Russian Federation", 11}, {"Poland", 5}, {"Belarus", 8} /* Country to number */}};
|
||||
|
||||
TEST_EQUAL(stats1, expected, ());
|
||||
}
|
||||
@@ -101,8 +98,7 @@ UNIT_TEST(AddTracksStatsTest)
|
||||
|
||||
UNIT_TEST(MappingToCsvTest)
|
||||
{
|
||||
Stats::NameToCountMapping const mapping = {
|
||||
{{"Belarus_Minsk Region", 2}, {"Uzbekistan", 5}, {"Russia_Moscow", 3}}};
|
||||
Stats::NameToCountMapping const mapping = {{{"Belarus_Minsk Region", 2}, {"Uzbekistan", 5}, {"Russia_Moscow", 3}}};
|
||||
{
|
||||
std::ostringstream ss;
|
||||
MappingToCsv("mwm", mapping, true /* printPercentage */, ss);
|
||||
@@ -127,8 +123,7 @@ Belarus_Minsk Region,2
|
||||
|
||||
UNIT_TEST(MappingToCsvUint64Test)
|
||||
{
|
||||
Stats::NameToCountMapping const mapping = {{"Belarus_Minsk Region", 5'000'000'000},
|
||||
{"Uzbekistan", 15'000'000'000}};
|
||||
Stats::NameToCountMapping const mapping = {{"Belarus_Minsk Region", 5'000'000'000}, {"Uzbekistan", 15'000'000'000}};
|
||||
std::stringstream ss;
|
||||
MappingToCsv("mwm", mapping, true /* printPercentage */, ss);
|
||||
std::string const expected = R"(mwm,number,percent
|
||||
@@ -140,21 +135,17 @@ Belarus_Minsk Region,5000000000,25
|
||||
|
||||
UNIT_TEST(SerializationToCsvTest)
|
||||
{
|
||||
Stats::NameToCountMapping const mapping1 = {{"Belarus_Minsk Region", 2},
|
||||
{"Uzbekistan", 5},
|
||||
{"Russia_Moscow", 1},
|
||||
{"Russia_Moscow Oblast_East", 2}};
|
||||
Stats::NameToCountMapping const mapping1 = {
|
||||
{"Belarus_Minsk Region", 2}, {"Uzbekistan", 5}, {"Russia_Moscow", 1}, {"Russia_Moscow Oblast_East", 2}};
|
||||
TestSerializationToCsv(mapping1);
|
||||
|
||||
Stats::NameToCountMapping const mapping2 = {
|
||||
{{"Belarus_Minsk Region", 2}, {"Uzbekistan", 5}, {"Russia_Moscow", 3}}};
|
||||
Stats::NameToCountMapping const mapping2 = {{{"Belarus_Minsk Region", 2}, {"Uzbekistan", 5}, {"Russia_Moscow", 3}}};
|
||||
TestSerializationToCsv(mapping2);
|
||||
}
|
||||
|
||||
UNIT_TEST(SerializationToCsvWithZeroValueTest)
|
||||
{
|
||||
Stats::NameToCountMapping const mapping = {{"Russia_Moscow Oblast_East", 2},
|
||||
{"Poland_Lesser Poland Voivodeship", 0}};
|
||||
Stats::NameToCountMapping const mapping = {{"Russia_Moscow Oblast_East", 2}, {"Poland_Lesser Poland Voivodeship", 0}};
|
||||
Stats::NameToCountMapping const expected = {{"Russia_Moscow Oblast_East", 2}};
|
||||
|
||||
std::stringstream ss;
|
||||
@@ -168,9 +159,8 @@ UNIT_TEST(SerializationToCsvWithZeroValueTest)
|
||||
|
||||
UNIT_TEST(SerializationToCsvUint64Test)
|
||||
{
|
||||
Stats::NameToCountMapping const mapping = {{"Belarus_Minsk Region", 20'000'000'000},
|
||||
{"Uzbekistan", 5},
|
||||
{"Russia_Moscow", 7'000'000'000}};
|
||||
Stats::NameToCountMapping const mapping = {
|
||||
{"Belarus_Minsk Region", 20'000'000'000}, {"Uzbekistan", 5}, {"Russia_Moscow", 7'000'000'000}};
|
||||
TestSerializationToCsv(mapping);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include "coding/zip_creator.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "3party/minizip/minizip.hpp"
|
||||
|
||||
@@ -31,8 +31,7 @@ struct UserTrackInfo
|
||||
Track m_track;
|
||||
};
|
||||
|
||||
std::optional<UserTrackInfo> ParseLogRecord(std::string const & record,
|
||||
TemporaryFile & tmpArchiveFile);
|
||||
std::optional<UserTrackInfo> ParseLogRecord(std::string const & record, TemporaryFile & tmpArchiveFile);
|
||||
std::optional<std::string> ParseMultipartData(std::string const & binaryData);
|
||||
bool ParseTrackFile(unzip::File & zipReader, Track & trackData) noexcept;
|
||||
template <typename Reader, typename Pack>
|
||||
@@ -83,8 +82,8 @@ UNIT_TEST(UnpackTrackArchiveDataTest)
|
||||
vector<string> trackFiles;
|
||||
trackFiles.push_back(archiveFileName);
|
||||
string const containerFileName("test_track_archive.zip");
|
||||
TEST_EQUAL(CreateZipFromFiles(trackFiles, containerFileName, CompressionLevel::NoCompression),
|
||||
true, ("Unable to create tracks archive"));
|
||||
TEST_EQUAL(CreateZipFromFiles(trackFiles, containerFileName, CompressionLevel::NoCompression), true,
|
||||
("Unable to create tracks archive"));
|
||||
FileWriter::DeleteFileX(archiveFileName);
|
||||
|
||||
// Step 2.3: Read batch archive content
|
||||
@@ -99,8 +98,7 @@ UNIT_TEST(UnpackTrackArchiveDataTest)
|
||||
// Step 2.4: Wrap as multipart data
|
||||
stringstream multipartStream;
|
||||
multipartStream << "------0000000000000\r\n";
|
||||
multipartStream << "Content-Disposition: form-data; name=\"file\"; filename=\""
|
||||
<< containerFileName << "\"\r\n";
|
||||
multipartStream << "Content-Disposition: form-data; name=\"file\"; filename=\"" << containerFileName << "\"\r\n";
|
||||
multipartStream << "Content-Type: application/zip\r\n";
|
||||
multipartStream << "\r\n";
|
||||
multipartStream.write(buffer.data(), buffer.size());
|
||||
@@ -110,16 +108,14 @@ UNIT_TEST(UnpackTrackArchiveDataTest)
|
||||
string multipartData = multipartStream.str();
|
||||
|
||||
stringstream logStream;
|
||||
logStream << testUserId << "\t1\t1577826010\t" << multipartData.size() << "\t"
|
||||
<< ToHex(multipartData);
|
||||
logStream << testUserId << "\t1\t1577826010\t" << multipartData.size() << "\t" << ToHex(multipartData);
|
||||
|
||||
string const logRecord = logStream.str();
|
||||
|
||||
// Unpack log record
|
||||
TemporaryFile tmpArchiveFile("tmp-unittest", ".zip");
|
||||
|
||||
optional<track_analyzing::details::UserTrackInfo> data =
|
||||
ParseLogRecord(logRecord, tmpArchiveFile);
|
||||
optional<track_analyzing::details::UserTrackInfo> data = ParseLogRecord(logRecord, tmpArchiveFile);
|
||||
TEST_EQUAL(bool(data), true, ("Unable parse track archive record"));
|
||||
|
||||
TEST_EQUAL(data->m_userId, testUserId, ());
|
||||
@@ -128,10 +124,8 @@ UNIT_TEST(UnpackTrackArchiveDataTest)
|
||||
for (size_t i = 0; i < testTrack.size(); ++i)
|
||||
{
|
||||
TEST_EQUAL(data->m_track[i].m_timestamp, testTrack[i].m_timestamp, ());
|
||||
TEST_ALMOST_EQUAL_ABS(data->m_track[i].m_latLon.m_lat, testTrack[i].m_latLon.m_lat,
|
||||
kAccuracyEps, ());
|
||||
TEST_ALMOST_EQUAL_ABS(data->m_track[i].m_latLon.m_lon, testTrack[i].m_latLon.m_lon,
|
||||
kAccuracyEps, ());
|
||||
TEST_ALMOST_EQUAL_ABS(data->m_track[i].m_latLon.m_lat, testTrack[i].m_latLon.m_lat, kAccuracyEps, ());
|
||||
TEST_ALMOST_EQUAL_ABS(data->m_track[i].m_latLon.m_lon, testTrack[i].m_latLon.m_lon, kAccuracyEps, ());
|
||||
TEST_EQUAL(data->m_track[i].m_traffic, testTrack[i].m_traffic, ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ using namespace track_analyzing;
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
const string kTmpArchiveFileNameTemplate("-tmp-track-archive.zip");
|
||||
string const kTmpArchiveFileNameTemplate("-tmp-track-archive.zip");
|
||||
|
||||
// Track record fields:
|
||||
// 0: user ID
|
||||
@@ -124,8 +124,8 @@ optional<string> ParseMultipartData(string const & binaryData)
|
||||
{
|
||||
if (expectedContentType == header)
|
||||
hasContentTypeHeader = true;
|
||||
if (expectedContentDispositionPrefix.compare(0, string::npos, header, 0,
|
||||
expectedContentDispositionPrefix.size()) == 0)
|
||||
if (expectedContentDispositionPrefix.compare(0, string::npos, header, 0, expectedContentDispositionPrefix.size()) ==
|
||||
0)
|
||||
{
|
||||
hasContentDispositionHeader = true;
|
||||
}
|
||||
@@ -140,8 +140,8 @@ optional<string> ParseMultipartData(string const & binaryData)
|
||||
|
||||
bool HasZipSignature(string const & binaryData)
|
||||
{
|
||||
return binaryData.size() >= 4 && binaryData[0] == 0x50 && binaryData[1] == 0x4b &&
|
||||
binaryData[2] == 0x03 && binaryData[3] == 0x04;
|
||||
return binaryData.size() >= 4 && binaryData[0] == 0x50 && binaryData[1] == 0x4b && binaryData[2] == 0x03 &&
|
||||
binaryData[3] == 0x04;
|
||||
}
|
||||
|
||||
template <typename Reader, typename Pack>
|
||||
@@ -153,8 +153,7 @@ bool ReadTrackFromArchive(char const * data, size_t dataSize, Track & trackData)
|
||||
vector<uint8_t> buffer;
|
||||
inflate(data, dataSize, back_inserter(buffer));
|
||||
|
||||
ReaderSource<MemReaderWithExceptions> reader(
|
||||
MemReaderWithExceptions(buffer.data(), buffer.size()));
|
||||
ReaderSource<MemReaderWithExceptions> reader(MemReaderWithExceptions(buffer.data(), buffer.size()));
|
||||
if (reader.Size() == 0)
|
||||
return false;
|
||||
|
||||
@@ -209,13 +208,13 @@ bool ParseTrackFile(unzip::File & zipReader, Track & trackData) noexcept
|
||||
bool result = false;
|
||||
if (archiveInfo.m_trackType == routing::RouterType::Vehicle)
|
||||
{
|
||||
result = ReadTrackFromArchive<ReaderSource<MemReaderWithExceptions>, tracking::PacketCar>(
|
||||
fileData.data(), dataSize, trackData);
|
||||
result = ReadTrackFromArchive<ReaderSource<MemReaderWithExceptions>, tracking::PacketCar>(fileData.data(), dataSize,
|
||||
trackData);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ReadTrackFromArchive<ReaderSource<MemReaderWithExceptions>, tracking::Packet>(
|
||||
fileData.data(), dataSize, trackData);
|
||||
result = ReadTrackFromArchive<ReaderSource<MemReaderWithExceptions>, tracking::Packet>(fileData.data(), dataSize,
|
||||
trackData);
|
||||
}
|
||||
|
||||
if (unzip::CloseCurrentFile(zipReader) != unzip::Code::Ok)
|
||||
@@ -254,9 +253,7 @@ optional<Track> ParseTrackArchiveData(string const & content, TemporaryFile & tm
|
||||
|
||||
bool result = ParseTrackFile(zipReader, trackData);
|
||||
while (result && unzip::GoToNextFile(zipReader) == unzip::Code::Ok)
|
||||
{
|
||||
result = ParseTrackFile(zipReader, trackData);
|
||||
}
|
||||
|
||||
if (unzip::Close(zipReader) != unzip::Code::Ok)
|
||||
LOG(LERROR, ("Unable to close temporary zip archive"));
|
||||
@@ -285,8 +282,7 @@ optional<UserTrackInfo> ParseLogRecord(string const & record, TemporaryFile & tm
|
||||
|
||||
} // namespace details
|
||||
|
||||
void TrackArchiveReader::ParseUserTracksFromFile(string const & logFile,
|
||||
UserToTrack & userToTrack) const
|
||||
void TrackArchiveReader::ParseUserTracksFromFile(string const & logFile, UserToTrack & userToTrack) const
|
||||
{
|
||||
// Read file content
|
||||
FileReader reader(logFile);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "base/stl_helpers.hpp"
|
||||
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
using namespace routing;
|
||||
@@ -25,8 +24,7 @@ namespace
|
||||
double constexpr kMatchingRange = 20.0;
|
||||
|
||||
// Mercator distance from segment to point in meters.
|
||||
double DistanceToSegment(m2::PointD const & segmentBegin, m2::PointD const & segmentEnd,
|
||||
m2::PointD const & point)
|
||||
double DistanceToSegment(m2::PointD const & segmentBegin, m2::PointD const & segmentEnd, m2::PointD const & point)
|
||||
{
|
||||
m2::ParametrizedSegment<m2::PointD> const segment(segmentBegin, segmentEnd);
|
||||
m2::PointD const projectionPoint = segment.ClosestPointTo(point);
|
||||
@@ -36,41 +34,36 @@ double DistanceToSegment(m2::PointD const & segmentBegin, m2::PointD const & seg
|
||||
double DistanceToSegment(Segment const & segment, m2::PointD const & point, IndexGraph & indexGraph)
|
||||
{
|
||||
auto const & road = indexGraph.GetRoadGeometry(segment.GetFeatureId());
|
||||
return DistanceToSegment(
|
||||
mercator::FromLatLon(road.GetPoint(segment.GetPointId(false))),
|
||||
mercator::FromLatLon(road.GetPoint(segment.GetPointId(true))), point);
|
||||
return DistanceToSegment(mercator::FromLatLon(road.GetPoint(segment.GetPointId(false))),
|
||||
mercator::FromLatLon(road.GetPoint(segment.GetPointId(true))), point);
|
||||
}
|
||||
|
||||
bool EdgesContain(IndexGraph::SegmentEdgeListT const & edges, Segment const & segment)
|
||||
{
|
||||
for (auto const & edge : edges)
|
||||
{
|
||||
if (edge.GetTarget() == segment)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// TrackMatcher ------------------------------------------------------------------------------------
|
||||
TrackMatcher::TrackMatcher(storage::Storage const & storage, NumMwmId mwmId,
|
||||
platform::CountryFile const & countryFile)
|
||||
TrackMatcher::TrackMatcher(storage::Storage const & storage, NumMwmId mwmId, platform::CountryFile const & countryFile)
|
||||
: m_mwmId(mwmId)
|
||||
, m_vehicleModel(CarModelFactory({}).GetVehicleModelForCountry(countryFile.GetName()))
|
||||
{
|
||||
auto localCountryFile = storage.GetLatestLocalFile(countryFile);
|
||||
CHECK(localCountryFile, ("Can't find latest country file for", countryFile.GetName()));
|
||||
auto registerResult = m_dataSource.Register(*localCountryFile);
|
||||
CHECK_EQUAL(registerResult.second, MwmSet::RegResult::Success,
|
||||
("Can't register mwm", countryFile.GetName()));
|
||||
CHECK_EQUAL(registerResult.second, MwmSet::RegResult::Success, ("Can't register mwm", countryFile.GetName()));
|
||||
|
||||
MwmSet::MwmHandle handle = m_dataSource.GetMwmHandleByCountryFile(countryFile);
|
||||
|
||||
m_graph = make_unique<IndexGraph>(
|
||||
make_shared<Geometry>(GeometryLoader::Create(handle, m_vehicleModel, false /* loadAltitudes */)),
|
||||
EdgeEstimator::Create(VehicleType::Car, *m_vehicleModel, nullptr /* trafficStash */,
|
||||
nullptr /* dataSource */, nullptr /* numMvmIds */));
|
||||
EdgeEstimator::Create(VehicleType::Car, *m_vehicleModel, nullptr /* trafficStash */, nullptr /* dataSource */,
|
||||
nullptr /* numMvmIds */));
|
||||
|
||||
DeserializeIndexGraph(*handle.GetValue(), VehicleType::Car, *m_graph);
|
||||
}
|
||||
@@ -88,8 +81,7 @@ void TrackMatcher::MatchTrack(vector<DataPoint> const & track, vector<MatchedTra
|
||||
{
|
||||
for (; trackBegin < steps.size(); ++trackBegin)
|
||||
{
|
||||
steps[trackBegin].FillCandidatesWithNearbySegments(m_dataSource, *m_graph, *m_vehicleModel,
|
||||
m_mwmId);
|
||||
steps[trackBegin].FillCandidatesWithNearbySegments(m_dataSource, *m_graph, *m_vehicleModel, m_mwmId);
|
||||
if (steps[trackBegin].HasCandidates())
|
||||
break;
|
||||
|
||||
@@ -130,13 +122,12 @@ void TrackMatcher::MatchTrack(vector<DataPoint> const & track, vector<MatchedTra
|
||||
|
||||
// TrackMatcher::Step ------------------------------------------------------------------------------
|
||||
TrackMatcher::Step::Step(DataPoint const & dataPoint)
|
||||
: m_dataPoint(dataPoint), m_point(mercator::FromLatLon(dataPoint.m_latLon))
|
||||
{
|
||||
}
|
||||
: m_dataPoint(dataPoint)
|
||||
, m_point(mercator::FromLatLon(dataPoint.m_latLon))
|
||||
{}
|
||||
|
||||
void TrackMatcher::Step::FillCandidatesWithNearbySegments(
|
||||
DataSource const & dataSource, IndexGraph const & graph,
|
||||
VehicleModelInterface const & vehicleModel, NumMwmId mwmId)
|
||||
void TrackMatcher::Step::FillCandidatesWithNearbySegments(DataSource const & dataSource, IndexGraph const & graph,
|
||||
VehicleModelInterface const & vehicleModel, NumMwmId mwmId)
|
||||
{
|
||||
dataSource.ForEachInRect([&](FeatureType & ft)
|
||||
{
|
||||
@@ -154,25 +145,20 @@ void TrackMatcher::Step::FillCandidatesWithNearbySegments(
|
||||
|
||||
for (size_t segIdx = 0; segIdx + 1 < ft.GetPointsCount(); ++segIdx)
|
||||
{
|
||||
double const distance =
|
||||
DistanceToSegment(ft.GetPoint(segIdx), ft.GetPoint(segIdx + 1), m_point);
|
||||
double const distance = DistanceToSegment(ft.GetPoint(segIdx), ft.GetPoint(segIdx + 1), m_point);
|
||||
if (distance < kMatchingRange)
|
||||
{
|
||||
AddCandidate(Segment(mwmId, ft.GetID().m_index, static_cast<uint32_t>(segIdx),
|
||||
true /* forward */),
|
||||
distance, graph);
|
||||
AddCandidate(Segment(mwmId, ft.GetID().m_index, static_cast<uint32_t>(segIdx), true /* forward */), distance,
|
||||
graph);
|
||||
|
||||
if (!vehicleModel.IsOneWay(types))
|
||||
{
|
||||
AddCandidate(Segment(mwmId, ft.GetID().m_index, static_cast<uint32_t>(segIdx),
|
||||
false /* forward */),
|
||||
distance, graph);
|
||||
AddCandidate(Segment(mwmId, ft.GetID().m_index, static_cast<uint32_t>(segIdx), false /* forward */), distance,
|
||||
graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
mercator::RectByCenterXYAndSizeInMeters(m_point, kMatchingRange),
|
||||
scales::GetUpperScale());
|
||||
}, mercator::RectByCenterXYAndSizeInMeters(m_point, kMatchingRange), scales::GetUpperScale());
|
||||
}
|
||||
|
||||
void TrackMatcher::Step::FillCandidates(Step const & previousStep, IndexGraph & graph)
|
||||
@@ -198,9 +184,7 @@ void TrackMatcher::Step::FillCandidates(Step const & previousStep, IndexGraph &
|
||||
base::SortUnique(m_candidates);
|
||||
|
||||
m_candidates.erase(remove_if(m_candidates.begin(), m_candidates.end(),
|
||||
[&](Candidate const & candidate) {
|
||||
return candidate.GetDistance() > kMatchingRange;
|
||||
}),
|
||||
[&](Candidate const & candidate) { return candidate.GetDistance() > kMatchingRange; }),
|
||||
m_candidates.end());
|
||||
}
|
||||
|
||||
@@ -211,8 +195,7 @@ void TrackMatcher::Step::ChooseSegment(Step const & nextStep, IndexGraph & index
|
||||
double minDistance = numeric_limits<double>::max();
|
||||
|
||||
IndexGraph::SegmentEdgeListT edges;
|
||||
indexGraph.GetEdgeList(nextStep.m_segment, false /* isOutgoing */, true /* useRoutingOptions */,
|
||||
edges);
|
||||
indexGraph.GetEdgeList(nextStep.m_segment, false /* isOutgoing */, true /* useRoutingOptions */, edges);
|
||||
edges.emplace_back(nextStep.m_segment, GetAStarWeightZero<RouteWeight>());
|
||||
|
||||
for (Candidate const & candidate : m_candidates)
|
||||
@@ -244,8 +227,7 @@ void TrackMatcher::Step::ChooseNearestSegment()
|
||||
}
|
||||
}
|
||||
|
||||
void TrackMatcher::Step::AddCandidate(Segment const & segment, double distance,
|
||||
IndexGraph const & graph)
|
||||
void TrackMatcher::Step::AddCandidate(Segment const & segment, double distance, IndexGraph const & graph)
|
||||
{
|
||||
if (graph.GetAccessType(segment) == RoadAccess::Type::Yes)
|
||||
m_candidates.emplace_back(segment, distance);
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace track_analyzing
|
||||
class TrackMatcher final
|
||||
{
|
||||
public:
|
||||
TrackMatcher(storage::Storage const & storage, routing::NumMwmId mwmId,
|
||||
platform::CountryFile const & countryFile);
|
||||
TrackMatcher(storage::Storage const & storage, routing::NumMwmId mwmId, platform::CountryFile const & countryFile);
|
||||
|
||||
void MatchTrack(std::vector<DataPoint> const & track, std::vector<MatchedTrack> & matchedTracks);
|
||||
|
||||
@@ -35,9 +34,7 @@ private:
|
||||
class Candidate final
|
||||
{
|
||||
public:
|
||||
Candidate(routing::Segment segment, double distance) : m_segment(segment), m_distance(distance)
|
||||
{
|
||||
}
|
||||
Candidate(routing::Segment segment, double distance) : m_segment(segment), m_distance(distance) {}
|
||||
|
||||
routing::Segment const & GetSegment() const { return m_segment; }
|
||||
double GetDistance() const { return m_distance; }
|
||||
@@ -57,17 +54,14 @@ private:
|
||||
DataPoint const & GetDataPoint() const { return m_dataPoint; }
|
||||
routing::Segment const & GetSegment() const { return m_segment; }
|
||||
bool HasCandidates() const { return !m_candidates.empty(); }
|
||||
void FillCandidatesWithNearbySegments(DataSource const & dataSource,
|
||||
routing::IndexGraph const & graph,
|
||||
routing::VehicleModelInterface const & vehicleModel,
|
||||
routing::NumMwmId mwmId);
|
||||
void FillCandidatesWithNearbySegments(DataSource const & dataSource, routing::IndexGraph const & graph,
|
||||
routing::VehicleModelInterface const & vehicleModel, routing::NumMwmId mwmId);
|
||||
void FillCandidates(Step const & previousStep, routing::IndexGraph & graph);
|
||||
void ChooseSegment(Step const & nextStep, routing::IndexGraph & indexGraph);
|
||||
void ChooseNearestSegment();
|
||||
|
||||
private:
|
||||
void AddCandidate(routing::Segment const & segment, double distance,
|
||||
routing::IndexGraph const & graph);
|
||||
void AddCandidate(routing::Segment const & segment, double distance, routing::IndexGraph const & graph);
|
||||
|
||||
DataPoint m_dataPoint;
|
||||
m2::PointD m_point;
|
||||
|
||||
@@ -17,8 +17,7 @@ using namespace std;
|
||||
|
||||
namespace track_analyzing
|
||||
{
|
||||
double CalcSubtrackLength(MatchedTrack::const_iterator begin, MatchedTrack::const_iterator end,
|
||||
Geometry & geometry)
|
||||
double CalcSubtrackLength(MatchedTrack::const_iterator begin, MatchedTrack::const_iterator end, Geometry & geometry)
|
||||
{
|
||||
double length = 0.0;
|
||||
|
||||
@@ -29,10 +28,8 @@ double CalcSubtrackLength(MatchedTrack::const_iterator begin, MatchedTrack::cons
|
||||
Segment const & segment = point.GetSegment();
|
||||
if (segment != prevSegment)
|
||||
{
|
||||
length +=
|
||||
ms::DistanceOnEarth(
|
||||
geometry.GetPoint(segment.GetRoadPoint(false /* front */)),
|
||||
geometry.GetPoint(segment.GetRoadPoint(true /* front */)));
|
||||
length += ms::DistanceOnEarth(geometry.GetPoint(segment.GetRoadPoint(false /* front */)),
|
||||
geometry.GetPoint(segment.GetRoadPoint(true /* front */)));
|
||||
prevSegment = segment;
|
||||
}
|
||||
}
|
||||
@@ -51,8 +48,7 @@ double CalcSpeedKMpH(double meters, uint64_t secondsElapsed)
|
||||
return measurement_utils::MpsToKmph(meters / static_cast<double>(secondsElapsed));
|
||||
}
|
||||
|
||||
void ReadTracks(shared_ptr<NumMwmIds> numMwmIds, string const & filename,
|
||||
MwmToMatchedTracks & mwmToMatchedTracks)
|
||||
void ReadTracks(shared_ptr<NumMwmIds> numMwmIds, string const & filename, MwmToMatchedTracks & mwmToMatchedTracks)
|
||||
{
|
||||
FileReader reader(filename);
|
||||
ReaderSource<FileReader> src(reader);
|
||||
@@ -60,9 +56,8 @@ void ReadTracks(shared_ptr<NumMwmIds> numMwmIds, string const & filename,
|
||||
serializer.Deserialize(mwmToMatchedTracks, src);
|
||||
}
|
||||
|
||||
MatchedTrack const & GetMatchedTrack(MwmToMatchedTracks const & mwmToMatchedTracks,
|
||||
NumMwmIds const & numMwmIds, string const & mwmName,
|
||||
string const & user, size_t trackIdx)
|
||||
MatchedTrack const & GetMatchedTrack(MwmToMatchedTracks const & mwmToMatchedTracks, NumMwmIds const & numMwmIds,
|
||||
string const & mwmName, string const & user, size_t trackIdx)
|
||||
{
|
||||
auto const countryFile = platform::CountryFile(mwmName);
|
||||
if (!numMwmIds.ContainsFile(countryFile))
|
||||
@@ -84,8 +79,8 @@ MatchedTrack const & GetMatchedTrack(MwmToMatchedTracks const & mwmToMatchedTrac
|
||||
|
||||
if (trackIdx >= tracks.size())
|
||||
{
|
||||
MYTHROW(MessageException, ("There is no track", trackIdx, "for user", user, ", she has",
|
||||
tracks.size(), "tracks only"));
|
||||
MYTHROW(MessageException,
|
||||
("There is no track", trackIdx, "for user", user, ", she has", tracks.size(), "tracks only"));
|
||||
}
|
||||
|
||||
return tracks[trackIdx];
|
||||
@@ -96,10 +91,9 @@ std::string GetCurrentVersionMwmFile(storage::Storage const & storage, std::stri
|
||||
return storage.GetFilePath(mwmName, MapFileType::Map);
|
||||
}
|
||||
|
||||
void ForEachTrackFile(
|
||||
std::string const & filepath, std::string const & extension,
|
||||
shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
std::function<void(std::string const & filename, MwmToMatchedTracks const &)> && toDo)
|
||||
void ForEachTrackFile(std::string const & filepath, std::string const & extension,
|
||||
shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
std::function<void(std::string const & filename, MwmToMatchedTracks const &)> && toDo)
|
||||
{
|
||||
Platform::EFileType fileType = Platform::EFileType::Unknown;
|
||||
Platform::EError const result = Platform::GetFileType(filepath, fileType);
|
||||
|
||||
@@ -29,14 +29,12 @@ double CalcSpeedKMpH(double meters, uint64_t secondsElapsed);
|
||||
void ReadTracks(std::shared_ptr<routing::NumMwmIds> numMwmIds, std::string const & filename,
|
||||
MwmToMatchedTracks & mwmToMatchedTracks);
|
||||
MatchedTrack const & GetMatchedTrack(MwmToMatchedTracks const & mwmToMatchedTracks,
|
||||
routing::NumMwmIds const & numMwmIds,
|
||||
std::string const & mwmName, std::string const & user,
|
||||
size_t trackIdx);
|
||||
routing::NumMwmIds const & numMwmIds, std::string const & mwmName,
|
||||
std::string const & user, size_t trackIdx);
|
||||
std::string GetCurrentVersionMwmFile(storage::Storage const & storage, std::string const & mwmName);
|
||||
|
||||
template <typename MwmToTracks, typename ToDo>
|
||||
void ForTracksSortedByMwmName(MwmToTracks const & mwmToTracks, routing::NumMwmIds const & numMwmIds,
|
||||
ToDo && toDo)
|
||||
void ForTracksSortedByMwmName(MwmToTracks const & mwmToTracks, routing::NumMwmIds const & numMwmIds, ToDo && toDo)
|
||||
{
|
||||
std::vector<std::string> mwmNames;
|
||||
mwmNames.reserve(mwmToTracks.size());
|
||||
@@ -53,8 +51,7 @@ void ForTracksSortedByMwmName(MwmToTracks const & mwmToTracks, routing::NumMwmId
|
||||
}
|
||||
}
|
||||
|
||||
void ForEachTrackFile(
|
||||
std::string const & filepath, std::string const & extension,
|
||||
std::shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
std::function<void(std::string const & filename, MwmToMatchedTracks const &)> && toDo);
|
||||
void ForEachTrackFile(std::string const & filepath, std::string const & extension,
|
||||
std::shared_ptr<routing::NumMwmIds> numMwmIds,
|
||||
std::function<void(std::string const & filename, MwmToMatchedTracks const &)> && toDo);
|
||||
} // namespace track_analyzing
|
||||
|
||||
Reference in New Issue
Block a user