forked from c00w/bitHopper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed.py
More file actions
36 lines (30 loc) · 1018 Bytes
/
speed.py
File metadata and controls
36 lines (30 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#License#
#bitHopper by Colin Rice is licensed under a Creative Commons
# Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#Based on a work at github.com.
import eventlet
from eventlet.green import threading, time, socket
# Global timeout for sockets in case something leaks
socket.setdefaulttimeout(900)
class Speed():
def __init__(self, bitHopper):
self.bitHopper = bitHopper
self.shares = 0
self.lock = threading.RLock()
eventlet.spawn_n(self.update_rate)
self.rate = 0
def add_shares(self, share):
self.shares += share
def update_rate(self):
self.old_time=time.time()
while True:
now = time.time()
diff = now -self.old_time
if diff <=0:
diff = 1
self.old_time = now
self.rate = int((float(self.shares) * (2**32)) / (diff * 1000000))
self.shares = 0
eventlet.sleep(60)
def get_rate(self):
return int(self.rate)