mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:10:05 +00:00
Use common map utility to get radar product record
This commit is contained in:
parent
bde8d288bd
commit
23337b3b21
2 changed files with 14 additions and 43 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||||
#include <scwx/common/constants.hpp>
|
#include <scwx/common/constants.hpp>
|
||||||
#include <scwx/util/threads.hpp>
|
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
#include <scwx/util/map.hpp>
|
||||||
|
#include <scwx/util/threads.hpp>
|
||||||
#include <scwx/wsr88d/nexrad_file_factory.hpp>
|
#include <scwx/wsr88d/nexrad_file_factory.hpp>
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
@ -66,9 +67,6 @@ public:
|
||||||
}
|
}
|
||||||
~RadarProductManagerImpl() = default;
|
~RadarProductManagerImpl() = default;
|
||||||
|
|
||||||
static std::shared_ptr<types::RadarProductRecord>
|
|
||||||
GetRadarProductRecord(RadarProductRecordMap& map,
|
|
||||||
std::chrono::system_clock::time_point time);
|
|
||||||
std::shared_ptr<types::RadarProductRecord>
|
std::shared_ptr<types::RadarProductRecord>
|
||||||
GetLevel2ProductRecord(std::chrono::system_clock::time_point time);
|
GetLevel2ProductRecord(std::chrono::system_clock::time_point time);
|
||||||
std::shared_ptr<types::RadarProductRecord>
|
std::shared_ptr<types::RadarProductRecord>
|
||||||
|
|
@ -311,46 +309,13 @@ void RadarProductManagerImpl::LoadNexradFile(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<types::RadarProductRecord>
|
|
||||||
RadarProductManagerImpl::GetRadarProductRecord(
|
|
||||||
RadarProductRecordMap& map, std::chrono::system_clock::time_point time)
|
|
||||||
{
|
|
||||||
std::shared_ptr<types::RadarProductRecord> record = nullptr;
|
|
||||||
|
|
||||||
// TODO: Round to minutes
|
|
||||||
|
|
||||||
// Find the first product record greater than the time requested
|
|
||||||
auto it = map.upper_bound(time);
|
|
||||||
|
|
||||||
// A product record with a time greater was found
|
|
||||||
if (it != map.cend())
|
|
||||||
{
|
|
||||||
// Are there product records prior to this record?
|
|
||||||
if (it != map.cbegin())
|
|
||||||
{
|
|
||||||
// Get the product record immediately preceding, this the record we are
|
|
||||||
// looking for
|
|
||||||
record = (--it)->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (map.size() > 0)
|
|
||||||
{
|
|
||||||
// A product record with a time greater was not found. If it exists, it
|
|
||||||
// must be the last record.
|
|
||||||
record = map.rbegin()->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<types::RadarProductRecord>
|
std::shared_ptr<types::RadarProductRecord>
|
||||||
RadarProductManagerImpl::GetLevel2ProductRecord(
|
RadarProductManagerImpl::GetLevel2ProductRecord(
|
||||||
std::chrono::system_clock::time_point time)
|
std::chrono::system_clock::time_point time)
|
||||||
{
|
{
|
||||||
std::shared_ptr<types::RadarProductRecord> record =
|
|
||||||
GetRadarProductRecord(level2ProductRecords_, time);
|
|
||||||
|
|
||||||
// TODO: Round to minutes
|
// TODO: Round to minutes
|
||||||
|
std::shared_ptr<types::RadarProductRecord> record =
|
||||||
|
util::GetBoundedElementValue(level2ProductRecords_, time);
|
||||||
|
|
||||||
// Does the record contain the time we are looking for?
|
// Does the record contain the time we are looking for?
|
||||||
if (record != nullptr && (time < record->level2_file()->start_time() ||
|
if (record != nullptr && (time < record->level2_file()->start_time() ||
|
||||||
|
|
@ -372,7 +337,7 @@ RadarProductManagerImpl::GetLevel3ProductRecord(
|
||||||
|
|
||||||
if (it != level3ProductRecords_.cend())
|
if (it != level3ProductRecords_.cend())
|
||||||
{
|
{
|
||||||
record = GetRadarProductRecord(it->second, time);
|
record = util::GetBoundedElementValue(it->second, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ namespace scwx
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class Key, class T>
|
template<class Key, class T, class ReturnType = std::optional<T>>
|
||||||
std::optional<T> GetBoundedElement(std::map<Key, T>& map, Key key)
|
ReturnType GetBoundedElement(std::map<Key, T>& map, Key key)
|
||||||
{
|
{
|
||||||
std::optional<T> element = std::nullopt;
|
ReturnType element;
|
||||||
|
|
||||||
// Find the first element greater than the key requested
|
// Find the first element greater than the key requested
|
||||||
auto it = map.upper_bound(key);
|
auto it = map.upper_bound(key);
|
||||||
|
|
@ -37,5 +37,11 @@ std::optional<T> GetBoundedElement(std::map<Key, T>& map, Key key)
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Key, class T>
|
||||||
|
inline T GetBoundedElementValue(std::map<Key, T>& map, Key key)
|
||||||
|
{
|
||||||
|
return GetBoundedElement<Key, T, T>(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
} // namespace scwx
|
} // namespace scwx
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue