Spaces:
Sleeping
Sleeping
Chiragkumar Savani
commited on
Commit
•
a7ad55c
1
Parent(s):
42c790d
Colorise only if close price is relevant
Browse files
app.py
CHANGED
@@ -45,14 +45,22 @@ def last_thursday(dt):
|
|
45 |
return last_day_of_month - pd.Timedelta(days=offset)
|
46 |
|
47 |
|
48 |
-
def check_condition_passed(df, column_name, max_index, output_value, is_high = True):
|
49 |
if is_high:
|
50 |
filtered_df = df[(df.index < max_index) & (df[column_name] > output_value)]
|
51 |
else:
|
52 |
filtered_df = df[(df.index < max_index) & (df[column_name] < output_value)]
|
53 |
|
54 |
if not filtered_df.empty:
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
else:
|
57 |
return False
|
58 |
|
@@ -74,6 +82,10 @@ def process_csv(file):
|
|
74 |
if LOW_NAME not in df.columns:
|
75 |
LOW_NAME = "LOW"
|
76 |
|
|
|
|
|
|
|
|
|
77 |
DATE_NAME = "DATE"
|
78 |
if DATE_NAME not in df.columns:
|
79 |
DATE_NAME = "Date"
|
@@ -136,7 +148,7 @@ def process_csv(file):
|
|
136 |
style_df = set_cell_color(style_df, index=rows[j], column=column_name, hex_color=color)
|
137 |
|
138 |
# check if there is higher or lower value, if yes, then colorize it
|
139 |
-
response = check_condition_passed(df, column_name, rows[j], output_value, 'high' in column_name.lower())
|
140 |
if response:
|
141 |
style_df = set_cell_color(style_df, index=rows[j], column=result_column_name, hex_color=color)
|
142 |
break
|
|
|
45 |
return last_day_of_month - pd.Timedelta(days=offset)
|
46 |
|
47 |
|
48 |
+
def check_condition_passed(df, column_name, max_index, output_value, close_column, value1, value2, is_high = True):
|
49 |
if is_high:
|
50 |
filtered_df = df[(df.index < max_index) & (df[column_name] > output_value)]
|
51 |
else:
|
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 close_value > value1 and close_value > value2:
|
60 |
+
return True
|
61 |
+
else:
|
62 |
+
if close_value < value1 and close_value < value2:
|
63 |
+
return True
|
64 |
else:
|
65 |
return False
|
66 |
|
|
|
82 |
if LOW_NAME not in df.columns:
|
83 |
LOW_NAME = "LOW"
|
84 |
|
85 |
+
CLOSE_NAME = "CLOSE PRICE"
|
86 |
+
if CLOSE_NAME not in df.columns:
|
87 |
+
CLOSE_NAME = "close"
|
88 |
+
|
89 |
DATE_NAME = "DATE"
|
90 |
if DATE_NAME not in df.columns:
|
91 |
DATE_NAME = "Date"
|
|
|
148 |
style_df = set_cell_color(style_df, index=rows[j], column=column_name, hex_color=color)
|
149 |
|
150 |
# check if there is higher or lower value, if yes, then colorize it
|
151 |
+
response = check_condition_passed(df, column_name, rows[j], output_value, CLOSE_NAME, df.loc[rows[i], column_name], df.loc[rows[j], column_name], 'high' in column_name.lower())
|
152 |
if response:
|
153 |
style_df = set_cell_color(style_df, index=rows[j], column=result_column_name, hex_color=color)
|
154 |
break
|