def save_test(self): #if self.parent.current_test_grade < 0: if self.run_process.poll() is None: ErrorWindow(self.parent, "Error: Test not finished or broken") return try: os.system("cp {0}/test/Results/Run*.root {1}/".format( os.environ.get("Ph2_ACF_AREA"), self.output_dir)) getfile = subprocess.run( 'ls -alt {0}/test/Results/Run*.root'.format(self.output_dir), shell=True, stdout=subprocess.PIPE) filelist = getfile.stdout.decode('utf-8') outputfile = filelist.rstrip('\n').split('\n')[-1].split(' ')[-1] DQMFile = self.output_dir + "/" + outputfile time_stamp = datetime.fromisoformat(self.output_dir.split('_')[-2]) testing_info = [ self.parent.current_module_id, self.parent.current_user, self.calibration, time_stamp.strftime('%Y-%m-%d %H:%M:%S.%f'), self.parent.new_test_grade, DQMFile ] insertTestResult(self.dbconnection, testing_info) # fixme #database.createTestEntry(testing_info) except: ErrorWindow(self.parent, "Error: Could not save") return
def __init__(self, parent, dbconnection): self.parent = parent if self.parent.current_user == '': ErrorWindow(self.parent, "Error: Please login") return if not dbconnection: ErrorWindow(self.parent, "Error: No DB connection ") return self.dbconnection = dbconnection tk.Toplevel.__init__(self, parent.root) self.master = self.parent.root self.title('New test') self.geometry("500x200") for row in range(1, 5): self.rowconfigure(row, weight=1, minsize=40) self.rowconfigure(0, weight=1, minsize=20) self.rowconfigure(5, weight=1, minsize=20) self.columnconfigure(1, weight=1, minsize=200) self.columnconfigure(2, weight=1, minsize=200) self.columnconfigure(0, weight=1, minsize=50) self.columnconfigure(3, weight=1, minsize=50) self.start_label = tk.Label(master=self, text="Start a new test", font=("Helvetica", 20, 'bold')) self.start_label.grid(row=1, column=1, columnspan=2, sticky="wen") self.moduleID_label = tk.Label(master=self, text="Module ID", font=("Helvetica", 15)) self.moduleID_label.grid(row=2, column=1, sticky='w') self.moduleID_entry = tk.Entry(master=self) self.moduleID_entry.grid(row=2, column=2, sticky='e') self.test_mode_label = tk.Label(master=self, text="Test mode", font=("Helvetica", 15)) self.test_mode_label.grid(row=3, column=1, sticky='w') #current_modes = [] #for mode in list(database.retrieveAllModes()): # current_modes.append(mode[1]) current_calibrations = [] for calibration in list(retrieveAllCalibrations(self.dbconnection)): current_calibrations.append(calibration[0]) self.mode_menu = tk.OptionMenu(self, self.parent.current_test_name, *current_calibrations) self.mode_menu.grid(row=3, column=2, sticky='e') self.start_button = ttk.Button(master=self, text="Start test", command=self.open_self) self.start_button.grid(row=4, column=1, columnspan=2)
def try_change_module(self): try: self.parent.review_module_id = int(self.change_entry.get()) except: ErrorWindow("Error: Please enter valid module ID") return try: self.destroy() ReviewModuleWindow(self.parent) except: ErrorWindow(self.parent, "Error: Could not change modules")
def filter_results(self): filter_option = self.parent.result_filter_attr.get() filter_eq = self.parent.result_filter_eq.get() filter_val = self.rfilter_entry.get() # FIXME #self.parent.all_results = database.retrieveAllTestTasks() self.parent.all_results = retrieveAllTestResults(self.dbconnection) filtered_results = [] if self.parent.all_results[0][0] == "": self.parent.all_results.pop(0) options_dict = {"module ID": 0, "user": 1, "testname": 2, "date": 3, "grade": 4} if filter_eq == 'contains': if filter_option == 'grade' or filter_option == 'module ID': ErrorWindow(self.parent, 'Error: Option not supported for chosen variable') return filtered_results = [r for r in self.parent.all_results if filter_val in r[options_dict[filter_option]]] else: op_dict = { '=': operator.eq, '>=': operator.ge, '>': operator.gt, '<=': operator.le, '<': operator.lt } if filter_option in ["user", "testname", "date"]: if filter_eq != '=': ErrorWindow(self.parent, 'Error: Option not supported for chosen variable') return else: filtered_results = [r for r in self.parent.all_results if op_dict[filter_eq](r[options_dict[filter_option]], filter_val)] else: try: filter_val = int(filter_val) except: ErrorWindow(self.parent, 'Error: Cannot filter a string with an numeric operation') return filtered_results = [r for r in self.parent.all_results if op_dict[filter_eq](int(r[options_dict[filter_option]]), filter_val)] self.rtable_canvas.delete('all') if len(filtered_results) == 0: self.error_label = tk.Label(master=self.rtable_canvas, text="No results found", font=("Helvetica", 15)) self.rtable_canvas.create_window(10, 10, window=self.error_label, anchor="nw") self.rtable_num['text'] = "(Showing 0 results)" return self.parent.all_results = filtered_results self.rmake_table()
def try_open_continue(self): try: self.parent.current_module_id = self.parent.review_module_id ContinueWindow(self.parent) return except: ErrorWindow(self.parent, "Error: Could not open continue window")
def config_test(self): #TCPConfigure(self.calibration, self.config_entry.get()) self.input_dir = "" self.output_dir, self.input_dir = ConfigureTest( self.calibration, self.parent.current_module_id, self.output_dir, self.dbconnection) if self.input_dir == "": if self.config_file == "": config_file = os.environ.get('GUI_dir') + ConfigFiles.get( self.calibration, "None") SetupXMLConfigfromFile(config_file, self.output_dir) ErrorWindow(self.parent, "Noitce: Using default XML configuration") else: SetupXMLConfigfromFile(self.config_file, self.output_dir) else: if self.config_file != "": SetupXMLConfigfromFile(self.config_file, self.output_dir) else: SetupXMLConfig(self.input_dir, self.output_dir) if self.input_dir == "": if self.rd53_file == "": rd53_file = os.environ.get( 'Ph2_ACF_AREA') + "/settings/RD53Files/CMSIT_RD53.txt" SetupRD53ConfigfromFile(rd53_file, self.output_dir) else: SetupRD53ConfigfromFile(self.rd53_file, self.output_dir) else: if self.rd53_file == "": SetupRD53Config(self.input_dir, self.output_dir) else: SetupRD53ConfigfromFile(self.rd53_file, self.output_dir) return
def StartConnection(TryUsername, TryPassword, TryHostAddress, TryDatabase, master): # For test, no connection to DB is made and output will not be registered if TryHostAddress == "0.0.0.0": return "DummyDB" # Try connecting to DB on localhost with unspecific host address if not TryHostAddress: TryHostAddress = '127.0.0.1' if not TryDatabase: TryDatabase = 'phase2pixel_test' try: connection = mysql.connector.connect(user=str(TryUsername), password=str(TryPassword), host=str(TryHostAddress), database=str(TryDatabase)) except (ValueError, RuntimeError, TypeError, NameError, mysql.connector.Error): ErrorWindow( master, "Error:Unable to establish connection to host:" + str(TryHostAddress) + ", please check the username/password and host address") return return connection
def check_review_moduleID(self): try: self.parent.review_module_id = int(self.module_num_entry.get()) except: ErrorWindow(self.parent, "Error: Please enter valid module ID") return ReviewModuleWindow(self.parent, self.dbconnection)
def __init__(self, parent, dbconnection): tk.Toplevel.__init__(self,parent.root) self.parent = parent self.master = self.parent.root self.dbconnection = dbconnection if self.parent.current_user == '': ErrorWindow(self.parent, "Error: Please login") return self.re_width = scaleInvWidth(self.master, 0.6) self.re_height = scaleInvHeight(self.master, 0.6) self.title("Review Results") self.geometry("{}x{}".format(self.re_width, self.re_height)) self.grid_columnconfigure(0, weight=1, minsize=self.re_width) self.grid_rowconfigure(0, weight=1, minsize=100) self.grid_rowconfigure(1, weight=1, minsize=self.re_height-100) #FIXME #self.parent.all_results = database.retrieveAllTestTasks() self.parent.all_results = retrieveAllTestResults(self.dbconnection) #self.parent.all_results = retrieveAllTestResults(self.dbconnection) self.parent.all_results.sort(key=lambda r: r[3], reverse=True) self.setupFrame()
def open_self(self): try: self.parent.current_module_id = int(self.moduleID_entry.get()) except: ErrorWindow(self.parent, "Error: Please enter valid module ID") return RunWindow(self.parent) self.destroy()
def __init__(self, parent, dbconnection): tk.Toplevel.__init__(self) self.parent = parent if self.parent.current_user == '': ErrorWindow(self.parent, "Error: Please login") return self.master = self.parent.root self['bg'] = 'white' self.title("Create Test") self.geometry("1000x500") create_tmp_lbl = tk.Label(master = self, text = "Create test options will appear in this window", font=("Helvetica", 20)) create_tmp_lbl.pack()
def make_table(self): self.table_canvas.delete('all') self.table_num['text'] = "(Showing {0} results)".format(len(self.parent.module_results)) if not self.parent.module_results: ErrorWindow(self.parent, "No test results available") return if self.parent.module_results[0][0] != "Module ID": self.parent.module_results = [[ "Module ID", "User", "Test", "Date", "Grade", "DQMFile"]] + self.parent.module_results n_cols = 6 row_ids = [r[0] for r in self.parent.module_results] for j, result in enumerate(self.parent.module_results): if j != 0: result_button = tk.Button( master = self.table_canvas, text = "{0}".format(j) #command = partial(self.open_result, row_ids[j]) ) self.table_canvas.create_window(0*self.table_cols[0]/n_cols, j*25, window=result_button, anchor='nw') for i, item in enumerate(result): #if i in [5]: continue bold = '' if j == 0: bold = 'bold' row_label = tk.Label(master=self.table_canvas, text=str(item), font=("Helvetica", 15, bold)) anchor = 'nw' if i == 5: anchor = 'ne' if i in [0,1,2,3,4] or j == 0: self.table_canvas.create_window((i*self.table_cols[0]/n_cols)+65, j*25, window=row_label, anchor=anchor) if i == 5 and j != 0: detail_button = tk.Button( master = self, text = "Show Details...", command = partial(self.show_result,item) ) self.table_canvas.create_window((i*self.table_cols[0]/n_cols)+65, j*25, window=detail_button, anchor=anchor) self.table_canvas.config(scrollregion=(0,0,1000, (len(self.parent.module_results)+2)*25))
def login_user(self): if self.username_entry.get() == '': ErrorWindow(self.parent, "Error: Please enter a valid username") return TryUsername = self.username_entry.get() TryPassword = self.password_entry.get() TryHostAddress = self.host_entry.get() TryDatabase = self.database_entry.get() connection = StartConnection(TryUsername, TryPassword, TryHostAddress, TryDatabase, self.parent) if not connection: return self.dbconnection = connection # Checking login info in encrypted way to be added self.parent.current_user = self.username_entry.get() self.login_label['text'] = 'Welcome {0}'.format(self.parent.current_user) self.login_label['font'] = ('Helvetica', 20, 'bold') self.username_label.grid_remove() self.username_entry.grid_remove() self.password_label.grid_remove() self.password_entry.grid_remove() self.host_label.grid_remove() self.host_entry.grid_remove() self.database_label.grid_remove() self.database_entry.grid_remove() self.login_button.grid_remove() self.logout_button.grid(row=2, column=0, columnspan=2) self.exit_button.grid(row=3, column=0, columnspan=2) self.options_frame.SetDBConnection(self.dbconnection) self.options_frame.grid(row=1, column=1, sticky="es") #FIXME self.grid(row=1, column=0, sticky="ws") self['width'] = 300 self.columnconfigure(0, weight=1, minsize=150) self.columnconfigure(1, weight=1, minsize=150)
def __init__(self, parent, dbconnection): tk.Toplevel.__init__(self, parent.root) self.parent = parent self.master = self.parent.root self.dbconnection = dbconnection if self.parent.current_user == '': ErrorWindow(self.parent, "Error: Please login") return elif self.parent.review_module_id == -1: ErrorWindow(self.parent, "Error: Please enter module ID") return self.parent.module_results = retrieveModuleTests(self.dbconnection, self.parent.review_module_id) if len(self.parent.module_results) == 0: ErrorWindow(self.parent, "Error: No results found for this module, start a new test") self.parent.current_module_id = self.parent.review_module_id ContinueWindow(self.parent, self.dbconnection) self.destroy() return header = retriveTestTableHeader(self.dbconnection) col_names = list(map(lambda x: header[x][0], range(0,len(header)))) #grade_index = col_names.index('Grading') time_index = col_names.index('ExecutionTime') #best_result = self.parent.module_results[0] #latest_result = self.parent.module_results[0] #best_result = sorted(self.parent.module_results, key=lambda r: r[grade_index])[-1] #latest_result = sorted(self.parent.module_results, key=lambda r: r[time_index])[-1] self.parent.module_results.sort(key=lambda r: r[time_index], reverse=True) self.window_width = scaleInvWidth(self.master, 0.6) self.window_height = scaleInvHeight(self.master, 0.5) self.window_rows = list(map(lambda x : round(x * self.window_height), [0.1, 0.5, 0.4])) self.window_cols = [self.window_width] self.sub_rows = list(map(lambda x : round(x*self.window_rows[1]), [0.1, 0.7, 0.2])) self.sub_cols = [int(self.window_width/2)] self.table_rows = list(map(lambda x : round(x*self.window_rows[2]), [0.25, 0.75])) self.table_cols = [self.window_width-15, 15] self.tableb_rows = list(map(lambda x : round(x*self.table_rows[0]), [0.4, 0.3, 0.3])) self.tableb_cols = list(map(lambda x : round(x*self.window_width), [0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125])) # dev assert sum(self.window_rows) - self.window_height < 3, 'Check height' assert sum(self.window_cols) - self.window_width < 3, 'Check width' assert self.window_rows[1] - sum(self.sub_rows) < 3, 'Check bl subview' assert self.window_rows[2] - sum(self.table_rows) < 3, 'Check table subview' assert sum(self.tableb_rows) - self.table_rows[0] < 3, 'Check tableb rows' assert sum(self.tableb_cols) - self.window_width < 3, 'Check tableb cols' self.master = self.parent.root self.config(bg='white') self.title('Review Module ID: {0}'.format(self.parent.review_module_id)) self.geometry("{0}x{1}".format(self.window_width, self.window_height)) self.rowconfigure(0, weight=1, minsize=self.window_rows[0]) self.rowconfigure(1, weight=1, minsize=self.window_rows[1]) self.rowconfigure(2, weight=1, minsize=self.window_rows[2]) self.columnconfigure(0, weight=1, minsize=self.window_cols[0]) # setup header frames self.header_frame = tk.Frame(self, width=self.window_cols[0], height=self.window_rows[0]) self.header_frame.grid(row=0, column=0, sticky='nwes') self.header_frame.grid_propagate(False) # setup header module_label = tk.Label(master = self.header_frame, text = "Module ID: {0}".format(self.parent.review_module_id), font=("Helvetica", 25, 'bold')) module_label.pack(anchor='ne', side=tk.LEFT) self.change_entry = tk.Entry(master=self.header_frame) self.change_entry.pack(anchor='ne', side=tk.RIGHT) change_button = ttk.Button( master = self.header_frame, text = "Change module:", command = self.try_change_module ) change_button.pack(side=tk.RIGHT, anchor='ne') continue_button = ttk.Button( master = self.header_frame, text = "Continue Testing", command = self.try_open_continue, ) continue_button.pack(side=tk.RIGHT, anchor='n') # Histogram Frame for test history self.hist_frame = tk.Frame(self, width=self.window_cols[0], height=self.window_rows[1], bg='white') self.hist_frame.grid(row=1, column=0, sticky='nwes') self.hist_frame.columnconfigure(0, weight=1, minsize=self.window_cols[0]) self.hist_frame.rowconfigure(0, weight=1, minsize=self.window_rows[1]) self.hist_frame.grid_propagate(False) best_frame = tk.Frame(self.hist_frame, width=sum(self.sub_cols), height=sum(self.sub_rows), relief=tk.SUNKEN, bd=2, bg='white') best_frame.grid(row=0, column=0, sticky='nwes') best_frame.columnconfigure(0, weight=1, minsize=self.sub_cols[0]) best_frame.rowconfigure(0, weight=1, minsize=self.sub_rows[0]) best_frame.rowconfigure(1, weight=1, minsize=self.sub_rows[1]) best_frame.rowconfigure(2, weight=1, minsize=self.sub_rows[2]) best_tframe = tk.Frame(best_frame, width=self.sub_cols[0], height=self.sub_rows[1], bg='white') best_tframe.grid(row=1, column=0, sticky='nwes') best_bframe = tk.Frame(best_frame, width=self.sub_cols[0], height=self.sub_rows[2], bg='white') best_bframe.grid(row=2, column=0, sticky='nwes') best_frame.grid_propagate(False) best_tframe.grid_propagate(False) best_bframe.grid_propagate(False) # setup Histogram #best_title = tk.Label(master=best_frame, text="Best result", font=("Helvetica", 25),bg='white') #best_title.grid(row=0, column=0, sticky='n') # #best_glabel = tk.Label(master=best_bframe, text="{0}%".format(best_result[5]), font=("Helvetica", 45, 'bold'), bg='white') #best_glabel.pack(anchor='ne', side=tk.RIGHT, expand=False) #best_tlabel = tk.Label(master=best_bframe, text="{0}".format(best_result[3]), font=("Helvetica", 20), bg='white') #best_tlabel.pack(anchor='nw', side=tk.TOP) #best_dlabel = tk.Label(master=best_bframe, text="{0}".format(best_result[4]), font=("Helvetica", 20), bg='white') #best_dlabel.pack(anchor='nw', side=tk.TOP) #best_ulabel = tk.Label(master=best_bframe, text="{0}".format(best_result[2]), font=("Helvetica", 15), bg='white') #best_ulabel.pack(anchor='nw', side=tk.TOP) #FIXME: automate plot retrieval best_canvas = tk.Canvas(best_tframe, bg='white') best_canvas.pack(expand=True, fill='both', anchor='nw', side=tk.TOP) best_img = Image.open("test_plots/test_best1.png") best_img = best_img.resize((self.sub_cols[0], self.sub_rows[1]), Image.ANTIALIAS) self.parent.review_best_plot = ImageTk.PhotoImage(best_img) best_canvas.create_image(0, 0, image=self.parent.review_best_plot, anchor="nw") # Table Frame for test history self.table_frame = tk.Frame(self, width=self.window_width, height=self.window_rows[2], relief=tk.SUNKEN, bd=2) self.table_frame.grid(row=2, column=0, sticky='nwes') self.table_frame.grid_propagate(False) self.table_frame.columnconfigure(0, weight=1, minsize=self.window_width) self.table_frame.rowconfigure(0, weight=1, minsize=self.table_rows[0]) self.table_frame.rowconfigure(1, weight=1, minsize=self.table_rows[1]) table_tframe = tk.Frame(self.table_frame, width=self.window_width, height=self.table_rows[0]) table_tframe.grid(row=0, column=0, sticky='nwes') for row in range(3): table_tframe.grid_rowconfigure(row, weight=1, minsize=self.tableb_rows[row]) for col in range(len(self.tableb_cols)): table_tframe.grid_columnconfigure(row, weight=1, minsize=self.tableb_cols[col]) table_bframe = tk.Frame(self.table_frame, width=self.window_width, height=self.table_rows[1]) table_bframe.grid(row=1, column=0, sticky='nwes') table_bframe.rowconfigure(0, weight=1, minsize=self.table_rows[1]) table_bframe.columnconfigure(0, weight=1, minsize=self.table_cols[0]) table_bframe.columnconfigure(1, weight=1, minsize=self.table_cols[1]) self.table_frame.grid_propagate(False) table_tframe.grid_propagate(False) table_bframe.grid_propagate(False) # setup table self.parent.module_results = retrieveModuleTests(self.dbconnection, self.parent.review_module_id) table_label = tk.Label(master=table_tframe, text = "All results for module {0}".format(self.parent.review_module_id), font=("Helvetica", 20)) table_label.pack(side=tk.TOP, anchor='nw') self.table_num = tk.Label(master=table_tframe, text = "(Showing {0} results)".format(len(self.parent.module_results)), font=("Helvetica", 12)) self.table_num.grid(row=0, column=3, sticky='sw') sort_button = ttk.Button( master = table_tframe, text = "Sort by", command = self.sort_results, ) sort_button.grid(row=1, column=0, sticky='nsew') sort_menu = tk.OptionMenu(table_tframe, self.parent.review_sort_attr, *['date', 'user', 'grade', 'testname']) sort_menu.grid(row=1, column=1, sticky='nsew') dir_menu = tk.OptionMenu(table_tframe, self.parent.review_sort_dir, *["increasing", "decreasing"]) dir_menu.grid(row=1, column=2, sticky='nsw') filter_button = ttk.Button( master = table_tframe, text = "Filter", command = self.filter_results, ) filter_button.grid(row=1, column=3, sticky='nsew', padx=(0, 0)) filter_menu = tk.OptionMenu(table_tframe, self.parent.review_filter_attr, *['date', 'user', 'grade', 'testname']) filter_menu.grid(row=1, column=4, sticky='nsw') eq_menu = tk.OptionMenu(table_tframe, self.parent.review_filter_eq, *["=", ">=", "<=", ">", "<", "contains"]) eq_menu.grid(row=1, column=5, sticky='nsw') self.filter_entry = tk.Entry(master=table_tframe) self.filter_entry.insert(0, '{0}'.format(self.parent.current_user)) self.filter_entry.grid(row=1, column=6, sticky='nsw') reset_button = ttk.Button( master = table_tframe, text = "Reset", command = self.reset_results, ) reset_button.grid(row=1, column=7, sticky='nse') yscrollbar = tk.Scrollbar(table_bframe) yscrollbar.grid(row=0, column=1, sticky='nes') self.table_canvas = tk.Canvas(table_bframe, yscrollcommand=yscrollbar.set) self.table_canvas.grid(row=0, column=0, sticky='nsew') yscrollbar.config(command=self.table_canvas.yview) self.make_table()