Move brewery reverse geocoding from C# seeding to C++ pipeline (#249)

This commit is contained in:
2026-08-25 21:55:34 -04:00
committed by Aaron Po
parent 2b82d1918b
commit ad1c09f139
25 changed files with 377 additions and 185 deletions

View File

@@ -13,10 +13,12 @@ BiergartenPipelineOrchestrator::BiergartenPipelineOrchestrator(
std::unique_ptr<DataGenerator> generator,
std::unique_ptr<IExportService> exporter,
std::unique_ptr<ICuratedDataService> curated_data_service,
std::unique_ptr<IAddressService> address_service,
const ApplicationOptions& application_options)
: logger_(std::move(logger)),
context_service_(std::move(context_service)),
generator_(std::move(generator)),
exporter_(std::move(exporter)),
curated_data_service_(std::move(curated_data_service)),
address_service_(std::move(address_service)),
application_options_(application_options) {}

View File

@@ -7,14 +7,21 @@
#include <format>
#include <optional>
#include <random>
#include <string>
#include <string_view>
#include "biergarten_pipeline_orchestrator.h"
#include "biergarten_pipeline_orchestrator/coords.h"
#include "services/address/address_service.h"
#include "services/logging/logger.h"
using biergarten_pipeline_orchestrator_internal::Coords;
using biergarten_pipeline_orchestrator_internal::GetRandomCoordsWithinRange;
namespace {
constexpr std::string_view kPlaceholderAddressLine1 = "Address unavailable";
} // namespace
void BiergartenPipelineOrchestrator::GenerateBreweries(
std::span<const EnrichedCity> cities) {
logger_->Log({.level = LogLevel::Info,
@@ -39,10 +46,32 @@ void BiergartenPipelineOrchestrator::GenerateBreweries(
const Coords brewery_coords = GetRandomCoordsWithinRange(
city_centre, kMaxDistanceFromCentreKm, rng);
const std::optional<AddressLookupResult> geocoded =
address_service_->ReverseGeocode(brewery_coords.longitude,
brewery_coords.latitude);
if (!geocoded.has_value()) {
logger_->Log(
{.level = LogLevel::Warn,
.phase = PipelinePhase::BreweryAndBeerGeneration,
.message = std::format(
"[Pipeline] Could not reverse geocode brewery in '{}' "
"({}, {}); using a placeholder address.",
enriched_city.location.city, brewery_coords.latitude,
brewery_coords.longitude)});
}
return BreweryRecord{
.address = BreweryAddress{.city = enriched_city.location,
.longitude = brewery_coords.longitude,
.latitude = brewery_coords.latitude},
.address =
BreweryAddress{
.city = enriched_city.location,
.longitude = brewery_coords.longitude,
.latitude = brewery_coords.latitude,
.address_line1 = geocoded.has_value()
? geocoded->address_line1
: std::string(kPlaceholderAddressLine1),
.postal_code =
geocoded.has_value() ? geocoded->postal_code : ""},
.brewery = brewery};
} catch (const std::exception& e) {
++skipped_count;