From 61fce32c609d0354b8001506d0eb3a9427361c81 Mon Sep 17 00:00:00 2001
From: Theophile Terraz <theophile.terraz@inrae.fr>
Date: Tue, 30 Jul 2024 14:09:29 +0200
Subject: [PATCH] mean water depth

---
 src/Model/Geometry/ProfileXYZ.py | 12 ++++++++++++
 src/View/Results/Table.py        |  9 ++++++---
 src/View/Results/translate.py    |  3 ++-
 src/View/Translate.py            |  4 +++-
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py
index d06728d7..c06a2653 100644
--- a/src/Model/Geometry/ProfileXYZ.py
+++ b/src/Model/Geometry/ProfileXYZ.py
@@ -494,6 +494,18 @@ class ProfileXYZ(Profile, SQLSubModel):
 
         return lines
 
+    def max_water_depth(self, z):
+        return z - self.z_min()
+
+    def mean_water_depth(self, z):
+        a = self.wet_area(z)
+        w = self.wet_width(z)
+
+        if w == 0:
+            return 0
+
+        return a/w
+
     def wet_polygon(self, z):
         points = self.wet_points(z)
         if len(points) < 3:
diff --git a/src/View/Results/Table.py b/src/View/Results/Table.py
index 7b49910c..1088ac26 100644
--- a/src/View/Results/Table.py
+++ b/src/View/Results/Table.py
@@ -96,10 +96,13 @@ class TableModel(PamhyrTableModel):
                 z = self._lst[row].get_ts_key(self._timestamp, "Z")
                 v = self._lst[row].geometry.wet_width(z)
                 return f"{v:.4f}"
-            elif self._headers[column] == "depth":
+            elif self._headers[column] == "max_depth":
                 z = self._lst[row].get_ts_key(self._timestamp, "Z")
-                z_min = self._lst[row].geometry.z_min()
-                v = z - z_min
+                v = self._lst[row].geometry.max_water_depth(z)
+                return f"{v:.4f}"
+            elif self._headers[column] == "mean_depth":
+                z = self._lst[row].get_ts_key(self._timestamp, "Z")
+                v = self._lst[row].geometry.mean_water_depth(z)
                 return f"{v:.4f}"
             elif self._headers[column] == "wet_area":
                 z = self._lst[row].get_ts_key(self._timestamp, "Z")
diff --git a/src/View/Results/translate.py b/src/View/Results/translate.py
index 05ae7d6b..bf96ba13 100644
--- a/src/View/Results/translate.py
+++ b/src/View/Results/translate.py
@@ -59,7 +59,8 @@ class ResultsTranslate(MainTranslate):
             "discharge": self._dict["unit_discharge"],
             "velocity": self._dict["unit_speed"],
             "width": self._dict["unit_width"],
-            "depth": self._dict["unit_height"],
+            "max_depth": self._dict["unit_max_height"],
+            "mean_depth": self._dict["unit_mean_height"],
             "wet_area": self._dict["unit_wet_area"],
             "wet_perimeter": self._dict["unit_wet_perimeter"],
             "hydraulic_radius": self._dict["unit_hydraulic_radius"],
diff --git a/src/View/Translate.py b/src/View/Translate.py
index a9c3d8ee..5df0e944 100644
--- a/src/View/Translate.py
+++ b/src/View/Translate.py
@@ -54,7 +54,9 @@ class UnitTranslate(CommonWordTranslate):
 
         self._dict["unit_rk"] = _translate("Unit", "River Kilometric (m)")
         self._dict["unit_width"] = _translate("Unit", "Width (m)")
-        self._dict["unit_height"] = _translate("Unit", "Height (m)")
+        self._dict["unit_height"] = _translate("Unit", "Depth (m)")
+        self._dict["unit_max_height"] = _translate("Unit", "Max Depth (m)")
+        self._dict["unit_mean_height"] = _translate("Unit", "Mean Depth (m)")
         self._dict["unit_diameter"] = _translate("Unit", "Diameter (m)")
         self._dict["unit_thickness"] = _translate("Unit", "Thickness (m)")
         self._dict["unit_elevation"] = _translate("Unit", "Elevation (m)")
-- 
GitLab