[generator] proper renamings

This commit is contained in:
LaGrunge 2019-08-08 19:35:14 +03:00 committed by cc-engineering
parent 2b1ccfd5b0
commit 1413bec7e7
7 changed files with 52 additions and 37 deletions

View file

@ -88,8 +88,8 @@ set(
filter_planet.hpp
gen_mwm_info.hpp
generate_info.hpp
geo_objects/geo_object_info_getter.cpp
geo_objects/geo_object_info_getter.hpp
geo_objects/geo_object_maintainer.cpp
geo_objects/geo_object_maintainer.hpp
geo_objects/geo_objects.cpp
geo_objects/geo_objects.hpp
geo_objects/geo_objects_filter.cpp

View file

@ -5,7 +5,7 @@
#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
#include "generator/generator_tests/common.hpp"
#include "generator/geo_objects/geo_object_info_getter.hpp"
#include "generator/geo_objects/geo_object_maintainer.hpp"
#include "generator/geo_objects/geo_objects.hpp"
#include "generator/geo_objects/geo_objects_filter.hpp"
@ -24,7 +24,8 @@ bool CheckWeGotExpectedIdsByPoint(m2::PointD const & point,
std::vector<base::GeoObjectId> reference,
indexer::GeoObjectsIndex<IndexReader> const & index)
{
std::vector<base::GeoObjectId> test = GeoObjectInfoGetter::SearchObjectsInIndex(index, point);
std::vector<base::GeoObjectId> test =
GeoObjectMaintainer::SearchGeoObjectIdsByPoint(index, point);
std::sort(test.begin(), test.end());
std::sort(reference.begin(), reference.end());
return test == reference;

View file

@ -1,4 +1,4 @@
#include "generator/geo_objects/geo_object_info_getter.hpp"
#include "generator/geo_objects/geo_object_maintainer.hpp"
#include <utility>
@ -6,15 +6,15 @@ namespace generator
{
namespace geo_objects
{
GeoObjectInfoGetter::GeoObjectInfoGetter(indexer::GeoObjectsIndex<IndexReader> && index,
GeoObjectMaintainer::GeoObjectMaintainer(indexer::GeoObjectsIndex<IndexReader> && index,
KeyValueStorage const & kvStorage)
: m_index{std::move(index)}, m_storage{kvStorage}
{ }
std::shared_ptr<JsonValue> GeoObjectInfoGetter::Find(
std::shared_ptr<JsonValue> GeoObjectMaintainer::FindFirstMatchedObject(
m2::PointD const & point, std::function<bool(JsonValue const &)> && pred) const
{
auto const ids = SearchObjectsInIndex(m_index, point);
auto const ids = SearchGeoObjectIdsByPoint(m_index, point);
for (auto const & id : ids)
{
auto const object = m_storage.Find(id.GetEncodedId());
@ -28,10 +28,10 @@ std::shared_ptr<JsonValue> GeoObjectInfoGetter::Find(
return {};
}
boost::optional<base::GeoObjectId> GeoObjectInfoGetter::Search(
boost::optional<base::GeoObjectId> GeoObjectMaintainer::SearchIdOfFirstMatchedObject(
m2::PointD const & point, std::function<bool(JsonValue const &)> && pred) const
{
auto const ids = SearchObjectsInIndex(m_index, point);
auto const ids = SearchGeoObjectIdsByPoint(m_index, point);
for (auto const & id : ids)
{
auto const object = m_storage.Find(id.GetEncodedId());
@ -45,7 +45,7 @@ boost::optional<base::GeoObjectId> GeoObjectInfoGetter::Search(
return {};
}
std::vector<base::GeoObjectId> GeoObjectInfoGetter::SearchObjectsInIndex(
std::vector<base::GeoObjectId> GeoObjectMaintainer::SearchGeoObjectIdsByPoint(
indexer::GeoObjectsIndex<IndexReader> const & index, m2::PointD const & point)
{
std::vector<base::GeoObjectId> ids;

View file

@ -23,33 +23,29 @@ namespace generator
{
namespace geo_objects
{
class GeoObjectInfoGetter
class GeoObjectMaintainer
{
public:
using IndexReader = ReaderPtr<Reader>;
GeoObjectInfoGetter(indexer::GeoObjectsIndex<IndexReader> && index,
GeoObjectMaintainer(indexer::GeoObjectsIndex<IndexReader> && index,
KeyValueStorage const & kvStorage);
std::shared_ptr<JsonValue> Find(m2::PointD const & point,
std::function<bool(JsonValue const &)> && pred) const;
std::shared_ptr<JsonValue> FindFirstMatchedObject(
m2::PointD const & point, std::function<bool(JsonValue const &)> && pred) const;
boost::optional<base::GeoObjectId> Search(
boost::optional<base::GeoObjectId> SearchIdOfFirstMatchedObject(
m2::PointD const & point, std::function<bool(JsonValue const &)> && pred) const;
std::vector<base::GeoObjectId> SearchObjectsInIndex(m2::PointD const & point) const
{
return SearchObjectsInIndex(m_index, point);
return SearchGeoObjectIdsByPoint(m_index, point);
}
static std::vector<base::GeoObjectId> SearchObjectsInIndex(
static std::vector<base::GeoObjectId> SearchGeoObjectIdsByPoint(
indexer::GeoObjectsIndex<IndexReader> const & index, m2::PointD const & point);
KeyValueStorage const & GetKeyValueStorage() const
{
return m_storage;
}
private:
indexer::GeoObjectsIndex<IndexReader> m_index;
KeyValueStorage const & m_storage;

View file

@ -2,7 +2,7 @@
#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
#include "generator/geo_objects/geo_object_info_getter.hpp"
#include "generator/geo_objects/geo_object_maintainer.hpp"
#include "generator/geo_objects/geo_objects_filter.hpp"
#include "generator/key_value_storage.hpp"
#include "generator/locality_sorter.hpp"
@ -117,7 +117,7 @@ struct NullBuildingsInfo
std::unordered_map<base::GeoObjectId, base::GeoObjectId> m_Buildings2AddressPoint;
};
NullBuildingsInfo GetHelpfulNullBuildings(GeoObjectInfoGetter const & geoObjectInfoGetter,
NullBuildingsInfo GetHelpfulNullBuildings(GeoObjectMaintainer const & geoObjectMaintainer,
std::string const & pathInGeoObjectsTmpMwm,
size_t threadsCount)
{
@ -128,7 +128,10 @@ NullBuildingsInfo GetHelpfulNullBuildings(GeoObjectInfoGetter const & geoObjectI
if (!GeoObjectsFilter::HasHouse(fb) || !fb.IsPoint())
return;
auto const buildingId = geoObjectInfoGetter.Search(
// Можно искать не нуллбилдинги в кв, а те айдишгики, которых нет в кв, которое построено без нуллбилдингов.
auto const buildingId = geoObjectMaintainer.SearchIdOfFirstMatchedObject(
fb.GetKeyPoint(), [](JsonValue const & json) { return !JsonHasBuilding(json); });
if (!buildingId)
return;
@ -232,11 +235,11 @@ size_t AddBuildingGeometriesToAddressPoints(std::string const & pathInGeoObjects
}
NullBuildingsInfo EnrichPointsWithOuterBuildingGeometry(
GeoObjectInfoGetter const & geoObjectInfoGetter, std::string const & pathInGeoObjectsTmpMwm,
GeoObjectMaintainer const & geoObjectMaintainer, std::string const & pathInGeoObjectsTmpMwm,
size_t threadsCount)
{
auto const buildingInfo =
GetHelpfulNullBuildings(geoObjectInfoGetter, pathInGeoObjectsTmpMwm, threadsCount);
GetHelpfulNullBuildings(geoObjectMaintainer, pathInGeoObjectsTmpMwm, threadsCount);
LOG(LINFO, ("Found", buildingInfo.m_addressPoints2Buildings.size(),
"address points with outer building geometry"));
@ -296,21 +299,22 @@ boost::optional<indexer::GeoObjectsIndex<IndexReader>> MakeTempGeoObjectsIndex(
}
std::shared_ptr<JsonValue> FindHousePoi(FeatureBuilder const & fb,
GeoObjectInfoGetter const & geoObjectInfoGetter,
GeoObjectMaintainer const & geoObjectMaintainer,
NullBuildingsInfo const & buildingsInfo)
{
std::shared_ptr<JsonValue> house = geoObjectInfoGetter.Find(fb.GetKeyPoint(), JsonHasBuilding);
std::shared_ptr<JsonValue> house =
geoObjectMaintainer.FindFirstMatchedObject(fb.GetKeyPoint(), JsonHasBuilding);
if (house)
return house;
std::vector<base::GeoObjectId> potentialIds =
geoObjectInfoGetter.SearchObjectsInIndex(fb.GetKeyPoint());
geoObjectMaintainer.SearchObjectsInIndex(fb.GetKeyPoint());
for (base::GeoObjectId id : potentialIds)
{
auto const it = buildingsInfo.m_Buildings2AddressPoint.find(id);
if (it != buildingsInfo.m_Buildings2AddressPoint.end())
return geoObjectInfoGetter.GetKeyValueStorage().Find(it->second.GetEncodedId());
// if (it != buildingsInfo.m_Buildings2AddressPoint.end())
// return geoObjectMaintainer.GetKeyValueStorage().Find(it->second.GetEncodedId());
}
return {};
@ -329,7 +333,7 @@ base::JSONPtr MakeJsonValueWithNameFromFeature(FeatureBuilder const & fb, JsonVa
}
void AddPoisEnrichedWithHouseAddresses(KeyValueStorage & geoObjectsKv,
GeoObjectInfoGetter const & geoObjectInfoGetter,
GeoObjectMaintainer const & geoObjectMaintainer,
NullBuildingsInfo const & buildingsInfo,
std::string const & pathInGeoObjectsTmpMwm,
std::ostream & streamPoiIdsToAddToLocalityIndex,
@ -344,7 +348,7 @@ void AddPoisEnrichedWithHouseAddresses(KeyValueStorage & geoObjectsKv,
if (GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb))
return;
auto const house = FindHousePoi(fb, geoObjectInfoGetter, buildingsInfo);
auto const house = FindHousePoi(fb, geoObjectMaintainer, buildingsInfo);
if (!house)
return;
@ -439,16 +443,16 @@ bool GeoObjectsGenerator::GenerateGeoObjectsPrivate()
if (!geoObjectIndex)
return false;
GeoObjectInfoGetter const geoObjectInfoGetter{std::move(*geoObjectIndex), m_geoObjectsKv};
GeoObjectMaintainer const geoObjectMaintainer{std::move(*geoObjectIndex), m_geoObjectsKv};
LOG(LINFO, ("Enrich address points with outer null building geometry."));
NullBuildingsInfo const & buildingInfo = EnrichPointsWithOuterBuildingGeometry(
geoObjectInfoGetter, m_pathInGeoObjectsTmpMwm, m_threadsCount);
geoObjectMaintainer, m_pathInGeoObjectsTmpMwm, m_threadsCount);
std::ofstream streamPoiIdsToAddToLocalityIndex(m_pathOutPoiIdsToAddToLocalityIndex);
AddPoisEnrichedWithHouseAddresses(m_geoObjectsKv, geoObjectInfoGetter, buildingInfo,
AddPoisEnrichedWithHouseAddresses(m_geoObjectsKv, geoObjectMaintainer, buildingInfo,
m_pathInGeoObjectsTmpMwm, streamPoiIdsToAddToLocalityIndex,
m_verbose, m_threadsCount);

View file

@ -77,6 +77,17 @@ bool KeyValueStorage::ParseKeyValueLine(std::string const & line, std::streamoff
return true;
}
// static
std::string KeyValueStorage::SerializeFullLine(uint64_t key, JsonValue && value)
{
auto json = Serialize(value);
CHECK(!json.empty(), ());
std::stringstream result;
result << SerializeDref(key) << " " << json << "\n";
return result.str();
}
void KeyValueStorage::Insert(uint64_t key, JsonValue && value)
{
auto json = Serialize(value);

View file

@ -54,6 +54,9 @@ public:
KeyValueStorage & operator=(KeyValueStorage const &) = delete;
void Insert(uint64_t key, JsonValue && valueJson);
static std::string SerializeFullLine(uint64_t key, JsonValue && valueJson);
std::shared_ptr<JsonValue> Find(uint64_t key) const;
size_t Size() const;