Commit ca8dc19c authored by Theophile Terraz's avatar Theophile Terraz
Browse files

work on export CSV compare results

No related merge requests found
Showing with 17 additions and 15 deletions
+17 -15
# CustomPlotValuesSelectionDialog.py -- Pamhyr # CustomExportAdis.py -- Pamhyr
# Copyright (C) 2023-2024 INRAE # Copyright (C) 2023-2025 INRAE
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
......
...@@ -59,6 +59,7 @@ from View.Results.CustomPlot.Plot import CustomPlot ...@@ -59,6 +59,7 @@ from View.Results.CustomPlot.Plot import CustomPlot
from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import ( from View.Results.CustomPlot.CustomPlotValuesSelectionDialog import (
CustomPlotValuesSelectionDialog, CustomPlotValuesSelectionDialog,
) )
from View.Results.CustomExport.CustomExport import CustomExportDialog
from View.Results.Table import TableModel from View.Results.Table import TableModel
from View.Results.translate import ( from View.Results.translate import (
...@@ -665,9 +666,9 @@ class ResultsWindow(PamhyrWindow): ...@@ -665,9 +666,9 @@ class ResultsWindow(PamhyrWindow):
def _export(self): def _export(self):
dlg = CustomPlotValuesSelectionDialog(parent=self) dlg = CustomExportDialog(parent=self)
if dlg.exec(): if dlg.exec():
x, y, envelop = dlg.value x, y, envelop, solver_id = dlg.value
else: else:
return return
...@@ -677,26 +678,26 @@ class ResultsWindow(PamhyrWindow): ...@@ -677,26 +678,26 @@ class ResultsWindow(PamhyrWindow):
) )
self.file_dialog( self.file_dialog(
select_file="AnyFile", select_file="AnyFile",
callback=lambda f: self.export_to(f[0], x, y, envelop), callback=lambda f: self.export_to(f[0], x, y, envelop, solver_id),
default_suffix=".csv", default_suffix=".csv",
file_filter=["CSV (*.csv)"], file_filter=["CSV (*.csv)"],
) )
def export_to(self, filename, x, y, envelop): def export_to(self, filename, x, y, envelop, solver_id):
results = self._results[self._current_results[0]] results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()] reach = results.river.reachs[self._get_current_reach()]
first_line = [f"Study: {results.study.name}", first_line = [f"Study: {results.study.name}",
f"Reach: {reach.name}"] f"Reach: {reach.name}"]
if x == "rk": if x == "rk":
timestamp = self._get_current_timestamp() timestamp = self._get_current_timestamp()
first_line.append(f"Time: {timestamp}s") first_line.append(f"Time: {timestamp}s")
val_dict = self._export_rk(timestamp, y, envelop) val_dict = self._export_rk(timestamp, y, envelop, solver_id)
elif x == "time": elif x == "time":
profile_id = self._get_current_profile() profile_id = self._get_current_profile()
profile = reach.profile(profile_id) profile = reach.profile(profile_id)
pname = profile.name if profile.name != "" else profile.rk pname = profile.name if profile.name != "" else profile.rk
first_line.append(f"Profile: {pname}") first_line.append(f"Profile: {pname}")
val_dict = self._export_time(profile_id, y) val_dict = self._export_time(profile_id, y, solver_id)
with open(filename, 'w', newline='') as csvfile: with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', writer = csv.writer(csvfile, delimiter=',',
...@@ -752,8 +753,8 @@ class ResultsWindow(PamhyrWindow): ...@@ -752,8 +753,8 @@ class ResultsWindow(PamhyrWindow):
self._additional_plot.pop(tab_widget.tabText(index)) self._additional_plot.pop(tab_widget.tabText(index))
tab_widget.removeTab(index) tab_widget.removeTab(index)
def _export_rk(self, timestamp, y, envelop): def _export_rk(self, timestamp, y, envelop, solver_id):
results = self._results[self._current_results[0]] results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()] reach = results.river.reachs[self._get_current_reach()]
dict_x = self._trad.get_dict("values_x") dict_x = self._trad.get_dict("values_x")
dict_y = self._trad.get_dict("values_y") dict_y = self._trad.get_dict("values_y")
...@@ -997,8 +998,8 @@ class ResultsWindow(PamhyrWindow): ...@@ -997,8 +998,8 @@ class ResultsWindow(PamhyrWindow):
return my_dict return my_dict
def _export_time(self, profile, y): def _export_time(self, profile, y, solver_id):
results = self._results[self._current_results[0]] results = self._results[solver_id]
reach = results.river.reachs[self._get_current_reach()] reach = results.river.reachs[self._get_current_reach()]
profile = reach.profile(profile) profile = reach.profile(profile)
dict_x = self._trad.get_dict("values_x") dict_x = self._trad.get_dict("values_x")
......
...@@ -42,7 +42,8 @@ class ResultsTranslate(MainTranslate): ...@@ -42,7 +42,8 @@ class ResultsTranslate(MainTranslate):
self._dict['day'] = _translate("Results", "day") self._dict['day'] = _translate("Results", "day")
self._dict['days'] = _translate("Results", "days") self._dict['days'] = _translate("Results", "days")
self._dict['envelop'] = _translate("Results", "envelop") self._dict['envelop'] = _translate("Results", "Envelop")
self._dict['solver'] = _translate("Results", "Solver")
self._dict['x'] = _translate("Results", "X (m)") self._dict['x'] = _translate("Results", "X (m)")
...@@ -67,7 +68,7 @@ class ResultsTranslate(MainTranslate): ...@@ -67,7 +68,7 @@ class ResultsTranslate(MainTranslate):
} }
self._sub_dict["table_headers_solver"] = { self._sub_dict["table_headers_solver"] = {
"solver": _translate("Results", "Solver"), "solver": self._dict['solver'],
} }
self._sub_dict["table_headers_pollutants"] = { self._sub_dict["table_headers_pollutants"] = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment