-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotPusher.py
113 lines (86 loc) · 2.49 KB
/
plotPusher.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# this file reads data from DB and writes it to a live plot.ly graph
# this file is intended to be used as a standalone model
# watching for DB updates from mongo is crucial
import time, re, sys, arrow
import plotly.plotly as ply # plotly lib
from plotly.graph_objs import Scatter, Layout, Figure, Data, Stream, YAxis
# plotly config
username = "plotly_arc"
api_key = "x0c1fu75vc"
shares_stream_token = "icf8tcvpfn"
hashrate_stream_token = "qoej2vrvoe"
ply.sign_in(username, api_key)
from pymongo import MongoClient
client = MongoClient()
db = client['etherPool_log']
collection = db['pre_thaw']
def convertStamp(timestamp):
meta = arrow.get(timestamp)
local_conv = meta.to('US/Eastern')
time = local_conv.format('YYYY-MM-DD HH:mm:ss')
return(time)
# config for actual streaming plot
trace_shares = Scatter(
x=[],
y=[],
stream=Stream(
token=shares_stream_token
),
yaxis='y'
)
trace_hashrate = Scatter(
x=[],
y=[],
stream=Stream(
token=hashrate_stream_token
),
yaxis='y2'
)
layout = Layout(
title='Ether Pool Hashrate & Mined Shares',
yaxis=YAxis(
title='Ether'
),
yaxis2=YAxis(
title='MH/s',
side='right',
overlaying="y"
)
)
data = Data([trace_shares, trace_hashrate])
fig = Figure(data=data, layout=layout)
print ply.plot(fig, filename = 'Ether Pool Stats')
stream_shares = ply.Stream(shares_stream_token)
stream_shares.open()
stream_hashrate = ply.Stream(hashrate_stream_token)
stream_hashrate.open()
print 'init db len set'
lastUpdate = db.pre_thaw.count()
while(True):
check = db.pre_thaw.count()
if (check > lastUpdate):
print 'Update detected'
lastUpdate = check
#figure out what to push to live graph
metric_obj = collection.find().sort("_id", -1)[0]
now = convertStamp(metric_obj["timestamp"])
if(metric_obj["shares_change"] and not(metric_obj["hashrate_change"])):
# do stuff
print '- shares update -'
shares = metric_obj["shares"]
stream_shares.write({'x': now, 'y': shares })
if(metric_obj["hashrate_change"] and not(metric_obj["shares_change"])):
# do stuff
print '- hashrate update -'
hashrate = metric_obj["hashrate"]
stream_hashrate.write({'x': now, 'y': hashrate })
if(metric_obj["shares_change"] and metric_obj["hashrate_change"]):
# do stuff
print '- shares and hasrate update -'
shares = metric_obj["shares"]
hashrate = metric_obj["hashrate"]
stream_shares.write({'x': now, 'y': shares })
stream_hashrate.write({'x': now, 'y': hashrate })
time.sleep(1)
stream_shares.close()
stream_hashrate.close()