-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshares.py
37 lines (29 loc) · 1.02 KB
/
shares.py
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
37
#!/usr/bin/env python
# encoding: utf-8
import json
from stat_info import ShareInfo
from stat_info import DetailStatInfo1Min
from stat_info import DetailStatInfo30Min
from stat_info import TotalStatInfo30Min
from stat_info import ReceivedConnection
def on_receive_data(c):
while True:
if b'\n' in c.data_cache:
l = c.data_cache.split(b'\n', 1)
c.data_cache = l[1]
o = None
try:
o = json.loads(l[0].decode())
except:
return False
on_new_share(o)
else:
return True
def on_new_share(share_obj):
user_name = share_obj["uname"]
worker = share_obj["worker"]
share_diff = float(share_obj["sdiff"])
valid = share_obj["valid"]
TotalStatInfo30Min.add_share_info(ShareInfo(user_name, worker, share_diff, valid))
DetailStatInfo1Min.add_share_info(ShareInfo(user_name, worker, share_diff, valid))
DetailStatInfo30Min.add_share_info(ShareInfo(user_name, worker, share_diff, valid))