Add threat category to alert dock widget

This commit is contained in:
Dan Paulat 2024-06-18 00:33:22 -05:00
parent 9437b0bfce
commit 49ba9b905b
3 changed files with 57 additions and 15 deletions

View file

@ -34,6 +34,8 @@ public:
explicit AlertModelImpl(); explicit AlertModelImpl();
~AlertModelImpl() = default; ~AlertModelImpl() = default;
awips::ThreatCategory GetThreatCategory(const types::TextEventKey& key);
static std::string GetCounties(const types::TextEventKey& key); static std::string GetCounties(const types::TextEventKey& key);
static std::string GetState(const types::TextEventKey& key); static std::string GetState(const types::TextEventKey& key);
static std::chrono::system_clock::time_point static std::chrono::system_clock::time_point
@ -49,6 +51,10 @@ public:
const GeographicLib::Geodesic& geodesic_; const GeographicLib::Geodesic& geodesic_;
std::unordered_map<types::TextEventKey,
awips::ThreatCategory,
types::TextEventHash<types::TextEventKey>>
threatCategoryMap_;
std::unordered_map<types::TextEventKey, std::unordered_map<types::TextEventKey,
common::Coordinate, common::Coordinate,
types::TextEventHash<types::TextEventKey>> types::TextEventHash<types::TextEventKey>>
@ -125,6 +131,17 @@ QVariant AlertModel::data(const QModelIndex& index, int role) const
return QString::fromStdString( return QString::fromStdString(
awips::GetSignificanceText(textEventKey.significance_)); awips::GetSignificanceText(textEventKey.significance_));
case static_cast<int>(Column::ThreatCategory):
if (role == Qt::DisplayRole)
{
return QString::fromStdString(awips::GetThreatCategoryName(
p->GetThreatCategory(textEventKey)));
}
else
{
return static_cast<int>(p->GetThreatCategory(textEventKey));
}
case static_cast<int>(Column::State): case static_cast<int>(Column::State):
return QString::fromStdString(AlertModelImpl::GetState(textEventKey)); return QString::fromStdString(AlertModelImpl::GetState(textEventKey));
@ -204,6 +221,9 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const
case static_cast<int>(Column::Significance): case static_cast<int>(Column::Significance):
return tr("Significance"); return tr("Significance");
case static_cast<int>(Column::ThreatCategory):
return tr("Category");
case static_cast<int>(Column::State): case static_cast<int>(Column::State):
return tr("State"); return tr("State");
@ -240,6 +260,10 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const
contentsSize = fontMetrics.size(0, QString(10, 'W')); contentsSize = fontMetrics.size(0, QString(10, 'W'));
break; break;
case static_cast<int>(Column::ThreatCategory):
contentsSize = fontMetrics.size(0, QString(6, 'W'));
break;
case static_cast<int>(Column::State): case static_cast<int>(Column::State):
contentsSize = fontMetrics.size(0, "WW, WW"); contentsSize = fontMetrics.size(0, "WW, WW");
break; break;
@ -285,6 +309,9 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey,
std::shared_ptr<const awips::Segment> alertSegment = std::shared_ptr<const awips::Segment> alertSegment =
alertMessages[messageIndex]->segments().back(); alertMessages[messageIndex]->segments().back();
p->threatCategoryMap_.insert_or_assign(alertKey,
alertSegment->threatCategory_);
if (alertSegment->codedLocation_.has_value()) if (alertSegment->codedLocation_.has_value())
{ {
// Update centroid and distance // Update centroid and distance
@ -365,6 +392,20 @@ AlertModelImpl::AlertModelImpl() :
{ {
} }
awips::ThreatCategory
AlertModelImpl::GetThreatCategory(const types::TextEventKey& key)
{
awips::ThreatCategory threatCategory = awips::ThreatCategory::Base;
auto it = threatCategoryMap_.find(key);
if (it != threatCategoryMap_.cend())
{
threatCategory = it->second;
}
return threatCategory;
}
std::string AlertModelImpl::GetCounties(const types::TextEventKey& key) std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
{ {
auto messageList = manager::TextEventManager::Instance()->message_list(key); auto messageList = manager::TextEventManager::Instance()->message_list(key);

View file

@ -21,15 +21,16 @@ class AlertModel : public QAbstractTableModel
public: public:
enum class Column : int enum class Column : int
{ {
Etn = 0, Etn = 0,
OfficeId = 1, OfficeId = 1,
Phenomenon = 2, Phenomenon = 2,
Significance = 3, Significance = 3,
State = 4, ThreatCategory = 4,
Counties = 5, State = 5,
StartTime = 6, Counties = 6,
EndTime = 7, StartTime = 7,
Distance = 8 EndTime = 8,
Distance = 9
}; };
explicit AlertModel(QObject* parent = nullptr); explicit AlertModel(QObject* parent = nullptr);

View file

@ -7,13 +7,13 @@ namespace scwx
namespace awips namespace awips
{ {
enum class ThreatCategory enum class ThreatCategory : int
{ {
Base, Base = 0,
Significant, Significant = 1,
Considerable, Considerable = 2,
Destructive, Destructive = 3,
Catastrophic, Catastrophic = 4,
Unknown Unknown
}; };