Add support to OREF (-o flag)

This commit is contained in:
Dima yawaflua Andreev
2024-11-14 20:22:44 +02:00
parent 27632fa5c6
commit 89781660c3
12 changed files with 504 additions and 57 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/build
/cmake-build-debug
/.idea

View File

@@ -16,7 +16,14 @@ add_executable(tzeva_adom main.cpp
utils/audio_play.cpp
locale/localization_get.cpp
utils/localization_manager.h
utils/localization_manager.h
models/OrefAlertResponse.cpp
CONFIG.cpp
models/Interfaces/IAlertResponse.cpp
models/Interfaces/IAlert.cpp
locale/OREF_localization.cpp
models/AlertMessage_OREF.cpp
utils/OREFToTzevaAdom.cpp
models/OrefAlertResponse.cpp
)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)

16
CONFIG.cpp Normal file
View File

@@ -0,0 +1,16 @@
//
// Created by yawaflua on 30/10/2024.
//
#define OREF_URL "https://www.oref.org.il/warningMessages/alert/History/AlertsHistory.json"
#define TZEVA_ADOM_URL "https://api.tzevaadom.co.il/alerts-history"
#define THREAT_IMAGES_URL "https://www.tzevaadom.co.il/static/images/threat{}.{}"
#define BELL_SOUND_URL "https://www.tzevaadom.co.il/static/sounds/bell.mp3"
#define CITIES_OREF_URL_RU "https://www.oref.org.il/districts/cities_rus.json"
#define CITIES_OREF_URL_EN "https://www.oref.org.il/districts/cities_eng.json"
#define CITIES_OREF_URL_HE "https://www.oref.org.il/districts/cities_heb.json"
#define CITIES_TZEVA_ADOM "https://www.tzevaadom.co.il/static/cities.json"
#define ALERTS_OREF "https://www.oref.org.il/alerts/alertCategories.json"
#define ALERT_TRANSLATIONS_OREF "https://www.oref.org.il/alerts/alertsTranslation.json"

View File

@@ -9,6 +9,17 @@
"threat_7": "Неконвенциональная ракета",
"threat_8": "предупреждение",
"threat_9": "Учения Службы Тыла",
"missilealert": "Атака ракетами",
"uav": "Проникновение беспилотного самолета",
"nonconventional": "Неконвенциональная ракета",
"warning": "Предупреждение",
"earthquakealert1": "Землетрясение",
"earthquakealert2": "Землетрясение",
"terrorattack": "Подозрение на проникновение террористов",
"tsunami": "Цунами",
"hazmat": "Утечка опасных веществ",
"missilealertdrill": "Учения атаки ракетами",
"uavdrill": "Учения атаки беспилотников",
"default": "Неназвано",
"drill": "упражнения: ",
"true": "да",

View File

@@ -0,0 +1,89 @@
//
// Created by yawaflua on 01/11/2024.
//
#include <unistd.h>
#include <spdlog/fmt/fmt.h>
#ifndef OREF_LOCALIZATION_CPP
#define OREF_LOCALIZATION_CPP
#include "models/AlertMessage_OREF.cpp"
#include <string>
#include <unordered_map>
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp> // Подключение библиотеки JSON
#include <curl/curl.h>
#include "./CONFIG.cpp"
namespace tzeva_adom {
//class AlertMessage;
class LocalizationManager {
private:
std::vector<AlertMessage> jsonAlertsTranslate;
size_t static WriteCallbackAlerts(void* contents, size_t size, size_t nmemb, std::string* output) {
output->append(static_cast<char*>(contents), size * nmemb);
return size * nmemb;
}
std::string loadLocalizations(std::string lang) {
CURL* curl = curl_easy_init();
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_URL, ALERT_TRANSLATIONS_OREF);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallbackAlerts);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
CURLcode res = curl_easy_perform(curl);
auto jsonResponseFromLocalization = nlohmann::json::parse(readBuffer);
jsonAlertsTranslate = jsonResponseFromLocalization.get<std::vector<AlertMessage>>();
curl_easy_cleanup(curl);
}
public:
LocalizationManager() = default;
virtual ~LocalizationManager() = default;
// Загрузить языковой файл
bool loadLanguage(std::string lang) {
std::string path = std::filesystem::current_path().c_str() + fmt::format("/lang/{}.json", lang);
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "Failed to open localization file: " << lang << std::endl;
std::cerr << "Failed to open localization file: " << path << std::endl;
return false;
}
nlohmann::json json;
file >> json;
translations[lang] = json;
return true;
}
// Установить текущий язык
void setCurrentLanguage(const std::string& langCode) {
loadLanguage(langCode);
if (translations.find(langCode) != translations.end()) {
currentLanguage = langCode;
} else {
std::cerr << "Language code not loaded: " << langCode << std::endl;
}
}
// Получить переведенную строку по ключу
std::string getString(const std::string& key) const {
if (!translations.find(currentLanguage)->second.empty()) {
auto& langData = translations.at(currentLanguage);
if (langData.contains(key)) {
return langData[key];
}
}
return "Translation not found";
}
private:
std::unordered_map<std::string, nlohmann::json> translations;
std::string currentLanguage;
};
}
#endif // LOCALIZATION_MANAGER_H

102
main.cpp
View File

@@ -10,9 +10,12 @@
#include <libnotify/notify.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/split.hpp>
#include "CONFIG.cpp"
#include "utils/audio_play.cpp"
#include "models/AlertResponse.cpp"
#include "models/OrefAlertResponse.cpp"
#include "utils/image_downloader.cpp"
#include "utils/localization_manager.h"
@@ -20,13 +23,14 @@ class AlertResponse;
tzeva_adom::LocalizationManager localization_manager;
using json = nlohmann::json;
int16_t lastId = 0;
int64_t lastId = 0;
json cities_n_areas_list;
bool is_cities_loaded = false;
bool is_test = false;
std::string this_path = boost::filesystem::current_path().c_str();
std::string lang = "en";
std::vector<tzeva_adom::Alert> test_alert_variable;
bool is_oref = false;
// Функция для записи данных от curl
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* output) {
@@ -52,56 +56,55 @@ void process_alert(const std::string& data) {
}
spdlog::debug("Get first object from answer");
auto* first_alert = new tzeva_adom::AlertResponseElement(response.at(0));
spdlog::debug("Answer: {}", first_alert->get_id());
std::unique_ptr<tzeva_adom::IAlertResponse> first_alert;
if (is_oref) {
spdlog::debug("OREF_alertDate: {}", response[0]["alertDate"]);
spdlog::debug("OREF_title: {}", response[0]["title"]);
spdlog::debug("OREF_data: {}", response[0]["data"]);
spdlog::debug("OREF_category: {}",std::to_string(response[0]["category"].get<int>()));
spdlog::debug("OREF selected, create oref object");
auto response_oref = response.at(0);
first_alert = std::make_unique<tzeva_adom::OrefAlertResponse>(response_oref["alertDate"], response_oref["title"], response_oref["data"], response_oref["category"]);
}
else {
spdlog::debug("TzevaAdom selected, create object");
auto response_tzeva = response.at(0);
first_alert = std::make_unique<tzeva_adom::AlertResponseElement>(
response_tzeva["id"].get<int>(),
response_tzeva["description"].get<json>(),
response_tzeva["alerts"].get<json>());
}
auto id = first_alert->get_id();
spdlog::debug("Answer: {}", id);
if (lastId == 0 || id == lastId) {
lastId = id;
} else {
is_alert = !is_alert;
lastId = id;
if (!(lastId == 0 || id == lastId)) {
is_alert = true;
spdlog::debug("This is alert!");
}
lastId = id;
if (is_alert || is_test) {
is_test = !is_test;
// auto description = first_alert["description"].is_string() ?"": first_alert["description"].get<std::string>() ;
std::string description = "";
const std::vector<tzeva_adom::Alert> alerts_array = is_test ? test_alert_variable : first_alert->get_alerts();
std::vector<std::string> cities;
std::vector<int> threats;
is_test = false;
is_alert = false;
for (auto alerts: alerts_array) {
auto time = alerts.get_time();
for (auto city: alerts.get_cities()) {
cities.insert(cities.begin(), city);
}
std::string cities = first_alert->get_cities();
int threat = first_alert->get_threat();
threats.insert(threats.begin(), alerts.get_threat());
auto isDrill = alerts.get_is_drill();
// spdlog::debug("Time: {}", time);
spdlog::debug("Cities: {}", cities);
spdlog::debug("Time: {}", time);
spdlog::debug("Cities: {}", fmt::join(cities, ", "));
spdlog::debug("Threat Level: {}", alerts.get_threat());
spdlog::debug("Is Drill: {}", isDrill);
}
int threat = *std::max_element( threats.begin(), threats.end() );
std::string icon_url = boost::filesystem::current_path().c_str()+fmt::format("/threat{}.{}", std::to_string(threat), threat == 0 ? "png" : "svg");
spdlog::debug("Threat: {}", threat);
spdlog::debug("Threat: {}", first_alert->get_threat());
spdlog::debug("Threat name: {}", localization_manager.getString(fmt::format("threat_{}", threat)));
spdlog::debug("Language: {}", lang);
spdlog::debug("Icon path: {}", icon_url);
std::string localised_cities_names = "";
for (auto city: cities) {
for (auto city: first_alert->get_cities_arr()) {
localised_cities_names += fmt::format("{} ", cities_n_areas_list["cities"][city][lang]);
}
@@ -133,8 +136,9 @@ void process_alert(const std::string& data) {
}
} catch (const std::exception& e) {
spdlog::error("Alert error: {}", e.what());
} catch (...) {
std::exception_ptr e = std::current_exception();
spdlog::error("Alert error: {}", e ? (e.__cxa_exception_type()->name()) : "null");
}
@@ -150,9 +154,14 @@ void fetch_alerts_history(std::atomic<bool>& running) {
curl = curl_easy_init();
// Parse cities and areas names on he, ru and en
if (is_oref && lang == "he") {
spdlog::error("Lang is not supported. Use TZEVA_ADOM");
return;
}
if (!is_cities_loaded) {
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_URL, "https://www.tzevaadom.co.il/static/cities.json");
//Only tzeva_adom variable of cities list, because thats easier to work, than oref variable(without linq)
curl_easy_setopt(curl, CURLOPT_URL, CITIES_TZEVA_ADOM);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@@ -169,7 +178,7 @@ void fetch_alerts_history(std::atomic<bool>& running) {
if (curl) {
std::string readBuffer;
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.tzevaadom.co.il/alerts-history");
curl_easy_setopt(curl, CURLOPT_URL, !is_oref ? TZEVA_ADOM_URL : OREF_URL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@@ -213,15 +222,6 @@ int main(int argc, char** argv) {
spdlog::set_level(spdlog::level::debug); // Set global log level to debug if provided --debug
else if (argv[i] == "-t"sv || argv[i] == "--test") {
is_test = true; // Set tested variable is true
std::vector alert_to_array {tzeva_adom::Alert()};
const auto p1 = std::chrono::system_clock::now();
ulong t = std::chrono::duration_cast<std::chrono::seconds>(
p1.time_since_epoch()).count();
std::vector<std::string> city_vectors{"אשדוד -יא,יב,טו,יז,מרינה,סיט", "אשדוד - ח,ט,י,יג,יד,טז"};
alert_to_array[0].set_cities(city_vectors);
alert_to_array[0].set_time(t);
alert_to_array[0].set_threat(0);
test_alert_variable.push_back(alert_to_array[0]);
}
else if (argv[i] == "-l"sv || argv[i] == "--lang"sv) {
is_accept_values = true;
@@ -231,7 +231,6 @@ int main(int argc, char** argv) {
is_accept_values = false;
lang = argv[i];
spdlog::debug("Language setted to {}", lang);
}
else if (argv[i] == "-h"sv || argv[i] == "--help"sv) {
spdlog::info(
@@ -240,10 +239,15 @@ int main(int argc, char** argv) {
" -h --help: Show this message\n"\
" -d --debug: Show debug messages\n"\
" -t --test: Create test alert end exit\n"\
" -l --lang: Choose language: ru, en, he,"
" -l --lang: Choose language: ru, en, he\n"\
" -o --oref: Use OREF uri`s for alerts"\
"");
return 0;
}
else if (argv[i] == "-o"sv || argv[i] == "--oref"sv) {
is_oref = true;
spdlog::debug("Selected provider: OREF");
}
last_flag = argv[i];
}
@@ -253,7 +257,7 @@ int main(int argc, char** argv) {
if (!boost::filesystem::exists(this_path+fmt::format("/threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg"))) {
tzeva_adom::download_file(
fmt::format(
"https://www.tzevaadom.co.il/static/images/threat{}.{}",
THREAT_IMAGES_URL,
std::to_string(i), i == 0 ? "png" : "svg"),
fmt::format("threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg")
);
@@ -265,7 +269,7 @@ int main(int argc, char** argv) {
//Download tzeva-adom bell sound
if (!boost::filesystem::exists(this_path+fmt::format("/bell.mp3"))) {
tzeva_adom::download_file(
"https://www.tzevaadom.co.il/static/sounds/bell.mp3",
BELL_SOUND_URL,
fmt::format("bell.mp3")
);
}

View File

@@ -0,0 +1,69 @@
//
// Created by yawaflua on 01/11/2024.
//
#include <string>
#include <nlohmann/json.hpp>
namespace tzeva_adom {
class AlertMessage {
public:
std::string heb;
std::string eng;
std::string rus;
std::string arb;
int catId;
int matrixCatId;
std::string hebTitle;
std::string engTitle;
std::string rusTitle;
std::string arbTitle;
// AlertMessage(
// const std::string& heb, const std::string& eng, const std::string& rus, const std::string& arb,
// int catId, int matrixCatId,
// const std::string& hebTitle, const std::string& engTitle,
// const std::string& rusTitle, const std::string& arbTitle
// )
// : heb(heb), eng(eng), rus(rus), arb(arb),
// catId(catId), matrixCatId(matrixCatId),
// hebTitle(hebTitle), engTitle(engTitle),
// rusTitle(rusTitle), arbTitle(arbTitle) {}
AlertMessage() = default;
virtual ~AlertMessage() = default;
// JSON сериализация
friend void to_json(nlohmann::json& j, const AlertMessage& message) {
j = nlohmann::json{
{"heb", message.heb},
{"eng", message.eng},
{"rus", message.rus},
{"arb", message.arb},
{"catId", message.catId},
{"matrixCatId", message.matrixCatId},
{"hebTitle", message.hebTitle},
{"engTitle", message.engTitle},
{"rusTitle", message.rusTitle},
{"arbTitle", message.arbTitle}
};
}
// JSON десериализация
friend void from_json(const nlohmann::json& j, AlertMessage& message) {
j.at("heb").get_to(message.heb);
j.at("eng").get_to(message.eng);
j.at("rus").get_to(message.rus);
j.at("arb").get_to(message.arb);
j.at("catId").get_to(message.catId);
j.at("matrixCatId").get_to(message.matrixCatId);
j.at("hebTitle").get_to(message.hebTitle);
j.at("engTitle").get_to(message.engTitle);
j.at("rusTitle").get_to(message.rusTitle);
j.at("arbTitle").get_to(message.arbTitle);
}
using AlertingMessages = std::vector<AlertMessage>;
};
}

View File

@@ -11,8 +11,11 @@
#include <boost/optional.hpp>
#include <stdexcept>
#include <fmt/format.h>
#include <regex>
#include <nlohmann/json.hpp>
#include "models/Interfaces/IAlertResponse.cpp"
#include "models/Interfaces/IAlert.cpp"
namespace tzeva_adom {
using nlohmann::json;
@@ -31,9 +34,16 @@ namespace tzeva_adom {
}
#endif
class Alert {
class Alert : public IAlert{
public:
Alert() = default;
Alert(
const int64_t time,
const std::vector<std::string>& cities,
int64_t threat,
bool is_drill
) :
time(time), cities(cities), threat(threat), is_drill(is_drill) {};
virtual ~Alert() = default;
private:
@@ -48,10 +58,12 @@ namespace tzeva_adom {
void set_time(const int64_t & value) { this->time = value; }
const std::vector<std::string> & get_cities() const { return cities; }
std::vector<std::string> get_cities() override { return cities; }
std::vector<std::string> & get_mutable_cities() { return cities; }
void set_cities(const std::vector<std::string> & value) { this->cities = value; }
const int64_t & get_threat() const { return threat; }
int get_threat() override { return threat; }
int64_t & get_mutable_threat() { return threat; }
void set_threat(const int64_t & value) { this->threat = value; }
@@ -60,9 +72,25 @@ namespace tzeva_adom {
void set_is_drill(const bool & value) { this->is_drill = value; }
};
class AlertResponseElement {
class AlertResponseElement : public IAlertResponse {
public:
AlertResponseElement() = default;
AlertResponseElement(
const int id,
const nlohmann::json description,
const nlohmann::json alerts)
: id(id), description(description) {
for (const auto& alertJson : alerts) {
int64_t time = alertJson["time"];
std::vector<std::string> cities = alertJson["cities"].get<std::vector<std::string>>();
int64_t threat = alertJson["threat"];
bool is_drill = alertJson["isDrill"];
Alert _alert = *std::make_unique<Alert>(time, cities, threat, is_drill).get();
this->alerts.push_back(_alert);
}
}
virtual ~AlertResponseElement() = default;
private:
@@ -71,10 +99,19 @@ namespace tzeva_adom {
std::vector<Alert> alerts;
public:
const int64_t & get_id() const { return id; }
int get_id() override { return id; }
const int64_t &get_id() const { return id; }
int64_t & get_mutable_id() { return id; }
void set_id(const int64_t & value) { this->id = value; }
int get_threat() override {
int i = 0;
for (auto alert: alerts) {
i += alert.get_threat();
}
return i / alerts.size();
}
const nlohmann::json & get_description() const { return description; }
nlohmann::json & get_mutable_description() { return description; }
void set_description(const nlohmann::json & value) { this->description = value; }
@@ -82,6 +119,26 @@ namespace tzeva_adom {
const std::vector<Alert> & get_alerts() const { return alerts; }
std::vector<Alert> & get_mutable_alerts() { return alerts; }
void set_alerts(const std::vector<Alert> & value) { this->alerts = value; }
std::string get_cities() override {
return fmt::format("{}", fmt::join(get_cities_arr(), ", "));
}
std::vector<std::string> get_cities_arr() override {
std::vector<std::string> cities_to_return = {} ;
for (auto alert : alerts) {
cities_to_return.push_back(fmt::format("{}", fmt::join(alert.get_cities(), "")));
}
return cities_to_return;
}
std::vector<IAlert> get_alerts() override {
std::vector<IAlert> alertsToReturn {};
for (IAlert alert : alerts) {
alertsToReturn.insert(alertsToReturn.begin(), alert);
}
return alertsToReturn;
};
};
using AlertResponse = std::vector<AlertResponseElement>;

View File

@@ -0,0 +1,16 @@
//
// Created by yawaflua on 30/10/2024.
//
#pragma once
#include <vector>
#include <string>
namespace tzeva_adom {
class IAlert {
public:
virtual ~IAlert() = default;
virtual std::vector<std::string> get_cities() {};
virtual int get_threat() {};
};
}

View File

@@ -0,0 +1,24 @@
//
// Created by yawaflua on 30/10/2024.
//
#pragma once
#include <string>
#include <vector>
#include "IAlert.cpp"
namespace tzeva_adom {
class IAlertResponse
{
public:
// IAlertResponse() = default;
virtual ~IAlertResponse() = default;
virtual int get_id() = 0;
virtual int get_threat() = 0;
virtual std::string get_cities() = 0;
virtual std::vector<std::string> get_cities_arr() = 0;
virtual std::vector<IAlert> get_alerts() = 0;
};
}

View File

@@ -0,0 +1,125 @@
//
// Created by yawaflua on 30/10/2024.
//
#pragma once
#ifndef OREFALERTRESPONSE
#define OREFALERTRESPONSE
#include "models/Interfaces/IAlertResponse.cpp"
#include "utils/OREFToTzevaAdom.cpp"
#include <nlohmann/json.hpp>
namespace tzeva_adom{
class OrefAlert : public IAlert {
public:
OrefAlert() = default;
//virtual ~OrefAlert() = default;
void set_values(int _threat, std::vector<std::string> _cities) {
this->cities = _cities;
this->threat = _threat;
}
std::vector<std::string> get_cities() override { return cities; }
int get_threat() override { return threat; }
private:
int threat;
std::vector<std::string> cities;
};
class OrefAlertResponse : public IAlertResponse {
public:
OrefAlertResponse(const std::string& alertDate, const std::string& title,
const std::string& data, int64_t threat)
: alert_date(alertDate), title(title), data(data), threat(threat) {}
virtual ~OrefAlertResponse() = default;
private:
std::string alert_date;
std::string title;
std::string data;
int64_t threat;
public:
inline void set_data(std::string alert, std::string title_provided, std::string data_provided, int threat_provided) {
alert_date = alert;
title = title_provided;
data = data_provided;
threat = threat_provided;
}
const std::string & get_alert_date() const { return alert_date; }
std::string & get_mutable_alert_date() { return alert_date; }
void set_alert_date(const std::string & value) { this->alert_date = value; }
const std::string & get_title() const { return title; }
std::string & get_mutable_title() { return title; }
void set_title(const std::string & value) { this->title = value; }
const std::string & get_data() const { return data; }
std::string & get_mutable_data() { return data; }
void set_data(const std::string & value) { this->data = value; }
const int64_t &get_threat() const { return threat; }
int get_threat() override { return oref_threat_to_tzeva_adom(threat); }
int64_t & get_mutable_threat() { return threat; }
void set_threat(const int64_t & value) { this->threat = value; }
int get_id() override {
std::tm t = {};
std::istringstream ss(alert_date);
if (ss >> std::get_time(&t, "%Y-%m-%d %H:%M:%S"))
{
return std::mktime(&t) % 1000000;
}
};
std::string get_cities() override {return data; };
std::vector<std::string> get_cities_arr() override { return std::vector {data}; }
std::vector<IAlert> get_alerts() override {
auto orefAlertReturn = new OrefAlert();
orefAlertReturn->set_values(threat, get_cities_arr());
IAlert iAlertToReturn = static_cast<IAlert>(std::ref(*orefAlertReturn));
return std::vector {iAlertToReturn};
};
};
}
namespace tzeva_adom {
// void from_json(const nlohmann::json & j, OrefAlertResponse & x);
// void to_json(nlohmann::json & j, const OrefAlertResponse & x);
inline void to_json(nlohmann::json& j, const OrefAlertResponse& alert) {
j = nlohmann::json{
{"alert_date", alert.get_alert_date()},
{"title", alert.get_title()},
{"data", alert.get_data()},
{"threat", alert.get_threat()}
};
}
inline void from_json(const nlohmann::json& j, OrefAlertResponse& alert) {
if (j.contains("alert_date")) {
alert.set_alert_date(j.at("alert_date").get<std::string>());
}
if (j.contains("title")) {
alert.set_title(j.at("title").get<std::string>());
}
if (j.contains("data")) {
alert.set_data(j.at("data").get<std::string>());
}
if (j.contains("threat")) {
alert.set_threat(j.at("threat").get<int64_t>());
}
}
}
#endif

26
utils/OREFToTzevaAdom.cpp Normal file
View File

@@ -0,0 +1,26 @@
//
// Created by yawaflua on 13/11/2024.
//
#pragma once
#ifndef OREFTOTZEVAADOM_CPP
#define OREFTOTZEVAADOM_CPP
namespace tzeva_adom {
inline int oref_threat_to_tzeva_adom(int threat) {
switch (threat) {
case 1: return 0;
case 2: return 5;
case 3: return 7;
case 4: return 8;
case 6:
case 7: return 3;
case 8: return 0;
case 9: return 5;
case 10: return 4;
case 11: return 6;
default: return 9;
}
}
}
#endif