diff --git a/popmon/utils.py b/popmon/utils.py index 8487663d..20995c76 100644 --- a/popmon/utils.py +++ b/popmon/utils.py @@ -21,14 +21,24 @@ from textwrap import shorten from typing import Callable, List, Optional +import pandas as pd from joblib import Parallel, delayed -def short_date(date: str): +def short_date(date): """ Shorten date string to length of 22 """ - return shorten(date, width=22, placeholder="") + if isinstance(date, pd.Timestamp): + # Drop the time of day when midnight or noon + if date.hour in [0, 12] and date.minute == 0 and date.second == 0: + d = str(date).split(" ")[0] + else: + d = str(date) + else: + d = str(date) + + return shorten(d, width=22, placeholder="") def filter_metrics( diff --git a/popmon/visualization/alert_section_generator.py b/popmon/visualization/alert_section_generator.py index 7b5e17a5..c76728c7 100644 --- a/popmon/visualization/alert_section_generator.py +++ b/popmon/visualization/alert_section_generator.py @@ -126,7 +126,7 @@ def transform( inplace=True, errors="ignore", ) - dates = [short_date(str(date)) for date in df.index.tolist()] + dates = [short_date(date) for date in df.index.tolist()] metrics = filter_metrics( df.columns, self.ignore_stat_endswith, self.show_stats diff --git a/popmon/visualization/histogram_section.py b/popmon/visualization/histogram_section.py index 5f6f6e95..64aae482 100644 --- a/popmon/visualization/histogram_section.py +++ b/popmon/visualization/histogram_section.py @@ -112,7 +112,7 @@ def transform(self, data_obj: dict, sections: Optional[list] = None): continue # base64 heatmap plot for each metric - dates = [short_date(str(date)) for date in df.index[:]] + dates = [short_date(date) for date in df.index[:]] hists = [ df[hist_names].iloc[-i].values for i in reversed(range(1, len(dates) + 1)) @@ -131,7 +131,7 @@ def transform(self, data_obj: dict, sections: Optional[list] = None): ) # get base64 encoded plot for each metric; do parallel processing to speed up. - dates = [short_date(str(date)) for date in df.index[-last_n:]] + dates = [short_date(date) for date in df.index[-last_n:]] hists = [ df[hist_names].iloc[-i].values for i in reversed(range(1, last_n + 1)) ] diff --git a/popmon/visualization/section_generator.py b/popmon/visualization/section_generator.py index b16821c1..0b1afbfd 100644 --- a/popmon/visualization/section_generator.py +++ b/popmon/visualization/section_generator.py @@ -174,7 +174,7 @@ def transform( inplace=True, errors="ignore", ) - dates = np.array([short_date(str(date)) for date in df.index.tolist()]) + dates = np.array([short_date(date) for date in df.index.tolist()]) metrics = filter_metrics( df.columns, self.ignore_stat_endswith, self.show_stats diff --git a/popmon/visualization/traffic_light_section_generator.py b/popmon/visualization/traffic_light_section_generator.py index 1b282a6f..6d813339 100644 --- a/popmon/visualization/traffic_light_section_generator.py +++ b/popmon/visualization/traffic_light_section_generator.py @@ -125,7 +125,7 @@ def transform( inplace=True, errors="ignore", ) - dates = [short_date(str(date)) for date in df.index.tolist()] + dates = [short_date(date) for date in df.index.tolist()] metrics = sorted( filter_metrics(df.columns, self.ignore_stat_endswith, self.show_stats)