-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.py
141 lines (117 loc) · 5.18 KB
/
2.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from spyre import server
import pandas as pd
from urllib.request import urlopen
import matplotlib.pyplot as plt
import numpy as np
class StockExample(server.App):
title = "Inputs"
inputs = [{ "type":'dropdown',
"label": 'Index ',
"options" : [ {"label": "VCI", "value":"VCI"},
{"label": "TCI", "value":"TCI"},
{"label": "VHI", "value":"VHI"},],
"key": 'index',
"action_id": "update_data"},
{"type": 'dropdown',
"label": 'Region',
"options": [{"label": "Vinnitsya", "value": "1"},
{"label": "Volyn", "value": "2"},
{"label": "Dnipropetrovsk", "value": "3"},
{"label": "Donetsk", "value": "4"},
{"label": "Zhytomyr", "value": "5"},
{"label": "Zacarpathia", "value": "6"},
{"label": "Zaporizhzhya", "value": "7"},
{"label": "Ivano-Frankivsk", "value": "8"},
{"label": "Kiev", "value": "9"},
{"label": "Kirovohrad", "value": "10"},
{"label": "Luhansk", "value": "11"},
{"label": "Lviv", "value": "12"},
{"label": "Mykolayiv", "value": "13"},
{"label": "Odessa", "value": "14"},
{"label": "Poltava", "value": "15"},
{"label": "Rivne", "value": "16"},
{"label": "Sumy", "value": "17"},
{"label": "Ternopil", "value": "18"},
{"label": "Kharkiv", "value": "19"},
{"label": "Kherson", "value": "20"},
{"label": "Khmelnytskyy", "value": "21"},
{"label": "Cherkasy", "value": "22"},
{"label": "Chernivtsi", "value": "23"},
{"label": "Chernihiv", "value": "24"},
{"label": "Crimea", "value": "25"}],
"key": 'region',
"action_id": "update_data"},
{"input_type": "text",
"variable_name": "fyear",
"label": "First Year",
"value": 1990,
"key": 'fyear',
"action_id": "update_data"},
{"input_type": "text",
"variable_name": "lyear",
"label": "Last Year",
"value": 2000,
"key": 'lyear',
"action_id": "update_data"},
{"type": 'slider',
"label": 'First week',
"min": 1, "max": 52, "value": 1,
"key": 'first',
"action_id": 'update_data'},
{"type": 'slider',
"label": 'Last week',
"min": 1, "max": 52, "value": 52,
"key": 'last',
"action_id": 'update_data'}]
controls = [{"type": "hidden",
"id": "update_data"}]
tabs = ["Table","Plot"]
outputs = [{"type": "table",
"id": "table_id",
"control_id": "update_data",
"tab": "Table"},
{"type": "plot",
"id": "plot",
"control_id": "update_data",
"tab": "Plot"}]
def getData(self, params):
print("............")
index = params['index']
region = params['region']
fyear = params['fyear']
lyear = params['lyear']
first = params['first']
last = params['last']
path = r"freshdata/%s.csv" % region
df = pd.read_csv(path)
df1 = df[(df['Year'] >= int(fyear)) & (df['Year'] <= int(lyear)) & (df['Week'] >= int(first)) & (df['Week'] <= int(last))]
df1 = df1[['Year', 'Week', index]]
return df1
def getData1(self, params):
print("............")
index = params['index']
region = params['region']
fyear = params['fyear']
first = params['first']
last = params['last']
path = r"freshdata/%s.csv" % region
df = pd.read_csv(path)
df1 = df[(df['Year'] == int(fyear)) & (df['Week'] >= int(first)) & (df['Week'] <= int(last))]
df1 = df1[['Week', index]]
return df1
def getPlot(self, params):
index = params['index']
region = params['region']
fyear = params['fyear']
lyear = params['lyear']
first = params['first']
last = params['last']
df = self.getData(params).set_index('Week')
df1 = self.getData1(params).set_index('Week')
plt_obj = df1.plot()
plt_obj.set_ylabel(r"%s" % index)
plt_obj.set_title('Index {index} for {fyear} from {first} to {last} weeks'.format(index=index, fyear=int(fyear), first=int(first), last=int(last)))
fig = plt_obj.get_figure()
return fig
app = StockExample()
app.launch()