graph.py
2.52 KB
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
import sys
from PyQt5.QtWidgets import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from sqlalchemy import create_engine
from library.cf import *
class Graph(QDialog):
def __init__(self,num=1):
QDialog.__init__(self,None)
self.setGeometry(200,200,1000,800)
self.engine1 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" +
db_ip + ":" + db_port + "/simul1", encoding='utf-8')
self.engine2 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" +
db_ip + ":" + db_port + "/simul2", encoding='utf-8')
self.engine3 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" +
db_ip + ":" + db_port + "/simul3", encoding='utf-8')
self.engine4 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" +
db_ip + ":" + db_port + "/simul4", encoding='utf-8')
date,data=self.getAlgorithm(num)
col=""
if num==1:
col="red"
elif num==2:
col="blue"
elif num==3:
col="green"
elif num==4:
col="purple"
N = len(data)
value = data
ind = np.arange(N)
width = 0.35
self.fig = plt.Figure()
ax = self.fig.add_subplot(111)
ax.bar(ind, value, width,color=col)
ax.set_xticks(ind + width / 20)
ax.set_xticklabels(date)
canvas = FigureCanvas(self.fig)
canvas.draw()
lay=QVBoxLayout()
self.setLayout(lay)
lay.addWidget(canvas)
canvas.show()
def getdata(self,engine):
query="select date, sum_valuation_profit from jango_data order by date"
result=engine.execute(query).fetchall()
date=list()
data=list()
for i in range(len(result)):
date.append(result[i][0])
data.append(int(result[i][1]))
return date,data
def getAlgorithm(self,num):
if num==1:
engine=self.engine1
elif num==2:
engine=self.engine2
elif num==3:
engine=self.engine3
elif num==4:
engine=self.engine4
else:
sys.exit()
date,data=self.getdata(engine)
return date,data
if __name__=="__main__":
app=QApplication(sys.argv)
main_dialog=Graph()
main_dialog.show()
app.exec_()