Refactoring AWS level 2 data provider, pushing up common functions

This commit is contained in:
Dan Paulat 2022-05-30 00:53:22 -05:00
parent 394aba2d83
commit c5c54fbfa2
13 changed files with 512 additions and 439 deletions

View file

@ -1,18 +1,16 @@
#pragma once
#include <scwx/provider/level2_data_provider.hpp>
#include <scwx/provider/aws_nexrad_data_provider.hpp>
namespace scwx
{
namespace provider
{
class AwsLevel2DataProviderImpl;
/**
* @brief AWS Level 2 Data Provider
*/
class AwsLevel2DataProvider : public Level2DataProvider
class AwsLevel2DataProvider : public AwsNexradDataProvider
{
public:
explicit AwsLevel2DataProvider(const std::string& radarSite);
@ -27,26 +25,18 @@ public:
AwsLevel2DataProvider(AwsLevel2DataProvider&&) noexcept;
AwsLevel2DataProvider& operator=(AwsLevel2DataProvider&&) noexcept;
size_t cache_size() const;
std::chrono::system_clock::time_point last_modified() const;
std::chrono::seconds update_period() const;
std::string FindKey(std::chrono::system_clock::time_point time);
std::string FindLatestKey();
std::pair<size_t, size_t>
ListObjects(std::chrono::system_clock::time_point date);
std::shared_ptr<wsr88d::Ar2vFile> LoadObjectByKey(const std::string& key);
size_t Refresh();
std::chrono::system_clock::time_point
GetTimePointByKey(const std::string& key) const;
static std::chrono::system_clock::time_point
GetTimePointFromKey(const std::string& key);
protected:
std::string GetPrefix(std::chrono::system_clock::time_point date);
private:
std::unique_ptr<AwsLevel2DataProviderImpl> p;
class Impl;
std::unique_ptr<Impl> p;
};
} // namespace provider

View file

@ -0,0 +1,49 @@
#pragma once
#include <scwx/provider/nexrad_data_provider.hpp>
namespace scwx
{
namespace provider
{
/**
* @brief AWS NEXRAD Data Provider
*/
class AwsNexradDataProvider : public NexradDataProvider
{
public:
explicit AwsNexradDataProvider(const std::string& radarSite,
const std::string& bucketName,
const std::string& region);
~AwsNexradDataProvider();
AwsNexradDataProvider(const AwsNexradDataProvider&) = delete;
AwsNexradDataProvider& operator=(const AwsNexradDataProvider&) = delete;
AwsNexradDataProvider(AwsNexradDataProvider&&) noexcept;
AwsNexradDataProvider& operator=(AwsNexradDataProvider&&) noexcept;
size_t cache_size() const;
std::chrono::system_clock::time_point last_modified() const;
std::chrono::seconds update_period() const;
std::string FindKey(std::chrono::system_clock::time_point time);
std::string FindLatestKey();
std::pair<size_t, size_t>
ListObjects(std::chrono::system_clock::time_point date);
std::shared_ptr<wsr88d::NexradFile> LoadObjectByKey(const std::string& key);
size_t Refresh();
protected:
virtual std::string
GetPrefix(std::chrono::system_clock::time_point date) = 0;
private:
class Impl;
std::unique_ptr<Impl> p;
};
} // namespace provider
} // namespace scwx

View file

@ -1,29 +0,0 @@
#pragma once
#include <scwx/provider/level2_data_provider.hpp>
#include <memory>
namespace scwx
{
namespace provider
{
class Level2DataProviderFactory
{
private:
explicit Level2DataProviderFactory() = delete;
~Level2DataProviderFactory() = delete;
Level2DataProviderFactory(const Level2DataProviderFactory&) = delete;
Level2DataProviderFactory& operator=(const Level2DataProviderFactory&) = delete;
Level2DataProviderFactory(Level2DataProviderFactory&&) noexcept = delete;
Level2DataProviderFactory& operator=(Level2DataProviderFactory&&) noexcept = delete;
public:
static std::shared_ptr<Level2DataProvider> Create(const std::string& radarSite);
};
} // namespace provider
} // namespace scwx

View file

@ -1,6 +1,6 @@
#pragma once
#include <scwx/wsr88d/ar2v_file.hpp>
#include <scwx/wsr88d/nexrad_file.hpp>
#include <chrono>
#include <memory>
@ -11,19 +11,17 @@ namespace scwx
namespace provider
{
class Level2DataProviderImpl;
class Level2DataProvider
class NexradDataProvider
{
public:
explicit Level2DataProvider();
~Level2DataProvider();
explicit NexradDataProvider();
~NexradDataProvider();
Level2DataProvider(const Level2DataProvider&) = delete;
Level2DataProvider& operator=(const Level2DataProvider&) = delete;
NexradDataProvider(const NexradDataProvider&) = delete;
NexradDataProvider& operator=(const NexradDataProvider&) = delete;
Level2DataProvider(Level2DataProvider&&) noexcept;
Level2DataProvider& operator=(Level2DataProvider&&) noexcept;
NexradDataProvider(NexradDataProvider&&) noexcept;
NexradDataProvider& operator=(NexradDataProvider&&) noexcept;
virtual size_t cache_size() const = 0;
@ -49,19 +47,19 @@ public:
*
* @param time Upper-bound time for the key search
*
* @return Level 2 data key
* @return NEXRAD data key
*/
virtual std::string FindKey(std::chrono::system_clock::time_point time) = 0;
/**
* Finds the most recent key in the cache.
*
* @return Level 2 data key
* @return NEXRAD data key
*/
virtual std::string FindLatestKey() = 0;
/**
* Lists level 2 objects for the date supplied, and adds them to the cache.
* Lists NEXRAD objects for the date supplied, and adds them to the cache.
*
* @param date Date for which to list objects
*
@ -72,17 +70,17 @@ public:
ListObjects(std::chrono::system_clock::time_point date) = 0;
/**
* Loads a level 2 object by the given key.
* Loads a NEXRAD file object by the given key.
*
* @param key Level 2 data key
* @param key NEXRAD data key
*
* @return Level 2 data
* @return NEXRAD data
*/
virtual std::shared_ptr<wsr88d::Ar2vFile>
virtual std::shared_ptr<wsr88d::NexradFile>
LoadObjectByKey(const std::string& key) = 0;
/**
* Lists level 2 objects for the current date, and adds them to the cache. If
* Lists NEXRAD objects for the current date, and adds them to the cache. If
* no objects have been added to the cache for the current date, the previous
* date is also queried for data.
*
@ -93,15 +91,16 @@ public:
/**
* Convert the object key to a time point.
*
* @key Level 2 data key
* @key NEXRAD data key
*
* @return Level 2 data time point
* @return NEXRAD data time point
*/
virtual std::chrono::system_clock::time_point
GetTimePointByKey(const std::string& key) const = 0;
private:
std::unique_ptr<Level2DataProviderImpl> p;
class Impl;
std::unique_ptr<Impl> p;
};
} // namespace provider

View file

@ -0,0 +1,32 @@
#pragma once
#include <scwx/provider/nexrad_data_provider.hpp>
#include <memory>
namespace scwx
{
namespace provider
{
class NexradDataProviderFactory
{
private:
explicit NexradDataProviderFactory() = delete;
~NexradDataProviderFactory() = delete;
NexradDataProviderFactory(const NexradDataProviderFactory&) = delete;
NexradDataProviderFactory&
operator=(const NexradDataProviderFactory&) = delete;
NexradDataProviderFactory(NexradDataProviderFactory&&) noexcept = delete;
NexradDataProviderFactory&
operator=(NexradDataProviderFactory&&) noexcept = delete;
public:
static std::shared_ptr<NexradDataProvider>
CreateLevel2DataProvider(const std::string& radarSite);
};
} // namespace provider
} // namespace scwx