Copying & exporting tau data, touch up UI & histogram display

master
michael 2021-08-11 15:07:11 -07:00
parent 1c409ed2c6
commit 918944e39e
4 changed files with 24 additions and 12 deletions

19
app.py
View File

@ -1,6 +1,6 @@
import sys import sys
import crds_calc import crds_calc
from pandas import read_csv from pandas import read_csv, DataFrame
from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5 import QtGui, QtWidgets, QtCore
from db import mem from db import mem
from mainwin import Ui_MainWindow from mainwin import Ui_MainWindow
@ -11,7 +11,8 @@ 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
import numpy as np from numpy import average as np_average
from pyperclip import copy as pycopy
class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow): class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@ -264,11 +265,11 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
tau_out = "" tau_out = ""
for p_i in range(len(mem['time_constants'][0])): for p_i in range(len(mem['time_constants'][0])):
tau_avg = np.average(mem['time_constants'][0:len(mem['time_constants'])][p_i]) tau_avg = np_average(mem['time_constants'][0:len(mem['time_constants'])][p_i])
pp = PrettyPrinter(indent=2) pp = PrettyPrinter(indent=2)
tau_out += f""" tau_out += f"""
Tooth: {p_i+1} Tooth: {p_i}
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;
@ -289,6 +290,16 @@ Tau Average: {tau_avg}
scene.addItem(item) scene.addItem(item)
self.equation_view.setScene(scene) self.equation_view.setScene(scene)
# Tau output actions
self.copy_results_button.pressed.connect(lambda: pycopy(self.tau_output.toPlainText()))
def export_csv():
try:
filename, _ = QtWidgets.QFileDialog.getSaveFileName(self)
DataFrame(mem['time_constants']).to_csv(filename, index=False)
except KeyError:
display_error("No tau data to export.")
self.export_csv_button.pressed.connect(export_csv)
# Show self # Show self
self.show() self.show()

View File

@ -3,6 +3,7 @@ pandas
matplotlib matplotlib
numpy numpy
pyinstaller==4.4 pyinstaller==4.4
pyperclip
sqlitedict sqlitedict
scipy scipy
varname varname

View File

@ -41,7 +41,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>267</width> <width>267</width>
<height>917</height> <height>897</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -95,13 +95,13 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>248</width> <width>248</width>
<height>306</height> <height>286</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>248</width> <width>248</width>
<height>306</height> <height>286</height>
</size> </size>
</property> </property>
<property name="font"> <property name="font">
@ -845,7 +845,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:7.8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:7.8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="copyResultsButton"> <widget class="QPushButton" name="copy_results_button">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>20</x>
@ -858,7 +858,7 @@ p, li { white-space: pre-wrap; }
<string>Copy</string> <string>Copy</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="exportPlaintextButton"> <widget class="QPushButton" name="export_csv_button">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>20</x> <x>20</x>
@ -868,7 +868,7 @@ p, li { white-space: pre-wrap; }
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Export Text</string> <string>Export CSV</string>
</property> </property>
</widget> </widget>
</widget> </widget>

View File

@ -175,7 +175,7 @@ class TimeConstantGraph(BaseGraph):
data = [] data = []
for g_i in range(len(mem['time_constants'])): for g_i in range(len(mem['time_constants'])):
data.append(mem['time_constants'][g_i][self.peak_index]) data.append(mem['time_constants'][g_i][self.peak_index])
self.canv.axes.hist(data, bins='auto', alpha=0.8) self.canv.axes.hist(data, bins='auto', edgecolor='black')
class TimeConstantGraphsViewer(QtWidgets.QTabWidget): class TimeConstantGraphsViewer(QtWidgets.QTabWidget):
def __init__(self, x): def __init__(self, x):
@ -187,7 +187,7 @@ class TimeConstantGraphsViewer(QtWidgets.QTabWidget):
self.clear() self.clear()
for p_i in range(len(mem['time_constants'][0])): for p_i in range(len(mem['time_constants'][0])):
tab_name = str(p_i+1) tab_name = str(p_i)
tau_graph = TimeConstantGraph(self) tau_graph = TimeConstantGraph(self)
tau_graph.set_peak_index(p_i) tau_graph.set_peak_index(p_i)
self.addTab(tau_graph, tab_name) self.addTab(tau_graph, tab_name)