From f9c79d5b44b2b98118edd6d574cd93ff7ed65d2d Mon Sep 17 00:00:00 2001 From: taha afzal Date: Mon, 28 Feb 2022 13:29:57 -0500 Subject: [PATCH] Added vol/theo archiving to AnalyticsService --- src/lib/api/services/AnalyticsService.proto | 24 +++++++++++++- .../analytics/AnalyticsServiceServer.cpp | 31 ++++++++++++++++--- .../sparkd/analytics/AnalyticsServiceServer.h | 12 ++++++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/lib/api/services/AnalyticsService.proto b/src/lib/api/services/AnalyticsService.proto index 22989ef33..8cb7b0dfd 100644 --- a/src/lib/api/services/AnalyticsService.proto +++ b/src/lib/api/services/AnalyticsService.proto @@ -24,6 +24,26 @@ message VolSurfaceUsageEntry{ int32 vs_id = 30; } +message ArchivedSecurityTheo{ + bts.api.Security security = 10; + double driver = 20; + double vol = 30; + double theo = 40; + double delta = 50; +} + +message ArchivedTheoList{ + uint64 save_time = 10; + // these are sec_tups that are part of this save + repeated bts.api.SecurityTuple sec_tups = 20; + repeated ArchivedSecurityTheo sec_theo = 30; +} + +message ArchivedTheoRetrieval{ + SecurityTuple sec_tup = 10; + uint64 save_time = 20; +} + // message VolSurfaceUsageList{ int32 id = 10 [(bts.api.key)=true]; @@ -148,7 +168,6 @@ message Report{ ReportCalculationMode calc_mode = 150; } - service AnalyticsService { option (bts.api.service_description) = "Provides VolSurface creations and saves"; rpc get_new_volsurface_id(bts.api.VoidMessage) returns (AnalyticsServiceCreateReply); @@ -157,6 +176,9 @@ service AnalyticsService { rpc clean_up(IntWrapper) returns (bts.api.VoidMessage); rpc set_exp_parameters(ExpirationParameterEntryList) returns (bts.api.ResultMessage); rpc set_volsurface_usage_list(VolSurfaceUsageList) returns (bts.api.ResultMessage); + rpc archive_theos(ArchivedTheoList) returns (bts.api.ResultMessage); + // finds the archived_theo closest to this point + rpc get_archived_theos(ArchivedTheoRetrieval) returns (ArchivedTheoList); // subscription rpc volsurfaces(bts.api.VoidMessage) returns (stream VolSurfaceEntry); diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp index 47462c133..d7ab05de6 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,14 @@ using namespace bts::api::analytics; namespace bts::analytics { +uint64_t get_epoch() { + using namespace std::chrono; + milliseconds ms = + duration_cast(system_clock::now().time_since_epoch()); + uint64_t ms_u = ms.count(); + return ms_u; +} + // assumes key are ints int get_max_id(IStore *const store, const std::string &ns) { auto ns_map = store->retrieve_all(); @@ -68,10 +77,12 @@ struct AnalyticsServiceServer::PImpl { const std::string exp_params_ns = "analytics_expiration_params"; const std::string vs_usage_ns = "volsurface_usage"; const std::string reports_ns = "reports"; + const std::string archived_theos_ns = "archived_theos"; std::unique_ptr vs_store; std::unique_ptr exp_params_store; std::unique_ptr vs_usage_store; std::unique_ptr reports_store; + std::unique_ptr theos_store; AnalyticsServiceBase::VolsurfacesStatefulPublisher vs_publisher; AnalyticsServiceBase::Exp_parametersStatefulPublisher exp_params_publisher; AnalyticsServiceBase::Volsurface_usageStatefulPublisher vs_usage_publisher; @@ -91,6 +102,8 @@ struct AnalyticsServiceServer::PImpl { vs_usage_store( std::make_unique("volsurface_usage")), reports_store(std::make_unique("reports")), + theos_store( + std::make_unique("archived_theos")), vs_publisher(vs_publisher), exp_params_publisher(exp_params_publisher), vs_usage_publisher(vs_usage_publisher), reports_publisher(reports_publisher) {} @@ -187,10 +200,7 @@ void AnalyticsServiceServer::get_new_volsurface_id( void AnalyticsServiceServer::save_volsurface( const bts::api::analytics::VolSurfaceEntry &vs_entry_arg, const api::Response<::bts::api::ResultMessage> &response) { - using namespace std::chrono; - milliseconds ms = - duration_cast(system_clock::now().time_since_epoch()); - uint64_t ms_u = ms.count(); + uint64_t ms_u = get_epoch(); VolSurfaceEntry vs_entry = vs_entry_arg; vs_entry.set_save_time(ms_u); // namespace: volsurface__ @@ -338,6 +348,19 @@ void AnalyticsServiceServer::delete_report( resp(res); } +void AnalyticsServiceServer::archive_theos( + const bts::api::analytics::ArchivedTheoList &theo_list, + const api::Response<::bts::api::ResultMessage> &) { + const std::string &ns = me->archived_theos_ns; + const std::string key = std::to_string(theo_list.save_time()); + std::string value = utils::pb::to_string(theo_list); + me->theos_store->insert(ns, key, value); +} + +void AnalyticsServiceServer::get_archived_theos( + const bts::api::analytics::ArchivedTheoRetrieval &, + const bts::api::Response &) {} + AnalyticsServiceServer::~AnalyticsServiceServer() {} } // namespace bts::analytics \ No newline at end of file diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.h b/src/server/sparkd/analytics/AnalyticsServiceServer.h index 38bca5f0b..1d97c0e00 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.h +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.h @@ -50,13 +50,23 @@ class AnalyticsServiceServer const ::bts::api::VoidMessage &request, const api::Response<::bts::api::analytics::AnalyticsServiceCreateReply> &reply) override; + void save_report( const ::bts::api::analytics::Report &report, const api::Response<::bts::api::ResultMessage> &reply) override; + void delete_report( const ::bts::api::analytics::IntWrapper &request, const api::Response<::bts::api::ResultMessage> &reply) override; - // rpc reports(bts.api.VoidMessage) returns(stream Report); + + void archive_theos( + const bts::api::analytics::ArchivedTheoList &theos, + const api::Response<::bts::api::ResultMessage> &reply) override; + + void get_archived_theos( + const bts::api::analytics::ArchivedTheoRetrieval &theo_ret, + const bts::api::Response &reply) + override; ~AnalyticsServiceServer(); };