diff --git a/src/View/Results/CustomPlot/Plot.py b/src/View/Results/CustomPlot/Plot.py index a539112a8650a99ad764b297c90842a4023abe30..4712c45bb97f814f6520df95a1c107d103dd57c7 100644 --- a/src/View/Results/CustomPlot/Plot.py +++ b/src/View/Results/CustomPlot/Plot.py @@ -19,6 +19,7 @@ import logging from functools import reduce +from datetime import datetime from tools import timer from View.Tools.PamhyrPlot import PamhyrPlot @@ -139,6 +140,46 @@ class CustomPlot(PamhyrPlot): color='r', ) + def _customize_x_axes_time(self, ts, mode="time"): + # Custom time display + nb = len(ts) + mod = int(nb / 5) + mod = mod if mod > 0 else nb + + fx = list( + map( + lambda x: x[1], + filter( + lambda x: x[0] % mod == 0, + enumerate(ts) + ) + ) + ) + + if mode == "time": + t0 = datetime.fromtimestamp(0) + xt = list( + map( + lambda v: ( + str( + datetime.fromtimestamp(v) - t0 + ).split(",")[0] + .replace("days", self._trad["days"]) + .replace("day", self._trad["day"]) + ), + fx + ) + ) + else: + xt = list( + map( + lambda v: str(datetime.fromtimestamp(v).date()), + fx + ) + ) + + self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45) + def _draw_time(self): results = self.data reach = results.river.reach(self._reach) @@ -213,6 +254,8 @@ class CustomPlot(PamhyrPlot): color='r', ) + self._customize_x_axes_time(ts) + @timer def draw(self): self.canvas.axes.cla() diff --git a/src/View/Results/translate.py b/src/View/Results/translate.py index ae9dcad17d28dff1c7b8bc28196eb6eecc2447e3..4de61cc7b6c24b227ec7164fa390777b4f807b34 100644 --- a/src/View/Results/translate.py +++ b/src/View/Results/translate.py @@ -27,6 +27,13 @@ class ResultsTranslate(PamhyrTranslate): def __init__(self): super(ResultsTranslate, self).__init__() + self._dict['day'] = _translate( + "Results", "day" + ) + self._dict['days'] = _translate( + "Results", "days" + ) + self._sub_dict["table_headers_reach"] = { "name": _translate("Results", "Reach name"), }