From ec492bfb7700b719e41553417cbe77c5d10549ae Mon Sep 17 00:00:00 2001 From: fonsinchen Date: Fri, 20 Dec 2013 14:57:44 +0000 Subject: (svn r26166) -Fix: Scale flows only after mapping to avoid rounding errors. --- src/station_cmd.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/station_cmd.cpp') diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 6b158aaf1..6ef602b83 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -4289,6 +4289,22 @@ void FlowStat::ReleaseShare(StationID st) assert(!this->shares.empty()); } +/** + * Scale all shares from link graph's runtime to monthly values. + * @param runtime Time the link graph has been running without compression. + */ +void FlowStat::ScaleToMonthly(uint runtime) +{ + SharesMap new_shares; + uint share = 0; + for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) { + share = max(share + 1, i->first * 30 / runtime); + new_shares[share] = i->second; + if (this->unrestricted == i->first) this->unrestricted = share; + } + this->shares.swap(new_shares); +} + /** * Add some flow from "origin", going via "via". * @param origin Origin of the flow. -- cgit v1.2.3-54-g00ecf