mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
Style audit: update code to strictly follow Google Style Guide
This commit is contained in:
@@ -1,17 +1,37 @@
|
|||||||
---
|
|
||||||
Checks: >
|
Checks: >
|
||||||
-*,
|
-*,
|
||||||
bugprone-*,
|
bugprone-*,
|
||||||
clang-analyzer-*,
|
|
||||||
cppcoreguidelines-*,
|
|
||||||
google-*,
|
google-*,
|
||||||
modernize-*,
|
modernize-*,
|
||||||
performance-*,
|
|
||||||
readability-*,
|
readability-*,
|
||||||
-cppcoreguidelines-avoid-magic-numbers,
|
cppcoreguidelines-*,
|
||||||
-cppcoreguidelines-owning-memory,
|
-modernize-use-trailing-return-type,
|
||||||
-readability-magic-numbers,
|
-google-runtime-references
|
||||||
-google-readability-todo
|
|
||||||
HeaderFilterRegex: "^(src|includes)/.*"
|
CheckOptions:
|
||||||
FormatStyle: file
|
# Enforce Google Naming Conventions
|
||||||
...
|
- key: readability-identifier-naming.ClassMemberCase
|
||||||
|
value: snake_case
|
||||||
|
- key: readability-identifier-naming.ClassMemberSuffix
|
||||||
|
value: _
|
||||||
|
- key: readability-identifier-naming.ClassCase
|
||||||
|
value: PascalCase
|
||||||
|
- key: readability-identifier-naming.FunctionCase
|
||||||
|
value: PascalCase
|
||||||
|
- key: readability-identifier-naming.StructCase
|
||||||
|
value: PascalCase
|
||||||
|
- key: readability-identifier-naming.VariableCase
|
||||||
|
value: snake_case
|
||||||
|
- key: readability-identifier-naming.GlobalConstantCase
|
||||||
|
value: kPascalCase
|
||||||
|
|
||||||
|
# Ensure C++20 Modernization
|
||||||
|
- key: modernize-make-unique.MakeSmartPtrFunction
|
||||||
|
value: std::make_unique
|
||||||
|
- key: modernize-make-shared.MakeSmartPtrFunction
|
||||||
|
value: std::make_shared
|
||||||
|
- key: modernize-use-override.IgnoreDestructors
|
||||||
|
value: "false"
|
||||||
|
|
||||||
|
# Warnings as Errors to ensure compliance during build
|
||||||
|
WarningsAsErrors: "*"
|
||||||
|
|||||||
@@ -4,78 +4,76 @@ project(biergarten-pipeline)
|
|||||||
# Boost.DI still declares a very old minimum CMake version, which newer CMake
|
# Boost.DI still declares a very old minimum CMake version, which newer CMake
|
||||||
# releases reject unless a policy version floor is provided.
|
# releases reject unless a policy version floor is provided.
|
||||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)
|
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 1. GPU Detection
|
# 1. Platform & GPU Detection (Windows explicitly NOT supported)
|
||||||
# =============================================================================
|
|
||||||
# GGML_CUDA / GGML_METAL are set here so that the llama.cpp FetchContent below
|
|
||||||
# inherits them as cache variables before its CMakeLists.txt is processed.
|
|
||||||
# =============================================================================
|
|
||||||
# 1. Platform & GPU Detection
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
if(WIN32)
|
||||||
|
message(FATAL_ERROR "[biergarten] Windows is currently not supported. Please use Linux (Fedora 43) or macOS (M1 Pro).")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# Check if this is an M-series Mac (arm64) or Intel Mac (x86_64)
|
|
||||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
|
||||||
message(STATUS "[biergarten] Apple Silicon detected — enabling Metal acceleration.")
|
message(STATUS "[biergarten] Apple Silicon detected — enabling Metal acceleration.")
|
||||||
set(GGML_METAL ON CACHE BOOL "Enable Metal for Apple Silicon" FORCE)
|
set(GGML_METAL ON CACHE BOOL "Enable Metal for Apple Silicon" FORCE)
|
||||||
else()
|
else()
|
||||||
message(STATUS "[biergarten] Intel Mac detected — using CPU / Accelerate framework.")
|
message(STATUS "[biergarten] Intel Mac detected — using CPU / Accelerate framework.")
|
||||||
# Explicitly turn off Metal so the build doesn't fail on x86_64
|
|
||||||
set(GGML_METAL OFF CACHE BOOL "Disable Metal for Intel Macs" FORCE)
|
set(GGML_METAL OFF CACHE BOOL "Disable Metal for Intel Macs" FORCE)
|
||||||
# Note: llama.cpp will automatically detect and enable Apple's Accelerate framework here
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
elseif(UNIX AND NOT APPLE)
|
elseif(UNIX AND NOT APPLE)
|
||||||
# Search for NVIDIA CUDA Toolkit
|
|
||||||
find_package(CUDAToolkit QUIET)
|
find_package(CUDAToolkit QUIET)
|
||||||
|
|
||||||
# Search for AMD HIP/ROCm Toolkit
|
|
||||||
find_package(HIP QUIET)
|
find_package(HIP QUIET)
|
||||||
|
|
||||||
if(CUDAToolkit_FOUND)
|
if(CUDAToolkit_FOUND)
|
||||||
message(STATUS "[biergarten] NVIDIA GPU detected — enabling CUDA acceleration.")
|
message(STATUS "[biergarten] NVIDIA GPU detected — enabling CUDA acceleration.")
|
||||||
set(GGML_CUDA ON CACHE BOOL "Enable CUDA for NVIDIA GPUs" FORCE)
|
set(GGML_CUDA ON CACHE BOOL "Enable CUDA for NVIDIA GPUs" FORCE)
|
||||||
set(CMAKE_CUDA_ARCHITECTURES native)
|
set(CMAKE_CUDA_ARCHITECTURES native)
|
||||||
|
|
||||||
elseif(HIP_FOUND OR EXISTS "/opt/rocm")
|
elseif(HIP_FOUND OR EXISTS "/opt/rocm")
|
||||||
message(STATUS "[biergarten] AMD GPU detected — enabling HIP/ROCm acceleration.")
|
message(STATUS "[biergarten] AMD GPU detected — enabling HIP/ROCm acceleration.")
|
||||||
set(GGML_HIPBLAS ON CACHE BOOL "Enable HIP for AMD GPUs" FORCE)
|
set(GGML_HIPBLAS ON CACHE BOOL "Enable HIP for AMD GPUs" FORCE)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
message(STATUS "[biergarten] No NVIDIA or AMD GPU found — falling back to CPU.")
|
message(STATUS "[biergarten] No NVIDIA or AMD GPU found — falling back to CPU.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "[biergarten] Unrecognized platform. Windows is currently not supported.")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 2. Project-wide Settings
|
# 2. Project-wide Settings (Standard & Optimization)
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
|
||||||
|
# Downgrade to C++20 as per Google Style Guide
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# GCC/Clang specific settings (warnings as errors)
|
||||||
|
add_compile_options(-Wall -Wextra -Werror -Wpedantic)
|
||||||
|
|
||||||
|
# Release Build Optimization: Aggressive (-O3), Arch-specific, and LTO
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -flto")
|
||||||
|
|
||||||
|
# Debug Build Optimization: Fast and debuggable (-Og)
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g")
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 3. Dependencies
|
# 3. Dependencies
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
# --- libcurl ------------------------------------------------------------------
|
|
||||||
# Prefer the system package; the build will fail at link time if absent and
|
|
||||||
# no system curl is found, so emit a fatal error early rather than a silent gap.
|
|
||||||
find_package(CURL QUIET)
|
find_package(CURL QUIET)
|
||||||
if(NOT CURL_FOUND)
|
if(NOT CURL_FOUND)
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR "[biergarten] libcurl not found. Install it (e.g. 'sudo dnf install libcurl-devel').")
|
||||||
"[biergarten] libcurl not found. Install it via your package manager "
|
|
||||||
"(e.g. 'sudo dnf install libcurl-devel') or set CURL_ROOT.")
|
|
||||||
endif()
|
endif()
|
||||||
# --- llama.cpp ----------------------------------------------------------------
|
|
||||||
|
# Require system Boost for JSON and Program Options to speed up build times
|
||||||
|
find_package(Boost REQUIRED COMPONENTS json program_options)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
llama-cpp
|
llama-cpp
|
||||||
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
|
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
|
||||||
GIT_TAG b8739
|
GIT_TAG b8739
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(llama-cpp)
|
FetchContent_MakeAvailable(llama-cpp)
|
||||||
# --- boost-ext/di -------------------------------------------------------------
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
boost-di
|
boost-di
|
||||||
GIT_REPOSITORY https://github.com/boost-ext/di.git
|
GIT_REPOSITORY https://github.com/boost-ext/di.git
|
||||||
@@ -85,42 +83,33 @@ FetchContent_MakeAvailable(boost-di)
|
|||||||
if(TARGET Boost.DI AND NOT TARGET boost::di)
|
if(TARGET Boost.DI AND NOT TARGET boost::di)
|
||||||
add_library(boost::di ALIAS Boost.DI)
|
add_library(boost::di ALIAS Boost.DI)
|
||||||
endif()
|
endif()
|
||||||
# --- Boost (JSON + program_options) ------------------------------------------
|
|
||||||
FetchContent_Declare(
|
|
||||||
boost
|
|
||||||
URL https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.gz
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(boost)
|
|
||||||
# --- spdlog -------------------------------------------------------------------
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
spdlog
|
spdlog
|
||||||
GIT_REPOSITORY https://github.com/gabime/spdlog.git
|
GIT_REPOSITORY https://github.com/gabime/spdlog.git
|
||||||
GIT_TAG v1.15.3
|
GIT_TAG v1.15.3
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(spdlog)
|
FetchContent_MakeAvailable(spdlog)
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 4. Sources
|
# 4. Sources
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
# BiergartenDataGenerator methods
|
|
||||||
src/biergarten_data_generator/biergarten_data_generator.cpp
|
src/biergarten_data_generator/biergarten_data_generator.cpp
|
||||||
src/biergarten_data_generator/run.cpp
|
src/biergarten_data_generator/run.cpp
|
||||||
src/biergarten_data_generator/query_cities_with_countries.cpp
|
src/biergarten_data_generator/query_cities_with_countries.cpp
|
||||||
src/biergarten_data_generator/generate_breweries.cpp
|
src/biergarten_data_generator/generate_breweries.cpp
|
||||||
src/biergarten_data_generator/log_results.cpp
|
src/biergarten_data_generator/log_results.cpp
|
||||||
# WikipediaService methods
|
|
||||||
src/services/wikipedia/wikipedia_service.cpp
|
src/services/wikipedia/wikipedia_service.cpp
|
||||||
src/services/wikipedia/get_summary.cpp
|
src/services/wikipedia/get_summary.cpp
|
||||||
src/services/wikipedia/fetch_extract.cpp
|
src/services/wikipedia/fetch_extract.cpp
|
||||||
# CURLWebClient and CurlGlobalState methods
|
|
||||||
src/web_client/curl_global_state.cpp
|
src/web_client/curl_global_state.cpp
|
||||||
src/web_client/curl_web_client.cpp
|
src/web_client/curl_web_client.cpp
|
||||||
src/web_client/curl_web_client_download_to_file.cpp
|
src/web_client/curl_web_client_download_to_file.cpp
|
||||||
src/web_client/curl_web_client_get.cpp
|
src/web_client/curl_web_client_get.cpp
|
||||||
src/web_client/curl_web_client_utils.cpp
|
src/web_client/curl_web_client_utils.cpp
|
||||||
src/web_client/curl_web_client_url_encode.cpp
|
src/web_client/curl_web_client_url_encode.cpp
|
||||||
# Data generation modules
|
|
||||||
src/data_generation/llama/llama_generator.cpp
|
src/data_generation/llama/llama_generator.cpp
|
||||||
src/data_generation/llama/generate_brewery.cpp
|
src/data_generation/llama/generate_brewery.cpp
|
||||||
src/data_generation/llama/generate_user.cpp
|
src/data_generation/llama/generate_user.cpp
|
||||||
@@ -134,12 +123,11 @@ set(SOURCES
|
|||||||
src/data_generation/mock/generate_user.cpp
|
src/data_generation/mock/generate_user.cpp
|
||||||
src/json_handling/json_loader.cpp
|
src/json_handling/json_loader.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 5. Target
|
# 5. Target
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
${SOURCES}
|
|
||||||
)
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
includes
|
includes
|
||||||
${llama-cpp_SOURCE_DIR}/include
|
${llama-cpp_SOURCE_DIR}/include
|
||||||
@@ -148,8 +136,8 @@ target_include_directories(${PROJECT_NAME} PRIVATE
|
|||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
llama
|
llama
|
||||||
boost::di
|
boost::di
|
||||||
boost_json
|
Boost::json
|
||||||
boost_program_options
|
Boost::program_options
|
||||||
spdlog::spdlog
|
spdlog::spdlog
|
||||||
CURL::libcurl
|
CURL::libcurl
|
||||||
)
|
)
|
||||||
@@ -157,8 +145,6 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
|||||||
# =============================================================================
|
# =============================================================================
|
||||||
# 6. Runtime Assets
|
# 6. Runtime Assets
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Make locations.json available in the build directory for runtime relative path
|
|
||||||
# lookups (e.g. when running from ./build).
|
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_SOURCE_DIR}/locations.json
|
${CMAKE_SOURCE_DIR}/locations.json
|
||||||
${CMAKE_BINARY_DIR}/locations.json
|
${CMAKE_BINARY_DIR}/locations.json
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_BIERGARTEN_DATA_GENERATOR_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_BIERGARTEN_DATA_GENERATOR_H_
|
||||||
#define BIERGARTEN_PIPELINE_BIERGARTEN_DATA_GENERATOR_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_BIERGARTEN_DATA_GENERATOR_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file biergarten_data_generator.h
|
* @file biergarten_data_generator.h
|
||||||
@@ -117,6 +117,6 @@ class BiergartenDataGenerator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores generated brewery data.
|
/// @brief Stores generated brewery data.
|
||||||
std::vector<GeneratedBrewery> generatedBreweries_;
|
std::vector<GeneratedBrewery> generated_breweries_;
|
||||||
};
|
};
|
||||||
#endif // BIERGARTEN_PIPELINE_BIERGARTEN_DATA_GENERATOR_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_BIERGARTEN_DATA_GENERATOR_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_DATA_GENERATION_DATA_GENERATOR_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_DATA_GENERATOR_H_
|
||||||
#define BIERGARTEN_PIPELINE_DATA_GENERATION_DATA_GENERATOR_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_DATA_GENERATOR_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file data_generation/data_generator.h
|
* @file data_generation/data_generator.h
|
||||||
@@ -69,4 +69,4 @@ class DataGenerator {
|
|||||||
virtual UserResult GenerateUser(const std::string& locale) = 0;
|
virtual UserResult GenerateUser(const std::string& locale) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_DATA_GENERATION_DATA_GENERATOR_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_DATA_GENERATOR_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_H_
|
||||||
#define BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file data_generation/llama_generator.h
|
* @file data_generation/llama_generator.h
|
||||||
@@ -120,4 +120,4 @@ class LlamaGenerator final : public DataGenerator {
|
|||||||
std::string brewery_system_prompt_;
|
std::string brewery_system_prompt_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
||||||
#define BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file data_generation/llama_generator_helpers.h
|
* @file data_generation/llama_generator_helpers.h
|
||||||
@@ -85,4 +85,4 @@ std::string ValidateBreweryJsonPublic(const std::string& raw,
|
|||||||
*/
|
*/
|
||||||
std::string ExtractLastJsonObjectPublic(const std::string& text);
|
std::string ExtractLastJsonObjectPublic(const std::string& text);
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_LLAMA_GENERATOR_HELPERS_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_DATA_GENERATION_MOCK_GENERATOR_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_MOCK_GENERATOR_H_
|
||||||
#define BIERGARTEN_PIPELINE_DATA_GENERATION_MOCK_GENERATOR_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_MOCK_GENERATOR_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file data_generation/mock_generator.h
|
* @file data_generation/mock_generator.h
|
||||||
@@ -51,4 +51,4 @@ class MockGenerator final : public DataGenerator {
|
|||||||
static const std::vector<std::string> kBios;
|
static const std::vector<std::string> kBios;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_DATA_GENERATION_MOCK_GENERATOR_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_DATA_GENERATION_MOCK_GENERATOR_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_MODELS_LOCATION_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_DATA_MODEL_LOCATION_H_
|
||||||
#define BIERGARTEN_PIPELINE_MODELS_LOCATION_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_DATA_MODEL_LOCATION_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file data_model/location.h
|
* @file data_model/location.h
|
||||||
@@ -34,4 +34,4 @@ struct Location {
|
|||||||
double longitude;
|
double longitude;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_MODELS_LOCATION_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_DATA_MODEL_LOCATION_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_JSON_HANDLING_JSON_LOADER_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_JSON_HANDLING_JSON_LOADER_H_
|
||||||
#define BIERGARTEN_PIPELINE_JSON_HANDLING_JSON_LOADER_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_JSON_HANDLING_JSON_LOADER_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file json_handling/json_loader.h
|
* @file json_handling/json_loader.h
|
||||||
@@ -18,4 +18,4 @@ class JsonLoader {
|
|||||||
static std::vector<Location> LoadLocations(const std::string& filepath);
|
static std::vector<Location> LoadLocations(const std::string& filepath);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_JSON_HANDLING_JSON_LOADER_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_JSON_HANDLING_JSON_LOADER_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_LLAMA_BACKEND_STATE_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_LLAMA_BACKEND_STATE_H_
|
||||||
#define BIERGARTEN_PIPELINE_LLAMA_BACKEND_STATE_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_LLAMA_BACKEND_STATE_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file llama_backend_state.h
|
* @file llama_backend_state.h
|
||||||
@@ -29,4 +29,4 @@ class LlamaBackendState {
|
|||||||
LlamaBackendState& operator=(const LlamaBackendState&) = delete;
|
LlamaBackendState& operator=(const LlamaBackendState&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_LLAMA_BACKEND_STATE_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_LLAMA_BACKEND_STATE_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_SERVICES_ENRICHMENT_SERVICE_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_SERVICE_H_
|
||||||
#define BIERGARTEN_PIPELINE_SERVICES_ENRICHMENT_SERVICE_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_SERVICE_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file services/enrichment_service.h
|
* @file services/enrichment_service.h
|
||||||
@@ -27,4 +27,4 @@ class IEnrichmentService {
|
|||||||
virtual std::string GetLocationContext(const Location& loc) = 0;
|
virtual std::string GetLocationContext(const Location& loc) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_SERVICES_ENRICHMENT_SERVICE_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_ENRICHMENT_SERVICE_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_WIKIPEDIA_SERVICE_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_WIKIPEDIA_SERVICE_H_
|
||||||
#define BIERGARTEN_PIPELINE_WIKIPEDIA_SERVICE_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_WIKIPEDIA_SERVICE_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file services/wikipedia_service.h
|
* @file services/wikipedia_service.h
|
||||||
@@ -30,4 +30,4 @@ class WikipediaService final : public IEnrichmentService {
|
|||||||
std::unordered_map<std::string, std::string> extract_cache_;
|
std::unordered_map<std::string, std::string> extract_cache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_WIKIPEDIA_SERVICE_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_WIKIPEDIA_SERVICE_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
||||||
#define BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file web_client/curl_web_client.h
|
* @file web_client/curl_web_client.h
|
||||||
@@ -68,4 +68,4 @@ class CURLWebClient : public WebClient {
|
|||||||
std::string UrlEncode(const std::string& value) override;
|
std::string UrlEncode(const std::string& value) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_WEB_CLIENT_WEB_CLIENT_H_
|
#ifndef
|
||||||
#define BIERGARTEN_PIPELINE_WEB_CLIENT_WEB_CLIENT_H_
|
BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_WEB_CLIENT_H_
|
||||||
|
#define BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_WEB_CLIENT_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file web_client/web_client.h
|
* @file web_client/web_client.h
|
||||||
@@ -42,4 +43,4 @@ class WebClient {
|
|||||||
virtual std::string UrlEncode(const std::string& value) = 0;
|
virtual std::string UrlEncode(const std::string& value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_WEB_CLIENT_WEB_CLIENT_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_WEB_CLIENT_WEB_CLIENT_H_
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
void BiergartenDataGenerator::GenerateBreweries(
|
void BiergartenDataGenerator::GenerateBreweries(
|
||||||
const std::vector<EnrichedCity>& cities) {
|
const std::vector<EnrichedCity>& cities) {
|
||||||
spdlog::info("\n=== SAMPLE BREWERY GENERATION ===");
|
spdlog::info("\n=== SAMPLE BREWERY GENERATION ===");
|
||||||
generatedBreweries_.clear();
|
generated_breweries_.clear();
|
||||||
|
|
||||||
size_t skipped_count = 0;
|
size_t skipped_count = 0;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ void BiergartenDataGenerator::GenerateBreweries(
|
|||||||
BreweryLocation{enriched_city.location.city,
|
BreweryLocation{enriched_city.location.city,
|
||||||
enriched_city.location.country},
|
enriched_city.location.country},
|
||||||
enriched_city.region_context);
|
enriched_city.region_context);
|
||||||
generatedBreweries_.push_back(GeneratedBrewery{
|
generated_breweries_.push_back(GeneratedBrewery{
|
||||||
.location = enriched_city.location, .brewery = brewery});
|
.location = enriched_city.location, .brewery = brewery});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
++skipped_count;
|
++skipped_count;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
void BiergartenDataGenerator::LogResults() const {
|
void BiergartenDataGenerator::LogResults() const {
|
||||||
spdlog::info("\n=== GENERATED DATA DUMP ===");
|
spdlog::info("\n=== GENERATED DATA DUMP ===");
|
||||||
size_t index = 1;
|
size_t index = 1;
|
||||||
for (const auto& [location, brewery] : generatedBreweries_) {
|
for (const auto& [location, brewery] : generated_breweries_) {
|
||||||
spdlog::info(
|
spdlog::info(
|
||||||
"{}. city=\"{}\" country=\"{}\" state=\"{}\" "
|
"{}. city=\"{}\" country=\"{}\" state=\"{}\" "
|
||||||
"iso3166_2={} lat={} lon={}",
|
"iso3166_2={} lat={} lon={}",
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
static constexpr unsigned int brewery_amount = 4;
|
static constexpr unsigned int brewery_amount = 4;
|
||||||
|
|
||||||
auto BiergartenDataGenerator::QueryCitiesWithCountries()
|
std::vector<Location> BiergartenDataGenerator::QueryCitiesWithCountries() {
|
||||||
-> std::vector<Location> {
|
|
||||||
spdlog::info("\n=== GEOGRAPHIC DATA OVERVIEW ===");
|
spdlog::info("\n=== GEOGRAPHIC DATA OVERVIEW ===");
|
||||||
|
|
||||||
const std::filesystem::path locations_path = "locations.json";
|
const std::filesystem::path locations_path = "locations.json";
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "biergarten_data_generator.h"
|
#include "biergarten_data_generator.h"
|
||||||
|
|
||||||
auto BiergartenDataGenerator::Run() -> bool {
|
bool BiergartenDataGenerator::Run() {
|
||||||
try {
|
try {
|
||||||
const std::vector<Location> cities = QueryCitiesWithCountries();
|
const std::vector<Location> cities = QueryCitiesWithCountries();
|
||||||
std::vector<EnrichedCity> enriched;
|
std::vector<EnrichedCity> enriched;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
auto ExtractFinalJsonPayload(std::string raw_response) -> std::string {
|
std::string ExtractFinalJsonPayload(std::string raw_response) {
|
||||||
auto trim = [](std::string_view text) -> std::string_view {
|
auto trim = [](std::string_view text) -> std::string_view {
|
||||||
const std::size_t first = text.find_first_not_of(" \t\n\r");
|
const std::size_t first = text.find_first_not_of(" \t\n\r");
|
||||||
if (first == std::string_view::npos) {
|
if (first == std::string_view::npos) {
|
||||||
@@ -58,9 +58,8 @@ auto ExtractFinalJsonPayload(std::string raw_response) -> std::string {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
auto LlamaGenerator::GenerateBrewery(const BreweryLocation& location,
|
BreweryResult LlamaGenerator::GenerateBrewery(
|
||||||
const std::string& region_context)
|
const BreweryLocation& location, const std::string& region_context) {
|
||||||
-> BreweryResult {
|
|
||||||
/**
|
/**
|
||||||
* Preprocess and truncate region context to manageable size
|
* Preprocess and truncate region context to manageable size
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
|
|
||||||
#include "data_generation/mock_generator.h"
|
#include "data_generation/mock_generator.h"
|
||||||
|
|
||||||
auto MockGenerator::DeterministicHash(const BreweryLocation& location)
|
std::size_t MockGenerator::DeterministicHash(const BreweryLocation& location) {
|
||||||
-> std::size_t {
|
|
||||||
std::size_t seed = 0;
|
std::size_t seed = 0;
|
||||||
boost::hash_combine(seed, location.city_name);
|
boost::hash_combine(seed, location.city_name);
|
||||||
boost::hash_combine(seed, location.country_name);
|
boost::hash_combine(seed, location.country_name);
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
|
|
||||||
#include "data_generation/mock_generator.h"
|
#include "data_generation/mock_generator.h"
|
||||||
|
|
||||||
auto MockGenerator::GenerateBrewery(const BreweryLocation& location,
|
BreweryResult MockGenerator::GenerateBrewery(
|
||||||
const std::string& /*region_context*/)
|
const BreweryLocation& location, const std::string& /*region_context*/) {
|
||||||
-> BreweryResult {
|
|
||||||
const std::size_t hash = DeterministicHash(location);
|
const std::size_t hash = DeterministicHash(location);
|
||||||
|
|
||||||
const std::string& adjective =
|
const std::string& adjective =
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
static auto ReadRequiredString(const boost::json::object& object,
|
static std::string ReadRequiredString(const boost::json::object& object,
|
||||||
const char* key) -> std::string {
|
const char* key) {
|
||||||
const boost::json::value* value = object.if_contains(key);
|
const boost::json::value* value = object.if_contains(key);
|
||||||
if (value == nullptr || !value->is_string()) {
|
if (value == nullptr || !value->is_string()) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@@ -23,8 +23,8 @@ static auto ReadRequiredString(const boost::json::object& object,
|
|||||||
return std::string(value->as_string().c_str());
|
return std::string(value->as_string().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto ReadRequiredNumber(const boost::json::object& object,
|
static double ReadRequiredNumber(const boost::json::object& object,
|
||||||
const char* key) -> double {
|
const char* key) {
|
||||||
const boost::json::value* value = object.if_contains(key);
|
const boost::json::value* value = object.if_contains(key);
|
||||||
if (value == nullptr || !value->is_number()) {
|
if (value == nullptr || !value->is_number()) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@@ -33,8 +33,7 @@ static auto ReadRequiredNumber(const boost::json::object& object,
|
|||||||
return value->to_number<double>();
|
return value->to_number<double>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto JsonLoader::LoadLocations(const std::string& filepath)
|
std::vector<Location> JsonLoader::LoadLocations(const std::string& filepath) {
|
||||||
-> std::vector<Location> {
|
|
||||||
std::ifstream input(filepath);
|
std::ifstream input(filepath);
|
||||||
if (!input.is_open()) {
|
if (!input.is_open()) {
|
||||||
throw std::runtime_error("Failed to open locations file: " + filepath);
|
throw std::runtime_error("Failed to open locations file: " + filepath);
|
||||||
@@ -44,7 +43,7 @@ auto JsonLoader::LoadLocations(const std::string& filepath)
|
|||||||
buffer << input.rdbuf();
|
buffer << input.rdbuf();
|
||||||
const std::string content = buffer.str();
|
const std::string content = buffer.str();
|
||||||
|
|
||||||
boost::json::error_code error;
|
boost::system::error_code error;
|
||||||
boost::json::value root = boost::json::parse(content, error);
|
boost::json::value root = boost::json::parse(content, error);
|
||||||
if (error) {
|
if (error) {
|
||||||
throw std::runtime_error("Failed to parse locations JSON: " +
|
throw std::runtime_error("Failed to parse locations JSON: " +
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ namespace di = boost::di;
|
|||||||
* @param options Output ApplicationOptions struct.
|
* @param options Output ApplicationOptions struct.
|
||||||
* @return true if parsing succeeded and should proceed, false otherwise.
|
* @return true if parsing succeeded and should proceed, false otherwise.
|
||||||
*/
|
*/
|
||||||
auto ParseArguments(const int argc, char** argv,
|
bool ParseArguments(const int argc, char** argv,
|
||||||
ApplicationOptions& options) noexcept -> bool {
|
ApplicationOptions& options) noexcept {
|
||||||
prog_opts::options_description desc("Pipeline Options");
|
prog_opts::options_description desc("Pipeline Options");
|
||||||
desc.add_options()("help,h", "Produce help message")(
|
desc.add_options()("help,h", "Produce help message")(
|
||||||
"mocked", prog_opts::bool_switch(),
|
"mocked", prog_opts::bool_switch(),
|
||||||
@@ -118,7 +118,7 @@ auto ParseArguments(const int argc, char** argv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto main(const int argc, char** argv) noexcept -> int {
|
int main(const int argc, char** argv) noexcept {
|
||||||
try {
|
try {
|
||||||
const CurlGlobalState curl_state;
|
const CurlGlobalState curl_state;
|
||||||
const LlamaBackendState llama_backend_state;
|
const LlamaBackendState llama_backend_state;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "services/wikipedia_service.h"
|
#include "services/wikipedia_service.h"
|
||||||
|
|
||||||
auto WikipediaService::FetchExtract(std::string_view query) -> std::string {
|
std::string WikipediaService::FetchExtract(std::string_view query) {
|
||||||
const std::string cache_key(query);
|
const std::string cache_key(query);
|
||||||
const auto cache_it = this->extract_cache_.find(cache_key);
|
const auto cache_it = this->extract_cache_.find(cache_key);
|
||||||
if (cache_it != this->extract_cache_.end()) {
|
if (cache_it != this->extract_cache_.end()) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "services/wikipedia_service.h"
|
#include "services/wikipedia_service.h"
|
||||||
|
|
||||||
auto WikipediaService::GetLocationContext(const Location& loc) -> std::string {
|
std::string WikipediaService::GetLocationContext(const Location& loc) {
|
||||||
const std::string cache_key = loc.city + "|" + loc.country;
|
const std::string cache_key = loc.city + "|" + loc.country;
|
||||||
const auto cache_it = cache_.find(cache_key);
|
const auto cache_it = cache_.find(cache_key);
|
||||||
if (cache_it != cache_.end()) {
|
if (cache_it != cache_.end()) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
auto create_handle() -> CurlHandle {
|
CurlHandle create_handle() {
|
||||||
CURL* handle = curl_easy_init();
|
CURL* handle = curl_easy_init();
|
||||||
if (handle == nullptr) {
|
if (handle == nullptr) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@@ -16,8 +16,8 @@ auto create_handle() -> CurlHandle {
|
|||||||
return CurlHandle(handle, &curl_easy_cleanup);
|
return CurlHandle(handle, &curl_easy_cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto set_common_get_options(CURL* curl, const std::string& url,
|
void set_common_get_options(CURL* curl, const std::string& url,
|
||||||
CurlTimeouts timeouts) -> void {
|
CurlTimeouts timeouts) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "biergarten-pipeline/0.1.0");
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "biergarten-pipeline/0.1.0");
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
#ifndef BIERGARTEN_PIPELINE_SRC_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
||||||
#define BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
#define BIERGARTEN_PIPELINE_SRC_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file web_client/curl_web_client_utils.h
|
* @file web_client/curl_web_client_utils.h
|
||||||
@@ -23,4 +23,4 @@ CurlHandle create_handle();
|
|||||||
void set_common_get_options(CURL* curl, const std::string& url,
|
void set_common_get_options(CURL* curl, const std::string& url,
|
||||||
CurlTimeouts timeouts);
|
CurlTimeouts timeouts);
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
#endif // BIERGARTEN_PIPELINE_SRC_WEB_CLIENT_CURL_WEB_CLIENT_UTILS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user