fix csv exporting

master
michael 2021-08-11 16:25:38 -07:00
parent 918944e39e
commit a290f73957
1 changed files with 12 additions and 4 deletions

16
app.py
View File

@ -11,8 +11,9 @@ from varname.core import nameof
from hashlib import md5 from hashlib import md5
from sqlitedict import SqliteDict from sqlitedict import SqliteDict
from pprint import PrettyPrinter from pprint import PrettyPrinter
from numpy import average as np_average from numpy import average as np_average, arange
from pyperclip import copy as pycopy from pyperclip import copy as pycopy
from os import getcwd
class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow): class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@ -269,7 +270,7 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
pp = PrettyPrinter(indent=2) pp = PrettyPrinter(indent=2)
tau_out += f""" tau_out += f"""
Tooth: {p_i} Tooth: {p_i+1}
Tau Average: {tau_avg} Tau Average: {tau_avg}
""" """
# NOTE: Insert above inside fstring to see raw data; # NOTE: Insert above inside fstring to see raw data;
@ -294,10 +295,17 @@ Tau Average: {tau_avg}
self.copy_results_button.pressed.connect(lambda: pycopy(self.tau_output.toPlainText())) self.copy_results_button.pressed.connect(lambda: pycopy(self.tau_output.toPlainText()))
def export_csv(): def export_csv():
try: try:
filename, _ = QtWidgets.QFileDialog.getSaveFileName(self) mem['time_constants']
DataFrame(mem['time_constants']).to_csv(filename, index=False)
except KeyError: except KeyError:
display_error("No tau data to export.") display_error("No tau data to export.")
return
filename, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Export CSV", "file.csv")
df = DataFrame(mem['time_constants'])
# df.index = arange(1, len(df)+1)
try:
df.to_csv(filename, index=False)
except:
pass
self.export_csv_button.pressed.connect(export_csv) self.export_csv_button.pressed.connect(export_csv)
# Show self # Show self