mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 08:10:05 +00:00
Radar site configuration
This commit is contained in:
parent
19efb0e58c
commit
883626ebf5
5 changed files with 63 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include <scwx/qt/config/radar_site.hpp>
|
||||
#include <scwx/qt/util/json.hpp>
|
||||
#include <scwx/common/sites.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -18,7 +19,8 @@ static const std::string defaultRadarSiteFile_ =
|
|||
":/res/config/radar_sites.json";
|
||||
|
||||
static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
||||
radarSiteMap_;
|
||||
radarSiteMap_;
|
||||
static std::unordered_map<std::string, std::string> siteIdMap_;
|
||||
|
||||
static bool ValidateJsonEntry(const boost::json::object& o);
|
||||
|
||||
|
|
@ -100,6 +102,18 @@ std::shared_ptr<RadarSite> RadarSite::Get(const std::string& id)
|
|||
return radarSite;
|
||||
}
|
||||
|
||||
std::string GetRadarIdFromSiteId(const std::string& siteId)
|
||||
{
|
||||
std::string id = "???";
|
||||
|
||||
if (siteIdMap_.contains(siteId))
|
||||
{
|
||||
id = siteIdMap_.at(siteId);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void RadarSite::Initialize()
|
||||
{
|
||||
ReadConfig(defaultRadarSiteFile_);
|
||||
|
|
@ -145,6 +159,19 @@ size_t RadarSite::ReadConfig(const std::string& path)
|
|||
radarSiteMap_[site->p->id_] = site;
|
||||
++sitesAdded;
|
||||
}
|
||||
|
||||
std::string siteId = common::GetSiteId(site->p->id_);
|
||||
|
||||
if (!siteIdMap_.contains(siteId))
|
||||
{
|
||||
siteIdMap_[siteId] = site->p->id_;
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< logPrefix_ << "Site ID conflict: " << siteIdMap_.at(siteId)
|
||||
<< " and " << site->p->id_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ private:
|
|||
std::unique_ptr<RadarSiteImpl> p;
|
||||
};
|
||||
|
||||
std::string GetRadarIdFromSiteId(const std::string& siteId);
|
||||
|
||||
} // namespace config
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
|
|||
13
wxdata/include/scwx/common/sites.hpp
Normal file
13
wxdata/include/scwx/common/sites.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
|
||||
std::string GetSiteId(const std::string& radarId);
|
||||
|
||||
} // namespace common
|
||||
} // namespace scwx
|
||||
18
wxdata/source/scwx/common/sites.cpp
Normal file
18
wxdata/source/scwx/common/sites.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <scwx/common/products.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
|
||||
std::string GetSiteId(const std::string& radarId)
|
||||
{
|
||||
size_t siteIdIndex = std::max<size_t>(radarId.length(), 3u) - 3u;
|
||||
std::string siteId = radarId.substr(siteIdIndex);
|
||||
return siteId;
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace scwx
|
||||
|
|
@ -25,10 +25,12 @@ set(HDR_COMMON include/scwx/common/characters.hpp
|
|||
include/scwx/common/constants.hpp
|
||||
include/scwx/common/geographic.hpp
|
||||
include/scwx/common/products.hpp
|
||||
include/scwx/common/sites.hpp
|
||||
include/scwx/common/types.hpp
|
||||
include/scwx/common/vcp.hpp)
|
||||
set(SRC_COMMON source/scwx/common/color_table.cpp
|
||||
source/scwx/common/products.cpp
|
||||
source/scwx/common/sites.cpp
|
||||
source/scwx/common/vcp.cpp)
|
||||
set(HDR_UTIL include/scwx/util/iterator.hpp
|
||||
include/scwx/util/rangebuf.hpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue