From: Elena Mamontova Date: Wed, 20 Jul 2016 14:57:02 +0000 (+0300) Subject: Merge branch 'master' into ticket X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/b3bf247163c78d1bac74702459a4d53700280ebe?hp=5ac9b6c2949b075cbb8d8c91dd9f603f3f8ad0a3 Merge branch 'master' into ticket --- diff --git a/projects/sgconf/tariffs.cpp b/projects/sgconf/tariffs.cpp index 3d63d2a8..4d4374f7 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 ALLOW: return "allow"; + case TO_CHEAP: return "to_cheap"; + case TO_EXPENSIVE: return "to_expensive"; + case DENY: return "deny"; + } +return "unknown"; +} + std::string PeriodToString(TARIFF::PERIOD period) { switch (period) @@ -214,7 +226,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: " << CyangePolicyToString(conf.changePolicy) << "\n"; } void PrintTariff(const STG::GET_TARIFF::INFO & info, size_t level = 0) @@ -233,6 +246,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", "", "\ttarification 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 +351,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 +385,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); diff --git a/stglibs/srvconf.lib/parsers/chg_tariff.cpp b/stglibs/srvconf.lib/parsers/chg_tariff.cpp index 158e6f89..5c6fd720 100644 --- a/stglibs/srvconf.lib/parsers/chg_tariff.cpp +++ b/stglibs/srvconf.lib/parsers/chg_tariff.cpp @@ -69,6 +69,15 @@ if (!data.tariffConf.period.empty()) case TARIFF::MONTH: stream << ""; break; } +if (!data.tariffConf.changePolicy.empty()) + switch (data.tariffConf.changePolicy.data()) + { + case TARIFF::DAY: stream << ""; break; + case TARIFF::MONTH: stream << ""; break; + case TARIFF::MONTH: stream << ""; break; + case TARIFF::MONTH: stream << ""; break; + } + for (size_t i = 0; i < DIR_NUM; ++i) if (!data.dirPrice[i].hDay.empty() && !data.dirPrice[i].mDay.empty() && diff --git a/stglibs/srvconf.lib/parsers/get_tariff.cpp b/stglibs/srvconf.lib/parsers/get_tariff.cpp index 0804b269..d929b266 100644 --- a/stglibs/srvconf.lib/parsers/get_tariff.cpp +++ b/stglibs/srvconf.lib/parsers/get_tariff.cpp @@ -97,6 +97,31 @@ else return true; } +bool GetChangePolicy(const char ** attr, T & value, const std::string & attrName) +{ +if (!CheckValue(attr, attrName)) + return false; +std::string type(attr[1]); +switch (type) + { + case "allow": + value = TARIFF::ALLOW; + break; + case "to_cheap": + value = TARIFF::TO_CHEAP; + break; + case "to_expensive": + value = TARIFF::TO_EXPENSIVE; + break; + case "deny": + value = TARIFF::DENY; + break; + default: + return false; + } +return true; +} + template bool GetSlashedValue(const char ** attr, A & array, T A::value_type:: * field) { @@ -131,6 +156,7 @@ GET_TARIFF::PARSER::PARSER(CALLBACK f, void * d, const std::string & e) AddParser(propertyParsers, "free", info.tariffConf.free); AddParser(propertyParsers, "traffType", info.tariffConf.traffType, GetTraffType); AddParser(propertyParsers, "period", info.tariffConf.period, GetPeriod); + AddParser(propertyParsers, "changePolicy", info.tariffConf.changePolicy, GetChangePolicy); for (size_t i = 0; i < DIR_NUM; ++i) AddParser(propertyParsers, "time" + unsigned2str(i), info.dirPrice[i], GetTimeSpan); AddAOSParser(propertyParsers, "priceDayA", info.dirPrice, &DIRPRICE_DATA::priceDayA, GetSlashedValue);