forked from zietzm/Helmholtz_Test_Bench
comments and code cleanup
Logging, and threading cleanup
This commit is contained in:
+20
-17
@@ -9,9 +9,9 @@ from tkinter import filedialog
|
||||
from tkinter import messagebox
|
||||
import User_Interface as ui
|
||||
|
||||
log_data = pd.DataFrame() # pandas data frame containing logged data
|
||||
log_data = pd.DataFrame() # pandas data frame containing the logged data, in-program representation of csv/excel data
|
||||
unsaved_data = False # Bool to indicate if there is unsaved data, set to True each time a datapoint is logged
|
||||
zero_time = datetime.now()
|
||||
zero_time = datetime.now() # set reference for timestamps in log file, reset when log_data is cleared and restarted
|
||||
|
||||
# create dictionary with all value handles that could be logged
|
||||
# Key: String that is displayed in UI and column headers. Also serves as handle to access dictionary elements.
|
||||
@@ -39,20 +39,23 @@ def triple_list(key_list): # creates list with each entry of key_list tripled w
|
||||
return new_list
|
||||
|
||||
|
||||
def log_datapoint(key_list): # ToDo: comments
|
||||
global log_data
|
||||
global unsaved_data
|
||||
date = datetime.now().date()
|
||||
time = datetime.now().strftime("%H:%M:%S,%f")
|
||||
t = (datetime.now() - zero_time).total_seconds()
|
||||
data = [[date, time, t]]
|
||||
for key in key_list:
|
||||
for axis in g.AXES:
|
||||
data[0].append(getattr(axis, axis_data_dict[key])) # get value
|
||||
column_names = ["Date", "Time", "t (s)", *triple_list(key_list)]
|
||||
new_row = pd.DataFrame(data, columns=column_names)
|
||||
log_data = log_data.append(new_row, ignore_index=True)
|
||||
unsaved_data = True
|
||||
def log_datapoint(key_list): # logs a single row of data into the log_data DataFrame
|
||||
# key_list determines what data is logged
|
||||
global log_data # get global dataframe with logged data
|
||||
global unsaved_data # get global variable that indicates if there is unsaved data
|
||||
date = datetime.now().date() # get current date
|
||||
time = datetime.now().strftime("%H:%M:%S,%f") # get string with current time in correct format
|
||||
t = (datetime.now() - zero_time).total_seconds() # calculate timestamp relative to the start of the logging
|
||||
data = [[date, time, t]] # initialize new data row with timestamps
|
||||
for key in key_list: # go through the list telling us what data to log
|
||||
for axis in g.AXES: # log this data for each axis
|
||||
# get relevant value from the correct AXIS object and append to new data row:
|
||||
data[0].append(getattr(axis, axis_data_dict[key]))
|
||||
|
||||
column_names = ["Date", "Time", "t (s)", *triple_list(key_list)] # create list with the correct column headers
|
||||
new_row = pd.DataFrame(data, columns=column_names) # create data frame containing the new row
|
||||
log_data = log_data.append(new_row, ignore_index=True) # append the new data frame to the logged data
|
||||
unsaved_data = True # tell other program parts that there is now unsaved data
|
||||
|
||||
|
||||
def select_file(): # select a file to write logs to
|
||||
@@ -90,4 +93,4 @@ def write_to_file(dataframe, filepath):
|
||||
|
||||
def clear_logged_data(): # clears all logged data from data frame
|
||||
global log_data # get global variable
|
||||
log_data = pd.DataFrame() # reset to an empty data frame, i.e. clear all logged data
|
||||
log_data = pd.DataFrame() # reset to an empty data frame, i.e. clearing all logged data
|
||||
|
||||
Reference in New Issue
Block a user