X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/49ac42e64c982c16ca4421a50d15f36574ca0c10..66c4165457f76e06ce6716a42dd4c8495af916db:/projects/sgconf/tariffs.cpp diff --git a/projects/sgconf/tariffs.cpp b/projects/sgconf/tariffs.cpp index 663536fb..c384df1f 100644 --- a/projects/sgconf/tariffs.cpp +++ b/projects/sgconf/tariffs.cpp @@ -28,6 +28,18 @@ if (level == 0) return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' '); } +std::string ChangePolicyToString(TARIFF::CHANGE_POLICY changePolicy) +{ +switch (changePolicy) + { + case TARIFF::ALLOW: return "allow"; + case TARIFF::TO_CHEAP: return "to_cheap"; + case TARIFF::TO_EXPENSIVE: return "to_expensive"; + case TARIFF::DENY: return "deny"; + } +return "unknown"; +} + std::string PeriodToString(TARIFF::PERIOD period) { switch (period) @@ -40,17 +52,17 @@ switch (period) return "unknown"; } -std::string TraffTypeToString(int traffType) +std::string TraffTypeToString(TARIFF::TRAFF_TYPE traffType) { switch (traffType) { - case TRAFF_UP: + case TARIFF::TRAFF_UP: return "upload"; - case TRAFF_DOWN: + case TARIFF::TRAFF_DOWN: return "download"; - case TRAFF_UP_DOWN: + case TARIFF::TRAFF_UP_DOWN: return "upload + download"; - case TRAFF_MAX: + case TARIFF::TRAFF_MAX: return "max(upload, download)"; } return "unknown"; @@ -67,18 +79,33 @@ else throw SGCONF::ACTION::ERROR("Period should be 'daily' or 'monthly'. Got: '" + value + "'"); } -void ConvTraffType(const std::string & value, RESETABLE & res) +void ConvChangePolicy(const std::string & value, RESETABLE & res) +{ +std::string lowered = ToLower(value); +if (lowered == "allow") + res = TARIFF::ALLOW; +else if (lowered == "to_cheap") + res = TARIFF::TO_CHEAP; +else if (lowered == "to_expensive") + res = TARIFF::TO_EXPENSIVE; +else if (lowered == "deny") + res = TARIFF::DENY; +else + throw SGCONF::ACTION::ERROR("Change policy should be 'allow', 'to_cheap', 'to_expensive' or 'deny'. Got: '" + value + "'"); +} + +void ConvTraffType(const std::string & value, RESETABLE & res) { std::string lowered = ToLower(value); lowered.erase(std::remove(lowered.begin(), lowered.end(), ' '), lowered.end()); if (lowered == "upload") - res = TRAFF_UP; + res = TARIFF::TRAFF_UP; else if (lowered == "download") - res = TRAFF_DOWN; + res = TARIFF::TRAFF_DOWN; else if (lowered == "upload+download") - res = TRAFF_UP_DOWN; + res = TARIFF::TRAFF_UP_DOWN; else if (lowered.substr(0, 3) == "max") - res = TRAFF_MAX; + res = TARIFF::TRAFF_MAX; else throw SGCONF::ACTION::ERROR("Traff type should be 'upload', 'download', 'upload + download' or 'max'. Got: '" + value + "'"); } @@ -214,7 +241,8 @@ std::cout << Indent(level, true) << "name: " << conf.name << "\n" << Indent(level) << "free mb: " << conf.free << "\n" << Indent(level) << "passive cost: " << conf.passiveCost << "\n" << Indent(level) << "traff type: " << TraffTypeToString(conf.traffType) << "\n" - << Indent(level) << "period: " << PeriodToString(conf.period) << "\n"; + << Indent(level) << "period: " << PeriodToString(conf.period) << "\n" + << Indent(level) << "change policy: " << ChangePolicyToString(conf.changePolicy) << "\n"; } void PrintTariff(const STG::GET_TARIFF::INFO & info, size_t level = 0) @@ -233,6 +261,7 @@ params.push_back(SGCONF::API_ACTION::PARAM("free", "", "\tprepaid traff params.push_back(SGCONF::API_ACTION::PARAM("passive-cost", "", "\tpassive cost")); params.push_back(SGCONF::API_ACTION::PARAM("traff-type", "", "\ttraffic type (up, down, up+down, max)")); params.push_back(SGCONF::API_ACTION::PARAM("period", "", "\ttarification period (daily, monthly)")); +params.push_back(SGCONF::API_ACTION::PARAM("change-policy", "", "tariff change policy (allow, to_cheap, to_expensive, deny)")); params.push_back(SGCONF::API_ACTION::PARAM("times", "", "coma-separated day time-spans for each direction")); params.push_back(SGCONF::API_ACTION::PARAM("day-prices", "", "coma-separated day prices for each direction")); params.push_back(SGCONF::API_ACTION::PARAM("night-prices", "", "coma-separated night prices for each direction")); @@ -337,6 +366,7 @@ SGCONF::MaybeSet(options, "free", conf.tariffConf.free); SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost); SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType); SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod); +SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy); SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes); SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices); SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices); @@ -370,6 +400,7 @@ SGCONF::MaybeSet(options, "free", conf.tariffConf.free); SGCONF::MaybeSet(options, "passive-cost", conf.tariffConf.passiveCost); SGCONF::MaybeSet(options, "traff-type", conf.tariffConf.traffType, ConvTraffType); SGCONF::MaybeSet(options, "period", conf.tariffConf.period, ConvPeriod); +SGCONF::MaybeSet(options, "change-policy", conf.tariffConf.changePolicy, ConvChangePolicy); SGCONF::MaybeSet(options, "times", conf.dirPrice, ConvTimes); SGCONF::MaybeSet(options, "day-prices", conf.dirPrice, ConvDayPrices); SGCONF::MaybeSet(options, "night-prices", conf.dirPrice, ConvNightPrices);