Refactoring phenomena info to impact based warnings header

This commit is contained in:
Dan Paulat 2024-09-15 23:54:21 -05:00
parent 9182d170de
commit 829d8a3152
3 changed files with 44 additions and 31 deletions

View file

@ -23,36 +23,6 @@ namespace ui
static const std::string logPrefix_ = static const std::string logPrefix_ =
"scwx::qt::ui::settings::alert_palette_settings_widget"; "scwx::qt::ui::settings::alert_palette_settings_widget";
struct PhenomenonInfo
{
bool hasObservedTag_ {false};
bool hasTornadoPossibleTag_ {false};
std::vector<awips::ThreatCategory> threatCategories_ {
awips::ThreatCategory::Base};
};
static const boost::unordered_flat_map<awips::Phenomenon, PhenomenonInfo>
phenomenaInfo_ {{awips::Phenomenon::Marine,
PhenomenonInfo {.hasTornadoPossibleTag_ {true}}},
{awips::Phenomenon::FlashFlood,
PhenomenonInfo {.threatCategories_ {
awips::ThreatCategory::Base,
awips::ThreatCategory::Considerable,
awips::ThreatCategory::Catastrophic}}},
{awips::Phenomenon::SevereThunderstorm,
PhenomenonInfo {.hasTornadoPossibleTag_ {true},
.threatCategories_ {
awips::ThreatCategory::Base,
awips::ThreatCategory::Considerable,
awips::ThreatCategory::Destructive}}},
{awips::Phenomenon::SnowSquall, PhenomenonInfo {}},
{awips::Phenomenon::Tornado,
PhenomenonInfo {.hasObservedTag_ {true},
.threatCategories_ {
awips::ThreatCategory::Base,
awips::ThreatCategory::Considerable,
awips::ThreatCategory::Catastrophic}}}};
class AlertPaletteSettingsWidget::Impl class AlertPaletteSettingsWidget::Impl
{ {
public: public:
@ -208,7 +178,7 @@ QWidget* AlertPaletteSettingsWidget::Impl::CreateStackedWidgetPage(
QGridLayout* gridLayout = new QGridLayout(self_); QGridLayout* gridLayout = new QGridLayout(self_);
page->setLayout(gridLayout); page->setLayout(gridLayout);
const auto& phenomenonInfo = phenomenaInfo_.at(phenomenon); const auto& phenomenonInfo = awips::GetPhenomenonInfo(phenomenon);
int row = 0; int row = 0;

View file

@ -1,6 +1,9 @@
#pragma once #pragma once
#include <scwx/awips/phenomenon.hpp>
#include <string> #include <string>
#include <vector>
namespace scwx namespace scwx
{ {
@ -17,6 +20,15 @@ enum class ThreatCategory : int
Unknown Unknown
}; };
struct PhenomenonInfo
{
bool hasObservedTag_ {false};
bool hasTornadoPossibleTag_ {false};
std::vector<ThreatCategory> threatCategories_ {ThreatCategory::Base};
};
const PhenomenonInfo& GetPhenomenonInfo(Phenomenon phenomenon);
ThreatCategory GetThreatCategory(const std::string& name); ThreatCategory GetThreatCategory(const std::string& name);
const std::string& GetThreatCategoryName(ThreatCategory threatCategory); const std::string& GetThreatCategoryName(ThreatCategory threatCategory);

View file

@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/unordered/unordered_flat_map.hpp>
namespace scwx namespace scwx
{ {
@ -12,6 +13,26 @@ namespace awips
static const std::string logPrefix_ = "scwx::awips::impact_based_warnings"; static const std::string logPrefix_ = "scwx::awips::impact_based_warnings";
static const boost::unordered_flat_map<Phenomenon, PhenomenonInfo>
phenomenaInfo_ {
{Phenomenon::Marine, PhenomenonInfo {.hasTornadoPossibleTag_ {true}}},
{Phenomenon::FlashFlood,
PhenomenonInfo {.threatCategories_ {ThreatCategory::Base,
ThreatCategory::Considerable,
ThreatCategory::Catastrophic}}},
{Phenomenon::SevereThunderstorm,
PhenomenonInfo {.hasTornadoPossibleTag_ {true},
.threatCategories_ {ThreatCategory::Base,
ThreatCategory::Considerable,
ThreatCategory::Destructive}}},
{Phenomenon::SnowSquall, PhenomenonInfo {}},
{Phenomenon::Tornado,
PhenomenonInfo {.hasObservedTag_ {true},
.threatCategories_ {ThreatCategory::Base,
ThreatCategory::Considerable,
ThreatCategory::Catastrophic}}},
{Phenomenon::Unknown, PhenomenonInfo {}}};
static const std::unordered_map<ThreatCategory, std::string> static const std::unordered_map<ThreatCategory, std::string>
threatCategoryName_ {{ThreatCategory::Base, "Base"}, threatCategoryName_ {{ThreatCategory::Base, "Base"},
{ThreatCategory::Significant, "Significant"}, {ThreatCategory::Significant, "Significant"},
@ -20,6 +41,16 @@ static const std::unordered_map<ThreatCategory, std::string>
{ThreatCategory::Catastrophic, "Catastrophic"}, {ThreatCategory::Catastrophic, "Catastrophic"},
{ThreatCategory::Unknown, "?"}}; {ThreatCategory::Unknown, "?"}};
const PhenomenonInfo& GetPhenomenonInfo(Phenomenon phenomenon)
{
auto it = phenomenaInfo_.find(phenomenon);
if (it != phenomenaInfo_.cend())
{
return it->second;
}
return phenomenaInfo_.at(Phenomenon::Unknown);
}
SCWX_GET_ENUM(ThreatCategory, GetThreatCategory, threatCategoryName_) SCWX_GET_ENUM(ThreatCategory, GetThreatCategory, threatCategoryName_)
const std::string& GetThreatCategoryName(ThreatCategory threatCategory) const std::string& GetThreatCategoryName(ThreatCategory threatCategory)