Skip to content

Commit

Permalink
started adding some logging stuff to basic op page. Needs some work s…
Browse files Browse the repository at this point in the history
…till

Former-commit-id: f05fe70dd775d0ba55f34112bbe21dd7346fac89
  • Loading branch information
Corbeno committed Apr 23, 2023
1 parent f79a7c9 commit 4049053
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 17 additions & 6 deletions gui/widgets/basic_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Stuff From Project - May show as an error but it works
from generated.BasicOperationWidgetUI import Ui_BasicOpetaionWidget
from widgets.mode_widget import CyDAQModeWidget
from widgets import config

# Constants
DEFAULT_SAVE_LOCATION = "U:\\"
Expand All @@ -32,6 +33,7 @@ def __init__(self, mainWindow):
self.setupUi(self)

self.mainWindow = mainWindow
self.logger = self.mainWindow.logger

# Share resources from main window
self.threadpool = self.mainWindow.threadpool
Expand Down Expand Up @@ -142,13 +144,14 @@ def onFilterChange():

def writingData(self):
"""When the cyDAQ is sending data to the frontend, and it's writing it to a file."""
self.logger.debug("GUI started accepting/writing sample data...")
self.writing = True
self.mainWindow.pingTimer.stop()
self.start_stop_sampling_btn.setText("Writing...")

def writingDataFinished(self):
"""When the cyDAQ is finished writing data."""
print("writing data finished")
self.logger.debug("writing data finished")
# Adds the filename to the plotter window for ease of use
# self.mainWindow.livestream.infile_line.setText(self.filename)
self.writing = False
Expand Down Expand Up @@ -190,6 +193,7 @@ def copyTempFile(self):
while os.path.exists(new_filename):
i += 1
new_filename = base + f'_{i}' + ext
self.logger.info("Unable to write to file path " + self.filename + ". Picked new name: " + new_filename)
self.filename = new_filename

# If the filename is still the temp filename, no file was selected
Expand All @@ -200,14 +204,16 @@ def copyTempFile(self):
# Copy the temp file over to the new one. If the user chose a matlab file, convert the csv to matlab first
if ext == ".mat":
scipy.io.savemat(self.filename, {"data": pd.read_csv(self.temp_filename).values})
self.logger.info(".mat file chosen. Converted and written to " + self.filename)
else:
self.logger.info("Copying file from " + self.temp_filename + " to " + self.filename)
shutil.copyfile(self.temp_filename, self.filename)

# Delete the old temp file
try:
os.remove(self.temp_filename)
except PermissionError:
print("Unable to delete temp file!! ", self.temp_filename)
self.logger.error("Unable to delete temp file: " + self.temp_filename)

# Reset the temp filename and the existing filename
# Causes an ask for filename every sample
Expand Down Expand Up @@ -310,11 +316,11 @@ def stop_sampling(self):
self.shouldTimeout = False
self.sampling = False

if not os.path.exists("C:\Temp"):
os.makedirs("C:\Temp")
if not os.path.exists(config.TEMP_DIR):
os.makedirs(config.TEMP_DIR)

# Set the filename to a temp filename in the user's temp directory for writing
self.temp_filename = 'C:\Temp\sample_{}.csv'.format(time.strftime('%Y%m%d-%H%M%S'))
self.temp_filename = config.TEMP_SAMPLE_LOCATION.format(time.strftime('%Y%m%d-%H%M%S'))

self.writingData()

Expand All @@ -333,7 +339,10 @@ def stop_sampling(self):
DEFAULT_SAVE_LOCATION, "CSV Files (*.csv);;MATLAB Files (*.mat)",
options=options)
if self.filename.strip() == "": # no file chosen
self.logger.debug("No file chosen. Picking " + self.temp_filename + "to write sample data")
self.filename = self.temp_filename
else:
self.logger.debug("User chose " + self.filename + " to save samples")

# Method that is run both to start and stop sampling
# Runs in a worker thread to keep the GUI from freezing and to allow use of other features
Expand Down Expand Up @@ -539,7 +548,7 @@ def resetSendConfigBtn():
self.wrapper.set_values(json.dumps(self.getData()))
response = self.wrapper.send_config_to_cydaq()
if not self.wrapper.mocking:
print(self.wrapper.get_config())
self.logger.debug("GUI config: " + self.wrapper.get_config())
send_config = self.send_config_btn
if response: # Config sent successfully
send_config.setText("Config Sent")
Expand All @@ -561,6 +570,7 @@ def resetSendConfigBtn():

def _show_error(self, message):
"""Private method to just show an error message box with a custom message"""
self.logger.error(message)
errorbox = QMessageBox(self)
errorbox.setWindowTitle("Error")
errorbox.setText(message)
Expand All @@ -569,6 +579,7 @@ def _show_error(self, message):

def _show_message(self, title, message, subtext=None):
"""Private method to just show an info message box with a custom message"""
self.logger.info(message)
messagebox = QMessageBox(self)
messagebox.setWindowTitle(title)
messagebox.setText(message)
Expand Down
3 changes: 3 additions & 0 deletions gui/widgets/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
DEBUG_WIDGET_LOG_LEVEL = logging.DEBUG
# Log file location for different OS's (development)
if sys.platform == "win32":
TEMP_DIR = "C:\\Temp"
DEFAULT_LOG_FILE = f"C:\\Temp\\cydaq_current_log.log"
else:
TEMP_DIR = "/tmp"
DEFAULT_LOG_FILE = f"/tmp/cydaq_current_log.log"
TEMP_SAMPLE_LOCATION = 'C:\Temp\sample_{}.csv' # the {} is where the time is calculated and placed

0 comments on commit 4049053

Please sign in to comment.