Spaces:
Sleeping
Sleeping
Chiragkumar Savani
commited on
Commit
•
98eb0b6
1
Parent(s):
a7ad55c
Use proper conditioning
Browse files
app.py
CHANGED
@@ -46,23 +46,44 @@ def last_thursday(dt):
|
|
46 |
|
47 |
|
48 |
def check_condition_passed(df, column_name, max_index, output_value, close_column, value1, value2, is_high = True):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
filtered_df = df[(df.index < max_index) & (df[column_name] < output_value)]
|
53 |
-
|
54 |
-
if not filtered_df.empty:
|
55 |
-
first_valid_row = filtered_df.iloc[0]
|
56 |
-
close_value = first_valid_row[close_column]
|
57 |
-
|
58 |
if is_high:
|
59 |
-
if
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
else:
|
62 |
-
if
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def get_output_value(value1, value2, is_high=False):
|
68 |
if is_high:
|
@@ -91,7 +112,7 @@ def process_csv(file):
|
|
91 |
DATE_NAME = "Date"
|
92 |
|
93 |
# Add three empty columns between LOW PRICE and CLOSE PRICE
|
94 |
-
low_price_index = df.columns.get_loc(
|
95 |
df.insert(low_price_index + 1, 'HIGH Result', '')
|
96 |
df.insert(low_price_index + 2, 'LOW Result', '')
|
97 |
df.insert(low_price_index + 3, 'Empty Column', '')
|
@@ -114,7 +135,7 @@ def process_csv(file):
|
|
114 |
# Insert an empty row
|
115 |
df = pd.concat([df.iloc[:idx], pd.DataFrame([{'Separator': 'Separator'}]), df.iloc[idx:]]).reset_index(drop=True)
|
116 |
|
117 |
-
price_columns = [HIGH_NAME, LOW_NAME]
|
118 |
df[price_columns] = df[price_columns].replace({',': ''}, regex=True).apply(pd.to_numeric, errors='coerce')
|
119 |
|
120 |
# Calculate global thresholds for HIGH PRICE and LOW PRICE columns
|
@@ -167,10 +188,11 @@ def process_csv(file):
|
|
167 |
df[DATE_NAME] = df[DATE_NAME].dt.strftime('%d-%b-%Y')
|
168 |
# df['Last_Thursday'] = df['Last_Thursday'].dt.strftime('%d-%b-%Y')
|
169 |
|
170 |
-
styled_df = df.style.apply(lambda _: style_df, axis=None)
|
171 |
|
|
|
172 |
styled_df.to_excel(output_file, engine='openpyxl', index=False)
|
173 |
|
|
|
174 |
return output_file
|
175 |
|
176 |
# Gradio Interface
|
|
|
46 |
|
47 |
|
48 |
def check_condition_passed(df, column_name, max_index, output_value, close_column, value1, value2, is_high = True):
|
49 |
+
# print(f"Max index: {max_index}")
|
50 |
+
for index_maybe in range(max_index-1, -1, -1):
|
51 |
+
# print(f"At index : {index_maybe}")
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
if is_high:
|
53 |
+
if df.loc[index_maybe, column_name] > output_value:
|
54 |
+
close_value = df.loc[index_maybe, close_column]
|
55 |
+
# print(f"current value: {df.loc[index_maybe, column_name]} - close value {close_value}")
|
56 |
+
if close_value > value1 and close_value > value2:
|
57 |
+
return True
|
58 |
+
break
|
59 |
else:
|
60 |
+
if df.loc[index_maybe, column_name] < output_value:
|
61 |
+
close_value = df.loc[index_maybe, close_column]
|
62 |
+
if close_value < value1 and close_value < value2:
|
63 |
+
return True
|
64 |
+
break
|
65 |
+
return False
|
66 |
+
|
67 |
+
# if is_high:
|
68 |
+
# filtered_df = df[(df.index < max_index) & (df[column_name] > output_value)]
|
69 |
+
# else:
|
70 |
+
# filtered_df = df[(df.index < max_index) & (df[column_name] < output_value)]
|
71 |
+
|
72 |
+
# if not filtered_df.empty:
|
73 |
+
# first_valid_row = filtered_df.iloc[0]
|
74 |
+
|
75 |
+
# print(f"Respective close row: {first_valid_row}")
|
76 |
+
# close_value = first_valid_row[close_column]
|
77 |
+
# print(f"Respective close value: {close_value}")
|
78 |
+
|
79 |
+
# if is_high:
|
80 |
+
# if close_value > value1 and close_value > value2:
|
81 |
+
# return True
|
82 |
+
# else:
|
83 |
+
# if close_value < value1 and close_value < value2:
|
84 |
+
# return True
|
85 |
+
# else:
|
86 |
+
# return False
|
87 |
|
88 |
def get_output_value(value1, value2, is_high=False):
|
89 |
if is_high:
|
|
|
112 |
DATE_NAME = "Date"
|
113 |
|
114 |
# Add three empty columns between LOW PRICE and CLOSE PRICE
|
115 |
+
low_price_index = df.columns.get_loc(CLOSE_NAME)
|
116 |
df.insert(low_price_index + 1, 'HIGH Result', '')
|
117 |
df.insert(low_price_index + 2, 'LOW Result', '')
|
118 |
df.insert(low_price_index + 3, 'Empty Column', '')
|
|
|
135 |
# Insert an empty row
|
136 |
df = pd.concat([df.iloc[:idx], pd.DataFrame([{'Separator': 'Separator'}]), df.iloc[idx:]]).reset_index(drop=True)
|
137 |
|
138 |
+
price_columns = [HIGH_NAME, LOW_NAME, CLOSE_NAME]
|
139 |
df[price_columns] = df[price_columns].replace({',': ''}, regex=True).apply(pd.to_numeric, errors='coerce')
|
140 |
|
141 |
# Calculate global thresholds for HIGH PRICE and LOW PRICE columns
|
|
|
188 |
df[DATE_NAME] = df[DATE_NAME].dt.strftime('%d-%b-%Y')
|
189 |
# df['Last_Thursday'] = df['Last_Thursday'].dt.strftime('%d-%b-%Y')
|
190 |
|
|
|
191 |
|
192 |
+
styled_df = df.style.apply(lambda _: style_df, axis=None)
|
193 |
styled_df.to_excel(output_file, engine='openpyxl', index=False)
|
194 |
|
195 |
+
|
196 |
return output_file
|
197 |
|
198 |
# Gradio Interface
|