]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/pages/torrent/client/CurrentRateMeasure.py
1 # Written by Bram Cohen
2 # see LICENSE.txt for license information
4 from clock
import clock
7 def __init__(self
, max_rate_period
, fudge
= 1):
8 self
.max_rate_period
= max_rate_period
9 self
.ratesince
= clock() - fudge
10 self
.last
= self
.ratesince
14 def update_rate(self
, amount
):
17 self
.rate
= (self
.rate
* (self
.last
- self
.ratesince
) +
18 amount
) / (t
- self
.ratesince
+ 0.0001)
20 if self
.ratesince
< t
- self
.max_rate_period
:
21 self
.ratesince
= t
- self
.max_rate_period
27 def get_rate_noupdate(self
):
30 def time_until_rate(self
, newrate
):
31 if self
.rate
<= newrate
:
33 t
= clock() - self
.ratesince
34 return ((self
.rate
* t
) / newrate
) - t