Spaces:
Runtime error
Runtime error
cyberosa
commited on
Commit
Β·
e5eef4b
1
Parent(s):
a9231a0
added a fix, if no current week data then take prev week data
Browse files- tabs/daily_graphs.py +14 -3
tabs/daily_graphs.py
CHANGED
|
@@ -22,7 +22,7 @@ color_mapping = [
|
|
| 22 |
def get_current_week_data(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 23 |
# Get current date
|
| 24 |
now = datetime.now()
|
| 25 |
-
|
| 26 |
# Get start of the current week (Monday)
|
| 27 |
start_of_week = now - timedelta(days=now.weekday())
|
| 28 |
start_of_week = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
@@ -33,11 +33,22 @@ def get_current_week_data(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 33 |
end_of_week = end_of_week.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 34 |
# print(f"end of the week = {end_of_week}")
|
| 35 |
trades_df["creation_date"] = pd.to_datetime(trades_df["creation_date"])
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
(trades_df["creation_date"] >= start_of_week)
|
| 39 |
& (trades_df["creation_date"] <= end_of_week)
|
| 40 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def get_boxplot_daily_metrics(
|
|
|
|
| 22 |
def get_current_week_data(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 23 |
# Get current date
|
| 24 |
now = datetime.now()
|
| 25 |
+
# this is a fix til we have
|
| 26 |
# Get start of the current week (Monday)
|
| 27 |
start_of_week = now - timedelta(days=now.weekday())
|
| 28 |
start_of_week = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
| 33 |
end_of_week = end_of_week.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 34 |
# print(f"end of the week = {end_of_week}")
|
| 35 |
trades_df["creation_date"] = pd.to_datetime(trades_df["creation_date"])
|
| 36 |
+
# check that we have data in the current week, if not, take previous week
|
| 37 |
+
current_week_data = trades_df[
|
| 38 |
(trades_df["creation_date"] >= start_of_week)
|
| 39 |
& (trades_df["creation_date"] <= end_of_week)
|
| 40 |
]
|
| 41 |
+
if len(current_week_data) > 0:
|
| 42 |
+
return current_week_data
|
| 43 |
+
prev_monday = start_of_week - timedelta(days=7)
|
| 44 |
+
prev_monday = prev_monday.replace(hour=0, minute=0, second=0, microsecond=0)
|
| 45 |
+
prev_sunday = prev_monday + timedelta(days=6)
|
| 46 |
+
prev_sunday = prev_sunday.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 47 |
+
prev_week_data = trades_df[
|
| 48 |
+
(trades_df["creation_date"] >= prev_monday)
|
| 49 |
+
& (trades_df["creation_date"] <= prev_sunday)
|
| 50 |
+
]
|
| 51 |
+
return prev_week_data
|
| 52 |
|
| 53 |
|
| 54 |
def get_boxplot_daily_metrics(
|