-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathScrip_Count_Display.py
More file actions
206 lines (173 loc) · 8.78 KB
/
Copy pathScrip_Count_Display.py
File metadata and controls
206 lines (173 loc) · 8.78 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import PySimpleGUI as sg
import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from Utils import process, processnewfiles, convertdataframe
backdays=5
optionMaxOccurence=5
df_bull=pd.DataFrame()
df_bear=pd.DataFrame()
df_intrabull=pd.DataFrame()
df_intrabear=pd.DataFrame()
df_global = pd.DataFrame()
def create_seaborn_plot():
matrix = np.random.randint(20, size=(10, 10))
figure = Figure(figsize=(3, 3))
ax = figure.subplots()
ax.cla()
sns.heatmap(matrix, square=True, cbar=False, ax=ax)
return figure
def oncombochange():
global df_bull
global df_bear
global df_intrabull
global df_intrabear
df_bull=pd.DataFrame()
df_bear=pd.DataFrame()
df_intrabull=pd.DataFrame()
df_intrabear=pd.DataFrame()
bullish,bearish,intradaybullish,intradaybearish=process(backdays)
''' if bullish.empty == False:
df_bull = convertdataframe(bullish)
if bearish.empty == False:
df_bear = convertdataframe(bearish)
if intradaybullish.empty == False:
df_intrabull = convertdataframe(intradaybullish)
if intradaybearish.empty == False:
df_intrabear = convertdataframe(intradaybearish) '''
def convertdataframe(df):
#if df is not None :
if df.empty == False:
df['OccurInDiffScreeners'] = df.groupby(by="nsecode")['nsecode'].transform('count')
df = df.query(f'OccurInDiffScreeners >{optionMaxOccurence}')
df.drop(['sr','per_chg','close','bsecode','volume'],axis=1,inplace=True)
grp_bullish = df.groupby("nsecode",as_index=False)['OccurInDiffScreeners'].max()
grp_bullish = grp_bullish[grp_bullish['OccurInDiffScreeners'] >optionMaxOccurence].sort_values(['OccurInDiffScreeners'],ascending=False)
return grp_bullish
Dateslist = [day for day in np.arange(1,60,1)]
layouttop = [[sg.Text('How many days of BackTracked Data to Display:'),sg.Combo(values=Dateslist,
size=(20, 7),
enable_events=True,
key="-COMBOBOX-",font="Helvetica 12",
metadata=[]),sg.Button("Get Data",key='-GETDATA-'),sg.Button("Graphical View",key='-GETDATAGRAPH-'),
[sg.Canvas(size=(300, 300), key="-CANVAS-")]
]]
layouttoprow = [sg.Text("Bullish Scrips ======> "),sg.Table(values=df_bull.values.tolist(), headings=['NseCode','NumberOfOccurencesinScreeners'],auto_size_columns=False,
display_row_numbers=False,
justification='center',
right_click_selects=True,
max_col_width=10,
col_widths=10, #list(map(lambda x:len(x)+1, headings)),
vertical_scroll_only = False,
alternating_row_color='DarkGreen',
num_rows=15,
key='-TABLE-BULL-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True, # Comment out to not enable header and other clicks
tooltip='This table displays the bullish count'),sg.Canvas(key='-CANVAS1-'),
sg.Text("Bearish Scrips =======> "),sg.Table(values=df_bear.values.tolist(), headings=['NseCode','NumberOfOccurencesinScreeners'],auto_size_columns=False,
display_row_numbers=False,
justification='center',
right_click_selects=True,
max_col_width=10,
col_widths=10, #list(map(lambda x:len(x)+1, headings)),
vertical_scroll_only = False,
alternating_row_color='DarkRed',
num_rows=15,
key='-TABLE-BEAR-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True, # Comment out to not enable header and other clicks
tooltip='This table displays the bearish count')
]
layoutbottomrow = [sg.Text("IntraDay Bullish Scrips==>"),
sg.Table(values=df_intrabull.values.tolist(), headings=['NseCode','NumberOfOccurencesinScreeners'],auto_size_columns=False,
display_row_numbers=False,
justification='center',
right_click_selects=True,
max_col_width=10,
col_widths=10, #list(map(lambda x:len(x)+1, headings)),
vertical_scroll_only = False,
alternating_row_color='LightGreen',
num_rows=15,
key='-TABLE-INTRABULL-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True, # Comment out to not enable header and other clicks
tooltip='This table displays the bullish count'),
sg.Text("IntraDay Bearish Scrips ==> "),
sg.Table(values=df_intrabear.values.tolist(), headings=['NseCode','NumberOfOccurencesinScreeners'],auto_size_columns=False,
display_row_numbers=False,
justification='center',
right_click_selects=True,
max_col_width=10,
col_widths=10, #list(map(lambda x:len(x)+1, headings)),
vertical_scroll_only = False,
alternating_row_color='Red',
num_rows=15,
key='-TABLE-INTRABEAR-',
selected_row_colors='red on yellow',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True, # Comment out to not enable header and other clicks
tooltip='This table displays the bearish count')
]
layout = [layouttop,layouttoprow,layoutbottomrow]
# ------ Create Window ------
window = sg.Window('The Table Element', layout,
resizable=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT, finalize=True,font="Helvetica 12")
while True:
event, values = window.read(timeout=2000)
if event == sg.TIMEOUT_EVENT:
#print(event, values)
if ~df_bull.empty:
window['-TABLE-BULL-'].update(values=df_bull.values.tolist())
if ~df_bear.empty:
window['-TABLE-BEAR-'].update(values=df_bear.values.tolist())
if ~df_intrabull.empty:
window['-TABLE-INTRABULL-'].update(values=df_intrabull.values.tolist())
if ~df_intrabear.empty:
window['-TABLE-INTRABEAR-'].update(values=df_intrabear.values.tolist())
#pass
elif event == '-COMBOBOX-':
backdays=values['-COMBOBOX-']
elif event == '-GETDATA-':
backdays=values['-COMBOBOX-']
oncombochange()
if ~df_bull.empty:
window['-TABLE-BULL-'].update(values=df_bull.values.tolist())
if ~df_bear.empty:
window['-TABLE-BEAR-'].update(values=df_bear.values.tolist())
if ~df_intrabull.empty:
window['-TABLE-INTRABULL-'].update(values=df_intrabull.values.tolist())
if ~df_intrabear.empty:
window['-TABLE-INTRABEAR-'].update(values=df_intrabear.values.tolist())
''' window['-TABLE-BULL-'].update(row_colors='green')
window['-TABLE-INTRABULL-'].update(row_colors='green')
window['-TABLE-BEAR-'].update(row_colors='red')
window['-TABLE-INTRABEAR-'].update(row_colors='red') '''
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == '-GETDATAGRAPH-':
if ~df_bull.empty :
fig = create_seaborn_plot()
canvas_elem = sg.Canvas(size=(300, 300), key="-CANVAS-")
canvas = FigureCanvasTkAgg(fig, canvas_elem.Widget)
canvas.draw()
window["-CANVAS-"].Widget.pack(fill="both", expand=True)
#window['-CANVAS1-'].update(values=df_bull.value_counts().plot.bar())
if event == 'Edit Me':
sg.execute_editor(__file__)
elif event == 'Version':
sg.popup_scrolled(__file__, sg.get_versions(), location=window.current_location(), keep_on_top=True, non_blocking=True)
window.close()