Results: Display custom time in hydrograph.

mesh
Pierre-Antoine Rouby 2023-08-22 11:03:50 +02:00
parent d7a8e5de20
commit bab1ce9e17
3 changed files with 52 additions and 5 deletions

View File

@ -201,7 +201,7 @@ class Mage(AbstractSolver):
f.write(f"*{header[0]:>9}|{header[1]:>10}\n") f.write(f"*{header[0]:>9}|{header[1]:>10}\n")
for d in bound.data: for d in bound.data:
f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n") f.write(f"{d[0]:10}{d[1]:10}\n")
return files return files

View File

@ -19,6 +19,7 @@
import logging import logging
from functools import reduce from functools import reduce
from datetime import datetime
from tools import timer, trace from tools import timer, trace
from View.Plot.APlot import APlot from View.Plot.APlot import APlot
@ -34,14 +35,14 @@ logger = logging.getLogger()
class PlotH(APlot): class PlotH(APlot):
def __init__(self, canvas=None, results=None, def __init__(self, canvas=None, results=None,
reach_id=0, profile_id=0, reach_id=0, profile_id=0,
toolbar=None, display_current=True): toolbar=None):
super(PlotH, self).__init__( super(PlotH, self).__init__(
canvas=canvas, canvas=canvas,
data=results, data=results,
toolbar=toolbar toolbar=toolbar
) )
self.display_current = display_current self._mode = "time"
self._current_timestamp = max(results.get("timestamps")) self._current_timestamp = max(results.get("timestamps"))
self._current_reach_id = reach_id self._current_reach_id = reach_id
@ -99,6 +100,10 @@ class PlotH(APlot):
) )
return return
self.canvas.axes.set_ylim(
[min(min(y),0), max(y)]
)
self._line = [ self._line = [
self.canvas.axes.plot( self.canvas.axes.plot(
x, y, lw=1., x, y, lw=1.,
@ -107,8 +112,47 @@ class PlotH(APlot):
) )
] ]
self.canvas.axes.autoscale_view(True, True, True) # Custom time display
self.canvas.axes.autoscale() nb = len(x)
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(x)
)
)
)
if self._mode == "time":
t0 = datetime.fromtimestamp(0)
xt = list(
map(
lambda v: (
str(
datetime.fromtimestamp(v) - t0
).split(",")[0]\
.replace("days", _translate("Results", "days"))\
.replace("day", _translate("Results", "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)
# self.canvas.axes.autoscale_view(True, True, True)
# self.canvas.axes.autoscale()
self.canvas.figure.tight_layout() self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle() self.canvas.figure.canvas.draw_idle()
if self.toolbar is not None: if self.toolbar is not None:

View File

@ -28,6 +28,9 @@
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="maximum">
<number>999999</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>