Adding command for saving unmatched tracks in csv in track analyzer.

This commit is contained in:
Vladimir Byko-Ianko 2018-05-28 15:03:51 +03:00 committed by mpimenov
parent b0845659f2
commit 7d1bec2c91
8 changed files with 123 additions and 23 deletions

View file

@ -9,8 +9,8 @@
#include "base/checked_cast.hpp"
#include "std/limits.hpp"
#include "std/vector.hpp"
#include <limits>
#include <string>
namespace coding
{
@ -112,7 +112,7 @@ private:
WriteVarUint(writer, deltaLon);
}
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, numeric_limits<size_t>::max(),
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(),
("Too much data."));
return static_cast<size_t>(writer.Pos() - startPos);
}
@ -153,7 +153,7 @@ private:
WriteVarUint(writer, traffic);
}
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, numeric_limits<size_t>::max(),
ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(),
("Too much data."));
return static_cast<size_t>(writer.Pos() - startPos);
}

View file

@ -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})

View file

@ -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> numMwmIds;
storage::Storage storage;
storage.RegisterAllLocalMaps(false /* enableDiffs */);
shared_ptr<NumMwmIds> numMwmIds = CreateNumMwmIds(storage);
Platform const & platform = GetPlatform();
string const dataDir = platform.WritableDir();
unique_ptr<storage::CountryInfoGetter> countryInfoGetter =
storage::CountryInfoReader::CreateCountryInfoReader(platform);
unique_ptr<m4::Tree<NumMwmId>> 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);

View file

@ -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);

View file

@ -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 <fstream>
#include <memory>
#include <string>
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> 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

View file

@ -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,

View file

@ -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> & numMwmIds,
Storage & storage, MwmToTracks & mwmToTracks)
{
storage.RegisterAllLocalMaps(false /* enableDiffs */);
numMwmIds = CreateNumMwmIds(storage);
Platform const & platform = GetPlatform();
string const dataDir = platform.WritableDir();
unique_ptr<CountryInfoGetter> countryInfoGetter =
CountryInfoReader::CreateCountryInfoReader(platform);
unique_ptr<m4::Tree<NumMwmId>> mwmTree = MakeNumMwmTree(*numMwmIds, *countryInfoGetter);
LOG(LINFO, ("Parsing", logFile));
LogParser parser(numMwmIds, move(mwmTree), dataDir);
parser.Parse(logFile, mwmToTracks);
}
} // namespace track_analyzing

View file

@ -0,0 +1,18 @@
#pragma once
#include "storage/storage.hpp"
#include "routing_common/num_mwm_id.hpp"
#include "track_analyzing/track.hpp"
#include <memory>
#include <string>
#include <track_analyzing/track.hpp>
namespace track_analyzing
{
/// \brief Parses tracks from |logFile| and fills |numMwmIds|, |storage| and |mwmToTracks|.
void ParseTracks(std::string const & logFile, std::shared_ptr<routing::NumMwmIds> & numMwmIds,
storage::Storage & storage, MwmToTracks & mwmToTracks);
} // namespace track_analyzing