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):
actions = {
"action_reload": self._reload,
"action_add": self._add_custom_plot,
"action_export": self.export,
# "action_export": self.export,
"action_export": self.export_current,
}
for action in actions:
......@@ -591,12 +592,15 @@ class ResultsWindow(PamhyrWindow):
)
def export_to(self, directory):
timestamps = sorted(self._results.get("timestamps"))
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 = name.replace(" ", "-")
if len(timestamps) == 1:
name = f"{name}_t{timestamps[0]}"
file_name = os.path.join(
directory,
......@@ -606,28 +610,40 @@ class ResultsWindow(PamhyrWindow):
with open(file_name, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["name", "rk", "data-file"])
for profile in reach.profiles:
p_file_name = os.path.join(
directory,
f"cs_{profile.geometry.id}.csv"
)
writer.writerow([
profile.name,
profile.rk,
p_file_name
])
self.export_profile(reach, profile, p_file_name)
def export_profile(self, reach, profile, file_name):
if len(timestamps) > 1:
writer.writerow(["name", "rk", "data-file"])
for profile in reach.profiles:
p_file_name = os.path.join(
directory,
f"cs_{profile.geometry.id}.csv"
)
writer.writerow([
profile.name,
profile.rk,
p_file_name
])
self.export_profile(reach,
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:
writer = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["timestamp", "z", "q"])
timestamps = sorted(self._results.get("timestamps"))
for ts in timestamps:
writer.writerow([
......@@ -635,3 +651,13 @@ class ResultsWindow(PamhyrWindow):
profile.get_ts_key(ts, "Z"),
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