X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6f7160dd027c8ce7e2760aa369768ba39ab80181..f30167d5f98aa53c747b1e119110fb0acff2651e:/projects/stargazer/tariff_impl.cpp diff --git a/projects/stargazer/tariff_impl.cpp b/projects/stargazer/tariff_impl.cpp index bfae5215..1fa2e82f 100644 --- a/projects/stargazer/tariff_impl.cpp +++ b/projects/stargazer/tariff_impl.cpp @@ -28,26 +28,21 @@ $Author: faust $ */ -#include -#include // std::max - #include "tariff_impl.h" + #include "stg_timer.h" -#include "common.h" +#include "stg/common.h" + +#include +#include // std::max //----------------------------------------------------------------------------- -TARIFF & TARIFF_IMPL::operator=(const TARIFF_DATA & td) +TARIFF_IMPL & TARIFF_IMPL::operator=(const TARIFF_DATA & td) { tariffData = td; return *this; } //----------------------------------------------------------------------------- -TARIFF & TARIFF_IMPL::operator=(const TARIFF & t) -{ -tariffData = t.GetTariffData(); -return *this; -} -//----------------------------------------------------------------------------- double TARIFF_IMPL::GetPriceWithTraffType(uint64_t up, uint64_t down, int dir, @@ -119,7 +114,7 @@ else } } //----------------------------------------------------------------------------- -double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int mb, time_t t) const +double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int64_t mb, time_t t) const { int interval = Interval(dir, t); @@ -143,45 +138,30 @@ else if (!sp && th) return tariffData.dirPrice[dir].priceNightA; else return tariffData.dirPrice[dir].priceDayA; - -/*if (tariffData.dirPrice[dir].noDiscount && tariffData.dirPrice[dir].singlePrice) - { - return tariffData.dirPrice[dir].priceDayA; - } -else +} +//----------------------------------------------------------------------------- +std::string TARIFF_IMPL::TariffChangeIsAllowed(const TARIFF & to, time_t currentTime) const +{ +time_t timeout = GetChangePolicyTimeout(); +if (currentTime > timeout && timeout != 0) + return ""; +switch (GetChangePolicy()) { - if (tariffData.dirPrice[dir].noDiscount) - { - // Without threshold - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceNightA; - } - - if (tariffData.dirPrice[dir].singlePrice) - { - // Without day/night - if (mb < tariffData.dirPrice[dir].threshold) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceDayB; - } - - if (mb < tariffData.dirPrice[dir].threshold) - { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; + case TARIFF::ALLOW: + return ""; + case TARIFF::TO_CHEAP: + if (to.GetFee() < GetFee()) + return ""; else - return tariffData.dirPrice[dir].priceNightA; - } - else - { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayB; + return "New tariff '" + to.GetName() + "' is more expensive than current tariff '" + GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'."; + case TARIFF::TO_EXPENSIVE: + if (to.GetFee() >= GetFee()) + return ""; else - return tariffData.dirPrice[dir].priceNightB; - } - }*/ + return "New tariff '" + to.GetName() + "' is more cheap than current tariff '" + GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'."; + case TARIFF::DENY: + return "Current tariff '" + GetName() + "', new tariff '" + to.GetName() + "'. The policy is '" + TARIFF::ChangePolicyToString(GetChangePolicy()) + "'."; + } +return ""; } //-----------------------------------------------------------------------------