mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Assign external URI for Kayak hotels.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
e7c04c5459
commit
6368ba477f
@@ -1,6 +1,7 @@
|
||||
#include "generator/kayak_dataset.hpp"
|
||||
|
||||
#include "generator/feature_builder.hpp"
|
||||
#include "generator/sponsored_dataset_inl.hpp"
|
||||
|
||||
#include "indexer/ftypes_matcher.hpp"
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace generator
|
||||
{
|
||||
using namespace feature;
|
||||
|
||||
// BookingHotel ------------------------------------------------------------------------------------
|
||||
// KayakHotel ------------------------------------------------------------------------------------
|
||||
KayakHotel::KayakHotel(std::string src)
|
||||
{
|
||||
using namespace strings;
|
||||
@@ -23,7 +24,7 @@ KayakHotel::KayakHotel(std::string src)
|
||||
|
||||
/// @todo For fast parsing we can preprocess src (quotes) and return string_view's.
|
||||
std::vector<std::string> rec;
|
||||
strings::ParseCSVRow(src, ',', rec);
|
||||
ParseCSVRow(src, ',', rec);
|
||||
|
||||
// Skip bad entries and header.
|
||||
if (rec.size() != Fields::Counter || rec[0] == "ChainID")
|
||||
@@ -31,7 +32,8 @@ KayakHotel::KayakHotel(std::string src)
|
||||
|
||||
// Assign id in the end in case of possible errors.
|
||||
uint32_t id;
|
||||
CLOG(LDEBUG, to_uint(rec[Fields::KayakHotelID], id), ()); /// @todo HotelID ?
|
||||
CLOG(LDEBUG, to_uint(rec[Fields::KayakHotelID], id), ());
|
||||
CLOG(LDEBUG, to_uint(rec[Fields::PlaceID], m_placeID), ());
|
||||
CLOG(LDEBUG, to_double(rec[Fields::Latitude], m_latLon.m_lat), (rec[Fields::Latitude]));
|
||||
CLOG(LDEBUG, to_double(rec[Fields::Longitude], m_latLon.m_lon), (rec[Fields::Longitude]));
|
||||
|
||||
@@ -44,10 +46,49 @@ KayakHotel::KayakHotel(std::string src)
|
||||
m_id.Set(id);
|
||||
}
|
||||
|
||||
// KayakPlace ----------------------------------------------------------------------------------
|
||||
KayakPlace::KayakPlace(std::string src)
|
||||
{
|
||||
using namespace strings;
|
||||
|
||||
std::vector<std::string> rec;
|
||||
ParseCSVRow(src, ',', rec);
|
||||
|
||||
if (rec.size() != Fields::Counter || rec[0] == "CountryCode")
|
||||
return;
|
||||
|
||||
m_good = to_uint(rec[Fields::PlaceID], m_placeID) &&
|
||||
to_uint(rec[Fields::KayakCityID], m_kayakCityID);
|
||||
}
|
||||
|
||||
std::string DebugPrint(KayakPlace const & p)
|
||||
{
|
||||
return std::to_string(p.m_placeID) + "; " + std::to_string(p.m_kayakCityID);
|
||||
}
|
||||
|
||||
// KayakDataset ----------------------------------------------------------------------------------
|
||||
KayakDataset::KayakDataset(std::string const & hotelsPath, std::string const & placesPath)
|
||||
: BaseDatasetT(hotelsPath)
|
||||
{
|
||||
std::ifstream source(placesPath);
|
||||
if (!source)
|
||||
{
|
||||
LOG(LERROR, ("Error while opening", placesPath, ":", strerror(errno)));
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::string line; std::getline(source, line);)
|
||||
{
|
||||
KayakPlace place(std::move(line));
|
||||
line.clear();
|
||||
|
||||
if (place.m_good)
|
||||
CLOG(LDEBUG, m_place2kayak.emplace(place.m_placeID, place.m_kayakCityID).second, (place));
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
bool KayakDataset::IsSponsoredCandidate(FeatureBuilder const & fb) const
|
||||
bool BaseDatasetT::IsSponsoredCandidate(FeatureBuilder const & fb) const
|
||||
{
|
||||
if (fb.GetName(StringUtf8Multilang::kDefaultCode).empty())
|
||||
return false;
|
||||
@@ -56,17 +97,26 @@ bool KayakDataset::IsSponsoredCandidate(FeatureBuilder const & fb) const
|
||||
}
|
||||
|
||||
template <>
|
||||
void KayakDataset::PreprocessMatchedOsmObject(ObjectId id, FeatureBuilder & fb, FBuilderFnT const fn) const
|
||||
void BaseDatasetT::PreprocessMatchedOsmObject(ObjectId id, FeatureBuilder & fb, FBuilderFnT const fn) const
|
||||
{
|
||||
auto const & hotel = m_storage.GetObjectById(id);
|
||||
|
||||
fb.SetHotelInfo(Metadata::SRC_KAYAK, hotel.m_id.Get(), hotel.m_overallRating, 0 /* priceCategory */);
|
||||
// Only hack like this ..
|
||||
KayakDataset const & kds = static_cast<KayakDataset const &>(*this);
|
||||
uint32_t const cityID = kds.GetKayakCityID(hotel.m_placeID);
|
||||
if (cityID)
|
||||
{
|
||||
std::string uri = hotel.m_name + ",-c" + std::to_string(cityID) + "-h" + std::to_string(hotel.m_id.Get());
|
||||
fb.SetHotelInfo(std::move(uri), hotel.m_overallRating);
|
||||
}
|
||||
else
|
||||
LOG(LWARNING, ("Unknown PlaceID", hotel.m_placeID));
|
||||
|
||||
fn(fb);
|
||||
}
|
||||
|
||||
template <>
|
||||
void KayakDataset::BuildObject(Object const &, FBuilderFnT const &) const
|
||||
void BaseDatasetT::BuildObject(Object const &, FBuilderFnT const &) const
|
||||
{
|
||||
// Don't create new objects.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user