diff --git a/coding/traffic.hpp b/coding/traffic.hpp index 86c638e19f..97b6d317fb 100644 --- a/coding/traffic.hpp +++ b/coding/traffic.hpp @@ -9,8 +9,8 @@ #include "base/checked_cast.hpp" -#include "std/limits.hpp" -#include "std/vector.hpp" +#include +#include namespace coding { @@ -112,7 +112,7 @@ private: WriteVarUint(writer, deltaLon); } - ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, numeric_limits::max(), + ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits::max(), ("Too much data.")); return static_cast(writer.Pos() - startPos); } @@ -153,7 +153,7 @@ private: WriteVarUint(writer, traffic); } - ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, numeric_limits::max(), + ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits::max(), ("Too much data.")); return static_cast(writer.Pos() - startPos); } diff --git a/track_analyzing/track_analyzer/CMakeLists.txt b/track_analyzing/track_analyzer/CMakeLists.txt index 6ab2fcf87b..436e3cd39b 100644 --- a/track_analyzing/track_analyzer/CMakeLists.txt +++ b/track_analyzing/track_analyzer/CMakeLists.txt @@ -9,7 +9,10 @@ set( cmd_table.cpp cmd_track.cpp cmd_tracks.cpp + cmd_unmatched_tracks.cpp track_analyzer.cpp + utils.cpp + utils.hpp ) omim_add_executable(${PROJECT_NAME} ${SRC}) diff --git a/track_analyzing/track_analyzer/cmd_match.cpp b/track_analyzing/track_analyzer/cmd_match.cpp index 21381582e3..7ce446718c 100644 --- a/track_analyzing/track_analyzer/cmd_match.cpp +++ b/track_analyzing/track_analyzer/cmd_match.cpp @@ -1,19 +1,15 @@ -#include "track_analyzing/log_parser.hpp" #include "track_analyzing/serialization.hpp" #include "track_analyzing/track.hpp" +#include "track_analyzing/track_analyzer/utils.hpp" #include "track_analyzing/track_matcher.hpp" #include "track_analyzing/utils.hpp" #include "routing_common/num_mwm_id.hpp" -#include "storage/country_info_getter.hpp" -#include "storage/routing_helpers.hpp" #include "storage/storage.hpp" #include "platform/platform.hpp" -#include "geometry/tree4d.hpp" - #include "base/logging.hpp" #include "base/timer.hpp" @@ -86,21 +82,10 @@ namespace track_analyzing void CmdMatch(string const & logFile, string const & trackFile) { LOG(LINFO, ("Matching", logFile)); - + shared_ptr numMwmIds; storage::Storage storage; - storage.RegisterAllLocalMaps(false /* enableDiffs */); - shared_ptr numMwmIds = CreateNumMwmIds(storage); - - Platform const & platform = GetPlatform(); - string const dataDir = platform.WritableDir(); - - unique_ptr countryInfoGetter = - storage::CountryInfoReader::CreateCountryInfoReader(platform); - unique_ptr> mwmTree = MakeNumMwmTree(*numMwmIds, *countryInfoGetter); - - LogParser parser(numMwmIds, move(mwmTree), dataDir); MwmToTracks mwmToTracks; - parser.Parse(logFile, mwmToTracks); + ParseTracks(logFile, numMwmIds, storage, mwmToTracks); MwmToMatchedTracks mwmToMatchedTracks; MatchTracks(mwmToTracks, storage, *numMwmIds, mwmToMatchedTracks); diff --git a/track_analyzing/track_analyzer/cmd_table.cpp b/track_analyzing/track_analyzer/cmd_table.cpp index e5dde35b14..07a8a70bf5 100644 --- a/track_analyzing/track_analyzer/cmd_table.cpp +++ b/track_analyzing/track_analyzer/cmd_table.cpp @@ -228,6 +228,11 @@ void CmdTagsTable(string const & filepath, string const & trackExtension, String for (size_t trackIdx = 0; trackIdx < kv.second.size(); ++trackIdx) { MatchedTrack const & track = kv.second[trackIdx]; + // Note. There's no need in tracks with length one point. CalcSpeedKMpH() used below + // requires |timeElapsed| is greater then zero. It's impossible if track length is one. + if (track.size() <= 1) + continue; + uint64_t const start = track.front().GetDataPoint().m_timestamp; uint64_t const timeElapsed = track.back().GetDataPoint().m_timestamp - start; double const length = CalcTrackLength(track, geometry); diff --git a/track_analyzing/track_analyzer/cmd_unmatched_tracks.cpp b/track_analyzing/track_analyzer/cmd_unmatched_tracks.cpp new file mode 100644 index 0000000000..6e90cd4411 --- /dev/null +++ b/track_analyzing/track_analyzer/cmd_unmatched_tracks.cpp @@ -0,0 +1,39 @@ +#include "track_analyzing/track.hpp" +#include "track_analyzing/track_analyzer/utils.hpp" + +#include "routing_common/num_mwm_id.hpp" + +#include "storage/storage.hpp" + +#include "base/logging.hpp" + +#include +#include +#include + +namespace track_analyzing +{ +using namespace routing; +using namespace std; + +void CmdUnmatchedTracks(string const & logFile, string const & trackFileCsv) +{ + LOG(LINFO, ("Saving unmatched tracks", logFile)); + shared_ptr numMwmIds; + storage::Storage storage; + MwmToTracks mwmToTracks; + ParseTracks(logFile, numMwmIds, storage, mwmToTracks); + + ofstream ofs(trackFileCsv, std::ofstream::out); + for (auto const & kv : mwmToTracks) + { + for (auto const & idTrack : kv.second) + { + ofs << numMwmIds->GetFile(kv.first).GetName() << ", " << idTrack.first; + for (auto const & pnt : idTrack.second) + ofs << ", " << pnt.m_latLon.lat << ", " << pnt.m_latLon.lon << ", " << pnt.m_timestamp; + ofs << "\n"; + } + } +} +} // namespace track_analyzing diff --git a/track_analyzing/track_analyzer/track_analyzer.cpp b/track_analyzing/track_analyzer/track_analyzer.cpp index 9b5e149d8e..92f70c3075 100644 --- a/track_analyzing/track_analyzer/track_analyzer.cpp +++ b/track_analyzing/track_analyzer/track_analyzer.cpp @@ -23,7 +23,15 @@ namespace return FLAGS_##name; \ } -DEFINE_string_ext(cmd, "", "command: match, info, cpptrack"); +DEFINE_string_ext(cmd, "", + "command:\n" + "match - based on raw logs gathers points to tracks and matchs them to features\n" + "unmatched_tracks - based on raw logs gathers points to tracks " + "and save tracks to csv. Track points save as lat, log, timestamp in seconds\n" + "tracks - prints track statistics\n" + "track - prints info about single track\n" + "cpptrack - prints track coords to insert them to cpp code\n" + "table - prints csv table based on matched tracks\n"); DEFINE_string_ext(in, "", "input log file name"); DEFINE_string(out, "", "output track file name"); DEFINE_string_ext(mwm, "", "short mwm name"); @@ -66,6 +74,8 @@ void CmdCppTrack(string const & trackFile, string const & mwmName, string const size_t trackIdx); // Match raw gps logs to tracks. void CmdMatch(string const & logFile, string const & trackFile); +// 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); @@ -93,6 +103,11 @@ int main(int argc, char ** argv) string const & logFile = Checked_in(); CmdMatch(logFile, FLAGS_out.empty() ? logFile + ".track" : FLAGS_out); } + else if (cmd == "unmatched_tracks") + { + string const & logFile = Checked_in(); + CmdUnmatchedTracks(logFile, FLAGS_out.empty() ? logFile + ".track.csv" : FLAGS_out); + } else if (cmd == "tracks") { TrackFilter const filter(FLAGS_min_duration, FLAGS_min_length, FLAGS_min_speed, diff --git a/track_analyzing/track_analyzer/utils.cpp b/track_analyzing/track_analyzer/utils.cpp new file mode 100644 index 0000000000..f79d667664 --- /dev/null +++ b/track_analyzing/track_analyzer/utils.cpp @@ -0,0 +1,35 @@ +#include "track_analyzing/track_analyzer/utils.hpp" + +#include "track_analyzing/log_parser.hpp" + +#include "storage/country_info_getter.hpp" +#include "storage/routing_helpers.hpp" + +#include "geometry/tree4d.hpp" + +#include "platform/platform.hpp" + +#include "base/logging.hpp" + +namespace track_analyzing +{ +using namespace routing; +using namespace std; +using namespace storage; + +void ParseTracks(string const & logFile, shared_ptr & numMwmIds, + Storage & storage, MwmToTracks & mwmToTracks) +{ + storage.RegisterAllLocalMaps(false /* enableDiffs */); + numMwmIds = CreateNumMwmIds(storage); + Platform const & platform = GetPlatform(); + string const dataDir = platform.WritableDir(); + unique_ptr countryInfoGetter = + CountryInfoReader::CreateCountryInfoReader(platform); + unique_ptr> mwmTree = MakeNumMwmTree(*numMwmIds, *countryInfoGetter); + + LOG(LINFO, ("Parsing", logFile)); + LogParser parser(numMwmIds, move(mwmTree), dataDir); + parser.Parse(logFile, mwmToTracks); +} +} // namespace track_analyzing diff --git a/track_analyzing/track_analyzer/utils.hpp b/track_analyzing/track_analyzer/utils.hpp new file mode 100644 index 0000000000..7d8a7e6ca0 --- /dev/null +++ b/track_analyzing/track_analyzer/utils.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "storage/storage.hpp" + +#include "routing_common/num_mwm_id.hpp" + +#include "track_analyzing/track.hpp" + +#include +#include +#include + +namespace track_analyzing +{ +/// \brief Parses tracks from |logFile| and fills |numMwmIds|, |storage| and |mwmToTracks|. +void ParseTracks(std::string const & logFile, std::shared_ptr & numMwmIds, + storage::Storage & storage, MwmToTracks & mwmToTracks); +} // namespace track_analyzing