Added vol/theo archiving to AnalyticsService

This commit is contained in:
taha afzal committed 2022-02-28 13:29:57 -05:00
1 parent fb2fd21417
commit f9c79d5b44
3 files changed
+61 -6

No files matched your search

+23 -1
View File
@@ -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);
@@ -14,6 +14,7 @@
#include <boost/tokenizer.hpp>
#include <chrono>
#include <cstdint>
#include <locale>
#include <memory>
#include <string>
#include <tuple>
@@ -22,6 +23,14 @@ using namespace bts::api::analytics;
namespace bts::analytics {
uint64_t get_epoch() {
using namespace std::chrono;
milliseconds ms =
duration_cast<milliseconds>(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<persistence::IStore> vs_store;
std::unique_ptr<persistence::IStore> exp_params_store;
std::unique_ptr<persistence::IStore> vs_usage_store;
std::unique_ptr<persistence::IStore> reports_store;
std::unique_ptr<persistence::IStore> 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<persistence::SqliteStore>("volsurface_usage")),
reports_store(std::make_unique<persistence::SqliteStore>("reports")),
theos_store(
std::make_unique<persistence::SqliteStore>("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<milliseconds>(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_<vs-name>_<vs-id>
@@ -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<bts::api::analytics::ArchivedTheoList> &) {}
AnalyticsServiceServer::~AnalyticsServiceServer() {}
} // namespace bts::analytics
@@ -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<bts::api::analytics::ArchivedTheoList> &reply)
override;
~AnalyticsServiceServer();
};