Commit 5e018fc8 authored by Theophile Terraz's avatar Theophile Terraz
Browse files

lighter data export

No related merge requests found
Pipeline #57008 passed with stages
in 6 minutes and 54 seconds
Showing with 46 additions and 20 deletions
+46 -20
...@@ -303,7 +303,8 @@ class ResultsWindow(PamhyrWindow): ...@@ -303,7 +303,8 @@ class ResultsWindow(PamhyrWindow):
actions = { actions = {
"action_reload": self._reload, "action_reload": self._reload,
"action_add": self._add_custom_plot, "action_add": self._add_custom_plot,
"action_export": self.export, # "action_export": self.export,
"action_export": self.export_current,
} }
for action in actions: for action in actions:
...@@ -591,12 +592,15 @@ class ResultsWindow(PamhyrWindow): ...@@ -591,12 +592,15 @@ class ResultsWindow(PamhyrWindow):
) )
def export_to(self, directory): def export_to(self, directory):
timestamps = sorted(self._results.get("timestamps"))
for reach in self._results.river.reachs: for reach in self._results.river.reachs:
self.export_reach(reach, directory) self.export_reach(reach, directory, timestamps)
def export_reach(self, reach, directory): def export_reach(self, reach, directory, timestamps):
name = reach.name name = reach.name
name = name.replace(" ", "-") name = name.replace(" ", "-")
if len(timestamps) == 1:
name = f"{name}_t{timestamps[0]}"
file_name = os.path.join( file_name = os.path.join(
directory, directory,
...@@ -606,28 +610,40 @@ class ResultsWindow(PamhyrWindow): ...@@ -606,28 +610,40 @@ class ResultsWindow(PamhyrWindow):
with open(file_name, 'w', newline='') as csvfile: with open(file_name, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL) quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["name", "rk", "data-file"]) if len(timestamps) > 1:
for profile in reach.profiles: writer.writerow(["name", "rk", "data-file"])
p_file_name = os.path.join( for profile in reach.profiles:
directory, p_file_name = os.path.join(
f"cs_{profile.geometry.id}.csv" directory,
) f"cs_{profile.geometry.id}.csv"
)
writer.writerow([
profile.name, writer.writerow([
profile.rk, profile.name,
p_file_name profile.rk,
]) p_file_name
])
self.export_profile(reach, profile, p_file_name)
self.export_profile(reach,
def export_profile(self, reach, profile, file_name): profile,
p_file_name,
timestamps)
else:
ts = timestamps[0]
writer.writerow(self._table["raw_data"]._headers)
for row in range(self._table["raw_data"].rowCount()):
line = []
for column in range(self._table["raw_data"].columnCount()):
index = self._table["raw_data"].index(row, column)
line.append(self._table["raw_data"].data(index))
writer.writerow(line)
def export_profile(self, reach, profile, file_name, timestamps):
with open(file_name, 'w', newline='') as csvfile: with open(file_name, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL) quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["timestamp", "z", "q"]) writer.writerow(["timestamp", "z", "q"])
timestamps = sorted(self._results.get("timestamps"))
for ts in timestamps: for ts in timestamps:
writer.writerow([ writer.writerow([
...@@ -635,3 +651,13 @@ class ResultsWindow(PamhyrWindow): ...@@ -635,3 +651,13 @@ class ResultsWindow(PamhyrWindow):
profile.get_ts_key(ts, "Z"), profile.get_ts_key(ts, "Z"),
profile.get_ts_key(ts, "Q"), profile.get_ts_key(ts, "Q"),
]) ])
def export_current(self):
self.file_dialog(
select_file=False,
callback=lambda d: self.export_current_to(d[0])
)
def export_current_to(self, directory):
reach = self._results.river.reachs[self._get_current_reach()]
self.export_reach(reach, directory, [self._get_current_timestamp()])
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