Skip to content

Commit

Permalink
feat: remove time of day from label when midnight or noon
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Sep 1, 2022
1 parent 727060d commit 830841c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions popmon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion popmon/visualization/alert_section_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions popmon/visualization/histogram_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
]
Expand Down
2 changes: 1 addition & 1 deletion popmon/visualization/section_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion popmon/visualization/traffic_light_section_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 830841c

Please sign in to comment.