Update preopen_html.py
Browse files- preopen_html.py +12 -9
preopen_html.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from nsepython import *
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
def build_preopen_html(key="NIFTY"):
|
| 5 |
# Fetch pre-open data
|
|
@@ -10,13 +11,15 @@ def build_preopen_html(key="NIFTY"):
|
|
| 10 |
main_df = data_df.iloc[[0]] if not data_df.empty else pd.DataFrame()
|
| 11 |
const_df = data_df.iloc[1:] if len(data_df) > 1 else pd.DataFrame()
|
| 12 |
|
| 13 |
-
# ================= REMOVE
|
| 14 |
-
|
| 15 |
-
return df[[c for c in df.columns if not c.endswith("_x")]]
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# ================= HELPER FUNCTION =================
|
| 22 |
def df_to_html_color(df, metric_col=None):
|
|
@@ -51,8 +54,8 @@ def build_preopen_html(key="NIFTY"):
|
|
| 51 |
def merge_info_main_cards(rem_df, main_df):
|
| 52 |
combined = pd.concat([rem_df, main_df], axis=1)
|
| 53 |
combined = combined.loc[:, ~combined.columns.duplicated()]
|
| 54 |
-
# Remove
|
| 55 |
-
combined = combined[[c for c in combined.columns if not
|
| 56 |
cards_html = '<div class="mini-card-container">'
|
| 57 |
for col in combined.columns:
|
| 58 |
val = combined.at[0, col] if not combined.empty else ""
|
|
@@ -71,7 +74,7 @@ def build_preopen_html(key="NIFTY"):
|
|
| 71 |
cons_html = df_to_html_color(const_df) if not const_df.empty else "<i>No pre-open constituents</i>"
|
| 72 |
|
| 73 |
# ================= Metric tables =================
|
| 74 |
-
metric_cols = [c for c in const_df.columns if pd.api.types.is_numeric_dtype(const_df[c]) and not
|
| 75 |
metric_tables = ""
|
| 76 |
for col in metric_cols:
|
| 77 |
df_const = const_df.copy()
|
|
|
|
| 1 |
from nsepython import *
|
| 2 |
import pandas as pd
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
def build_preopen_html(key="NIFTY"):
|
| 6 |
# Fetch pre-open data
|
|
|
|
| 11 |
main_df = data_df.iloc[[0]] if not data_df.empty else pd.DataFrame()
|
| 12 |
const_df = data_df.iloc[1:] if len(data_df) > 1 else pd.DataFrame()
|
| 13 |
|
| 14 |
+
# ================= REMOVE *_x AND SPECIFIC PATTERNS =================
|
| 15 |
+
pattern_remove = re.compile(r"^(price_|buyQty_|sellQty_|iep_)\d+$")
|
|
|
|
| 16 |
|
| 17 |
+
def remove_pattern_cols(df):
|
| 18 |
+
return df[[c for c in df.columns if not pattern_remove.match(c)]]
|
| 19 |
+
|
| 20 |
+
main_df = remove_pattern_cols(main_df)
|
| 21 |
+
const_df = remove_pattern_cols(const_df)
|
| 22 |
+
rem_df = remove_pattern_cols(rem_df)
|
| 23 |
|
| 24 |
# ================= HELPER FUNCTION =================
|
| 25 |
def df_to_html_color(df, metric_col=None):
|
|
|
|
| 54 |
def merge_info_main_cards(rem_df, main_df):
|
| 55 |
combined = pd.concat([rem_df, main_df], axis=1)
|
| 56 |
combined = combined.loc[:, ~combined.columns.duplicated()]
|
| 57 |
+
# Remove pattern columns
|
| 58 |
+
combined = combined[[c for c in combined.columns if not pattern_remove.match(c)]]
|
| 59 |
cards_html = '<div class="mini-card-container">'
|
| 60 |
for col in combined.columns:
|
| 61 |
val = combined.at[0, col] if not combined.empty else ""
|
|
|
|
| 74 |
cons_html = df_to_html_color(const_df) if not const_df.empty else "<i>No pre-open constituents</i>"
|
| 75 |
|
| 76 |
# ================= Metric tables =================
|
| 77 |
+
metric_cols = [c for c in const_df.columns if pd.api.types.is_numeric_dtype(const_df[c]) and not pattern_remove.match(c)] if not const_df.empty else []
|
| 78 |
metric_tables = ""
|
| 79 |
for col in metric_cols:
|
| 80 |
df_const = const_df.copy()
|