]> ToastFreeware Gitweb - chrisu/seepark.git/commitdiff
Fix error in PDF report generation when no water data is available.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 20 Aug 2025 19:49:57 +0000 (21:49 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 20 Aug 2025 19:49:57 +0000 (21:49 +0200)
web/seepark_web.py

index d7f25c522a281f4d110440bf812fa2d7c551ea2e..a2d77063d44384a6049c039f77099826b015b7a5 100644 (file)
@@ -394,12 +394,15 @@ def report(year, month):
                 x, y = data
                 for d in days_datetime:
                     report_datetime = datetime.datetime.combine(d.date(), t)
-                    closest_index = np.argmin(np.abs(x - report_datetime))
-                    if abs(x[closest_index] - report_datetime) > datetime.timedelta(hours=1):
+                    if len(x) == 0:
                         cell = 'N/A'
                     else:
-                        value = y[closest_index]
-                        cell = '{:.1f}'.format(value)
+                        closest_index = np.argmin(np.abs(x - report_datetime))
+                        if abs(x[closest_index] - report_datetime) > datetime.timedelta(hours=1):
+                            cell = 'N/A'
+                        else:
+                            value = y[closest_index]
+                            cell = '{:.1f}'.format(value)
                     row_cells.append(cell)
                 cells.append(row_cells)
         row_colors = list(ntimes(report_colors + ['w'], len(report_times)))