-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
72 lines (60 loc) · 1.66 KB
/
graph.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
#!/usr/bin/env python
# coding=utf-8
import os
import plotly
import datetime
import plotly.plotly as py
from dotenv import load_dotenv
from pymongo import MongoClient
from os.path import join, dirname
from plotly.graph_objs import Layout, Scatter
# ENV
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
# DB
client = MongoClient('localhost', 32769)
db = client['cwhelper']
collection = db.deals
# Ploty conf
plotly.tools.set_credentials_file(username=os.environ['PLOTLY_USER'], api_key=os.environ['PLOTLY_PASS'])
plotly.tools.set_config_file(world_readable=True, sharing='public')
steel_last_price = []
steel_timestamp = []
for rec in collection.find({'item':'Steel'}):
steel_last_price.append(rec['price'])
steel_timestamp.append(datetime.datetime.fromtimestamp(rec['timestamp']))
steel_lp = Scatter(
y=steel_last_price,
x=steel_timestamp,
name='Steel deals price',
mode='lines+markers')
print(steel_lp)
data = [steel_lp]
layout = dict(
title="Chat Wars Deals",
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=1,
label='1m',
step='month',
stepmode='backward'),
dict(count=6,
label='6m',
step='month',
stepmode='backward'),
dict(step='all')
])
),
rangeslider=dict(),
type='date'
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig, filename = "Chat Wars Deals")
#plotly.offline.plot(
# {
# 'data': data,
# 'layout': layout
# },
# filename=r"test.html", auto_open=True)