review fixes

This commit is contained in:
Lev Dragunov 2019-01-22 18:54:43 +03:00
parent 41d9aeb5b5
commit 65acbae808
13 changed files with 32 additions and 37 deletions

View File

@ -91,7 +91,7 @@ Every response object has a `code` property containing one of the strings below
#### Data version #### Data version
Every response object has a `data_version` propetry containing timestamp from the original OpenStreetMap file. May be `n/a` if original OSM file has not `osmosis_replication_timestamp` section. Every response object has a `data_version` propetry containing timestamp from the original OpenStreetMap file. This field is optional. It can be ommited if data_version parametr was not set on osrm-extract stage or OSM file has not `osmosis_replication_timestamp` section.
#### Example response #### Example response

View File

@ -68,7 +68,11 @@ class RouteAPI : public BaseAPI
response.values["waypoints"] = BaseAPI::MakeWaypoints(all_start_end_points); response.values["waypoints"] = BaseAPI::MakeWaypoints(all_start_end_points);
response.values["routes"] = std::move(jsRoutes); response.values["routes"] = std::move(jsRoutes);
response.values["code"] = "Ok"; response.values["code"] = "Ok";
response.values["data_version"] = facade.GetTimestamp(); auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty())
{
response.values["data_version"] = facade.GetTimestamp();
}
} }
protected: protected:

View File

@ -137,7 +137,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
extractor::Datasources *m_datasources; extractor::Datasources *m_datasources;
std::uint32_t m_check_sum; std::uint32_t m_check_sum;
DataTimestamp m_data_timestamp; StringView m_data_timestamp;
util::vector_view<util::Coordinate> m_coordinate_list; util::vector_view<util::Coordinate> m_coordinate_list;
extractor::PackedOSMIDsView m_osmnodeid_list; extractor::PackedOSMIDsView m_osmnodeid_list;
util::vector_view<std::uint32_t> m_lane_description_offsets; util::vector_view<std::uint32_t> m_lane_description_offsets;
@ -184,7 +184,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
m_check_sum = *index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum"); m_check_sum = *index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum");
m_data_timestamp = *index.GetBlockPtr<DataTimestamp>("/common/timestamp"); m_data_timestamp = make_timestamp_view(index, "/common/timestamp");
std::tie(m_coordinate_list, m_osmnodeid_list) = std::tie(m_coordinate_list, m_osmnodeid_list) =
make_nbn_data_view(index, "/common/nbn_data"); make_nbn_data_view(index, "/common/nbn_data");
@ -437,14 +437,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
std::string GetTimestamp() const override final std::string GetTimestamp() const override final
{ {
if (!m_data_timestamp) return std::string(m_data_timestamp.begin(), m_data_timestamp.end());
{
return "n/a";
}
time_t ts(m_data_timestamp);
char buf[21]; // sizeof "2019-01-01T01:01:01Z\n"];
strftime(buf, 21, "%FT%TZ", gmtime(&ts));
return std::string(buf, 20);
} }
GeometryID GetGeometryIndex(const NodeID id) const override final GeometryID GetGeometryIndex(const NodeID id) const override final

View File

@ -83,6 +83,7 @@ struct ExtractorConfig final : storage::IOConfig
boost::filesystem::path input_path; boost::filesystem::path input_path;
boost::filesystem::path profile_path; boost::filesystem::path profile_path;
std::vector<boost::filesystem::path> location_dependent_data_paths; std::vector<boost::filesystem::path> location_dependent_data_paths;
std::string data_version;
unsigned requested_num_threads; unsigned requested_num_threads;
unsigned small_component_size; unsigned small_component_size;

View File

@ -201,18 +201,6 @@ inline void read(tar::FileReader &reader, const std::string &name, std::string &
reader.ReadInto(name, const_cast<char *>(data.data()), count); reader.ReadInto(name, const_cast<char *>(data.data()), count);
} }
inline void write(tar::FileWriter &writer, const std::string &name, const std::uint64_t &data)
{
writer.WriteElementCount64(name, data);
writer.WriteFrom(name, &data, 1);
}
inline void read(tar::FileReader &reader, const std::string &name, std::uint64_t &data)
{
data = reader.ReadElementCount64(name);
reader.ReadInto(name, &data, 1);
}
template <typename T> template <typename T>
inline void read(tar::FileReader &reader, const std::string &name, std::vector<T> &data) inline void read(tar::FileReader &reader, const std::string &name, std::vector<T> &data)
{ {

View File

@ -274,7 +274,7 @@ inline auto make_partition_view(const SharedDataIndex &index, const std::string
inline auto make_timestamp_view(const SharedDataIndex &index, const std::string &name) inline auto make_timestamp_view(const SharedDataIndex &index, const std::string &name)
{ {
return index.template GetBlockPtr<DataTimestamp>(name); return util::StringView(index.GetBlockPtr<char>(name), index.GetBlockEntries(name));
} }
inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name) inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name)

View File

@ -79,7 +79,7 @@ using EdgeDistance = float;
using SegmentWeight = std::uint32_t; using SegmentWeight = std::uint32_t;
using SegmentDuration = std::uint32_t; using SegmentDuration = std::uint32_t;
using TurnPenalty = std::int16_t; // turn penalty in 100ms units using TurnPenalty = std::int16_t; // turn penalty in 100ms units
using DataTimestamp = std::uint64_t; using DataTimestamp = std::string;
static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max(); static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();

View File

@ -426,17 +426,19 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
// write .timestamp data file // write .timestamp data file
std::string timestamp = header.get("osmosis_replication_timestamp"); std::string timestamp = header.get("osmosis_replication_timestamp");
osmium::Timestamp ts; if (config.data_version == "osmosis")
{
files::writeTimestamp(config.GetPath(".osrm.timestamp").string(), timestamp);
}
else
{
files::writeTimestamp(config.GetPath(".osrm.timestamp").string(), config.data_version);
}
if (timestamp.empty()) if (timestamp.empty())
{ {
timestamp = "n/a"; timestamp = "n/a";
} }
else
{
ts = osmium::Timestamp(timestamp);
}
util::Log() << "timestamp: " << timestamp; util::Log() << "timestamp: " << timestamp;
files::writeTimestamp(config.GetPath(".osrm.timestamp").string(), DataTimestamp(ts));
} }
// Extraction containers and restriction parser // Extraction containers and restriction parser

View File

@ -404,8 +404,12 @@ void Storage::PopulateStaticData(const SharedDataIndex &index)
// Timestamp mark // Timestamp mark
{ {
auto timestamp = make_timestamp_view(index, "/common/timestamp"); auto timestamp_ref = make_timestamp_view(index, "/common/timestamp");
extractor::files::readTimestamp(config.GetPath(".osrm.timestamp"), *timestamp); std::string ts;
extractor::files::readTimestamp(config.GetPath(".osrm.timestamp"), ts);
if (!ts.empty()) {
memcpy(const_cast<char *>(timestamp_ref.data()), ts.data(), ts.size());
}
} }
// Turn lane data // Turn lane data

View File

@ -43,6 +43,10 @@ return_code parseArguments(int argc,
boost::program_options::value<boost::filesystem::path>(&extractor_config.profile_path) boost::program_options::value<boost::filesystem::path>(&extractor_config.profile_path)
->default_value("profiles/car.lua"), ->default_value("profiles/car.lua"),
"Path to LUA routing profile")( "Path to LUA routing profile")(
"data_version,d",
boost::program_options::value<std::string>(&extractor_config.data_version)
->default_value(""),
"Data version. Leave blank to avoid. osmosis - to get timestamp from file")(
"threads,t", "threads,t",
boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads) boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()), ->default_value(tbb::task_scheduler_init::default_num_threads()),

View File

@ -341,7 +341,7 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
StringView GetDestinationsForID(const NameID /*id*/) const override { return StringView{}; } StringView GetDestinationsForID(const NameID /*id*/) const override { return StringView{}; }
StringView GetExitsForID(const NameID /*id*/) const override { return StringView{}; } StringView GetExitsForID(const NameID /*id*/) const override { return StringView{}; }
bool GetContinueStraightDefault() const override { return false; } bool GetContinueStraightDefault() const override { return false; }
std::string GetTimestamp() const override { return "n/a"; } std::string GetTimestamp() const override { return ""; }
double GetMapMatchingMaxSpeed() const override { return 0; } double GetMapMatchingMaxSpeed() const override { return 0; }
const char *GetWeightName() const override { return ""; } const char *GetWeightName() const override { return ""; }
unsigned GetWeightPrecision() const override { return 0; } unsigned GetWeightPrecision() const override { return 0; }

View File

@ -47,7 +47,6 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
json::Object reference{ json::Object reference{
{{"code", "Ok"}, {{"code", "Ok"},
{"data_version", "2016-03-05T00:26:02Z"},
{"waypoints", {"waypoints",
json::Array{{json::Object{{{"name", "Boulevard du Larvotto"}, json::Array{{json::Object{{{"name", "Boulevard du Larvotto"},
{"location", location}, {"location", location},

View File

@ -53,7 +53,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
{ {
return 0; return 0;
} }
std::string GetTimestamp() const override { return "n/a"; } std::string GetTimestamp() const override { return ""; }
NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /* id */) const override NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /* id */) const override
{ {
static NodeID data[] = {0, 1, 2, 3}; static NodeID data[] = {0, 1, 2, 3};