mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 13:30:06 +00:00
Add NEXRAD data provider function to get time points by date
This commit is contained in:
parent
3bee6f65e5
commit
a9f5a766cc
4 changed files with 83 additions and 9 deletions
|
|
@ -66,6 +66,26 @@ TEST(AwsLevel3DataProvider, GetAvailableProducts)
|
||||||
EXPECT_GT(products.size(), 0);
|
EXPECT_GT(products.size(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AwsLevel3DataProvider, GetTimePointsByDate)
|
||||||
|
{
|
||||||
|
using namespace std::chrono;
|
||||||
|
using sys_days = time_point<system_clock, days>;
|
||||||
|
|
||||||
|
const auto date = sys_days {2021y / May / 27d};
|
||||||
|
const auto tomorrow = date + days {1};
|
||||||
|
|
||||||
|
AwsLevel3DataProvider provider("KLSX", "N0Q");
|
||||||
|
|
||||||
|
auto timePoints = provider.GetTimePointsByDate(date);
|
||||||
|
|
||||||
|
EXPECT_GT(timePoints.size(), 0);
|
||||||
|
for (auto timePoint : timePoints)
|
||||||
|
{
|
||||||
|
EXPECT_GE(timePoint, date);
|
||||||
|
EXPECT_LT(timePoint, tomorrow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(AwsLevel3DataProvider, TimePointValid)
|
TEST(AwsLevel3DataProvider, TimePointValid)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
|
||||||
|
|
@ -20,23 +20,26 @@ public:
|
||||||
const std::string& region);
|
const std::string& region);
|
||||||
virtual ~AwsNexradDataProvider();
|
virtual ~AwsNexradDataProvider();
|
||||||
|
|
||||||
AwsNexradDataProvider(const AwsNexradDataProvider&) = delete;
|
AwsNexradDataProvider(const AwsNexradDataProvider&) = delete;
|
||||||
AwsNexradDataProvider& operator=(const AwsNexradDataProvider&) = delete;
|
AwsNexradDataProvider& operator=(const AwsNexradDataProvider&) = delete;
|
||||||
|
|
||||||
AwsNexradDataProvider(AwsNexradDataProvider&&) noexcept;
|
AwsNexradDataProvider(AwsNexradDataProvider&&) noexcept;
|
||||||
AwsNexradDataProvider& operator=(AwsNexradDataProvider&&) noexcept;
|
AwsNexradDataProvider& operator=(AwsNexradDataProvider&&) noexcept;
|
||||||
|
|
||||||
size_t cache_size() const;
|
size_t cache_size() const override;
|
||||||
|
|
||||||
std::chrono::system_clock::time_point last_modified() const;
|
std::chrono::system_clock::time_point last_modified() const override;
|
||||||
std::chrono::seconds update_period() const;
|
std::chrono::seconds update_period() const override;
|
||||||
|
|
||||||
std::string FindKey(std::chrono::system_clock::time_point time);
|
std::string FindKey(std::chrono::system_clock::time_point time) override;
|
||||||
std::string FindLatestKey();
|
std::string FindLatestKey() override;
|
||||||
|
std::vector<std::chrono::system_clock::time_point>
|
||||||
|
GetTimePointsByDate(std::chrono::system_clock::time_point date) override;
|
||||||
std::pair<size_t, size_t>
|
std::pair<size_t, size_t>
|
||||||
ListObjects(std::chrono::system_clock::time_point date);
|
ListObjects(std::chrono::system_clock::time_point date) override;
|
||||||
std::shared_ptr<wsr88d::NexradFile> LoadObjectByKey(const std::string& key);
|
std::shared_ptr<wsr88d::NexradFile>
|
||||||
std::pair<size_t, size_t> Refresh();
|
LoadObjectByKey(const std::string& key) override;
|
||||||
|
std::pair<size_t, size_t> Refresh() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<Aws::S3::S3Client> client();
|
std::shared_ptr<Aws::S3::S3Client> client();
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,17 @@ public:
|
||||||
virtual std::chrono::system_clock::time_point
|
virtual std::chrono::system_clock::time_point
|
||||||
GetTimePointByKey(const std::string& key) const = 0;
|
GetTimePointByKey(const std::string& key) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets NEXRAD data time points for the date supplied. Lists and adds them
|
||||||
|
* to the cache if required.
|
||||||
|
*
|
||||||
|
* @param date Date for which to get NEXRAD data time points
|
||||||
|
*
|
||||||
|
* @return NEXRAD data time points
|
||||||
|
*/
|
||||||
|
virtual std::vector<std::chrono::system_clock::time_point>
|
||||||
|
GetTimePointsByDate(std::chrono::system_clock::time_point date) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests available NEXRAD products for the current radar site, and adds
|
* Requests available NEXRAD products for the current radar site, and adds
|
||||||
* the list to the cache.
|
* the list to the cache.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <aws/s3/model/GetObjectRequest.h>
|
#include <aws/s3/model/GetObjectRequest.h>
|
||||||
#include <aws/s3/model/ListObjectsV2Request.h>
|
#include <aws/s3/model/ListObjectsV2Request.h>
|
||||||
|
#include <fmt/chrono.h>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -156,6 +157,45 @@ std::string AwsNexradDataProvider::FindLatestKey()
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::chrono::system_clock::time_point>
|
||||||
|
AwsNexradDataProvider::GetTimePointsByDate(
|
||||||
|
std::chrono::system_clock::time_point date)
|
||||||
|
{
|
||||||
|
const auto day = std::chrono::floor<std::chrono::days>(date);
|
||||||
|
|
||||||
|
std::vector<std::chrono::system_clock::time_point> timePoints {};
|
||||||
|
|
||||||
|
logger_->debug("GetTimePointsByDate: {}", day);
|
||||||
|
|
||||||
|
std::shared_lock lock(p->objectsMutex_);
|
||||||
|
|
||||||
|
// Is the date present in the date list?
|
||||||
|
if (std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day) ==
|
||||||
|
p->objectDates_.cend())
|
||||||
|
{
|
||||||
|
// Temporarily unlock mutex
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
// List objects, since the date is not present in the date list
|
||||||
|
ListObjects(date);
|
||||||
|
|
||||||
|
// Re-lock mutex
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine objects to retrieve
|
||||||
|
auto objectsBegin = p->objects_.lower_bound(day);
|
||||||
|
auto objectsEnd = p->objects_.lower_bound(day + std::chrono::days {1});
|
||||||
|
|
||||||
|
// Copy time points to destination vector
|
||||||
|
std::transform(objectsBegin,
|
||||||
|
objectsEnd,
|
||||||
|
std::back_inserter(timePoints),
|
||||||
|
[](const auto& object) { return object.first; });
|
||||||
|
|
||||||
|
return timePoints;
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<size_t, size_t>
|
std::pair<size_t, size_t>
|
||||||
AwsNexradDataProvider::ListObjects(std::chrono::system_clock::time_point date)
|
AwsNexradDataProvider::ListObjects(std::chrono::system_clock::time_point date)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue