def usernameEvent(event): print("在用户名事件中") uname = self.new_name.get() letter = string.ascii_letters + string.digits if not uname: label_username_error['fg'] = "red" label_username_error["text"] = "用户名不能为空" self.submit_uname = False else: num_allow = 0 for i in uname: if i not in letter: num_allow += 1 if num_allow > 0: label_username_error['fg'] = "red" label_username_error["text"] = "含有非法字符" self.submit_uname = False else: querySQL = queryDB.queryDB() if querySQL.duplicate_check(uname): label_username_error['fg'] = "red" label_username_error["text"] = "该用户被注册过了" self.submit_uname = False else: label_username_error['fg'] = "green" label_username_error["text"] = "合法用户名" self.submit_uname = True
def submit(self): not_yet_list = [] answer_list = [] anaylse = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0} for value,i in zip(self.di.values(),range(1,self.length+1)): if value == -1: not_yet_list.append(i) elif value == 1 or value == 0: answer_list.append(i) print(self.di) print(not_yet_list) if len(answer_list) != 108 and len(not_yet_list) == 0: self.label_info["text"] = "你还没开始,怎么就结束了呢。还是答完题再交卷吧" # messagebox.showwarning(title="题目没做完",message="你还没开始,怎么就结束了呢。还是答完题在结束吧") elif len(not_yet_list)> 0: if len(not_yet_list) < 10: self.label_info["text"] = "还有%s道题目没有做完%s,不能交卷,"%(str(len(not_yet_list)),str(not_yet_list)) else: self.label_info["text"] = "您还有超过10道以上的题目没有做,请接着做完再交卷吧。" # messagebox.showwarning(title='题目没做完',message="还有%s道题目没有做完%s,不能交卷,"%(str(len(not_yet_list)),str(not_yet_list))) else:#正式提交 for ques_item,value in self.di.items():#前者是题目 后者是答案 char = self.questions_dict[ques_item] #该题目所属于的性格类型 print(char) if value == 1: anaylse[char] += 1 querySQL = queryDB.queryDB() user_id = querySQL.getUserId(uname=self.uname) querySQL.insertTestResult(id=user_id,uname=self.uname,test_result=anaylse,test_type="108") times = querySQL.getTestTimes(uname=self.uname) querySQL.updateTestTime(uname=self.uname,times=times) self.label_info["text"] = "检测结果:您更有可能是%s号性格。"% list(anaylse.keys())[list(anaylse.values()).index(sorted(anaylse.values())[-1])]
def login(self): uname = self.user_name.get() pwd = self.passwd.get() self.app = Applications.App(self.root, uname) # messagebox.showinfo(title="login",message=uname + "你点了login一下") querySQL = queryDB.queryDB() if not uname and not pwd: # 用户名和密码没写全 self.label_error_info_login["text"] = "废物,【用户名】和【密码】空着呢,我怎么登录啊" # messagebox.showwarning(title="登录警告",message="对不起,用户名或密码不能为空") elif not uname and pwd: self.label_error_info_login["text"] = "废物,【用户名】还空着呢,我怎么登录啊" elif not pwd and uname: self.label_error_info_login["text"] = "废物,【密码】空着呢,我怎么登录啊" else: # 用户民和密码都已填写 判断对错 if querySQL.duplicate_check(uname): # 如果该户注册了 if querySQL.checkUser(uname=uname, pwd=pwd): # 用户名和密码都输入正确 # self.root.destroy() # 登录成功之后 登录界面消失 # self.root.quit() self.root.withdraw() self.root.destroy() # root = tk.Tk() #因为self.root界面已经消失了 所以这里再创建一个主窗口 参数在函数内部设定 mainWindow.MainWindow(uname=uname, pwd=pwd).show() else: # 用户名或者密码输入有误 self.label_error_info_login["text"] = "对不起,用户名或者密码输错了" # messagebox.showinfo(title="登录错误", message="用户名或密码错误,请重新输入") else: # 改用户没有注册 self.label_error_info_login["text"] = "对不起,该用户还没有注册,请先注册"
def submit(self): answer_dict = itemContent.answer_dict_144 #用来校对答案的一个列表 里面放的是同样的题目和题目所属性格类型,就是格式不一样 not_yet_list = [] answer_list = [] anaylse = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0} for value, i in zip(self.di.values(), range(1, self.length + 1)): if value == -1: not_yet_list.append(i) elif value ==0 or value == 1: answer_list.append(i) print(not_yet_list) print(answer_list) if len(not_yet_list) == 0 and len(answer_list) != 144: self.label_info["text"] = "你还没开始,怎么就结束了呢。还是答完题再交卷吧" # messagebox.showwarning(title="题目没做完",message="你还没开始,怎么就结束了呢。还是答完题在结束吧") elif len(not_yet_list) > 0: if len(not_yet_list) < 10: self.label_info["text"] = "还有%s道题目没有做完%s,不能交卷," % (str(len(not_yet_list)), str(not_yet_list)) else: self.label_info["text"] = "您还有超过10道以上的题目没有做,请接着做完再交卷吧。" # messagebox.showwarning(title='题目没做完',message="还有%s道题目没有做完%s,不能交卷,"%(str(len(not_yet_list)),str(not_yet_list))) else: for answer_title, answer_num in zip(answer_dict, self.di.values()): anaylse[list(answer_title[answer_num].values())[0]] += 1 querySQL = queryDB.queryDB() user_id = querySQL.getUserId(uname=self.uname) querySQL.insertTestResult(id=user_id, uname=self.uname, test_result=anaylse, test_type="144") times = querySQL.getTestTimes(uname=self.uname) querySQL.updateTestTime(uname=self.uname, times=times) self.label_info["text"] = "检测结果:您更有可能是%s号性格。" % list(anaylse.keys())[ list(anaylse.values()).index(sorted(anaylse.values())[-1])] print(anaylse)
def __init__(self, stdscreen, userpass): self.screen = stdscreen self.username = userpass['user'] self.password = userpass['pass'] self.database_manager = DatabaseManager(self.screen, userpass) self.screen_manager = ScreenManager(self.screen) self.table_manager = TableManager(self.screen, userpass) self.query_manager = queryDB(self.screen, userpass) headeroptions = {'user':self.username} #I ran into an error here when trying to set cursur to invisible #this if/try makes sure that both the version of curses and the #terminal support this functionality if hasattr(curses, 'curs_set'): try: curses.curs_set(0) except: pass importer = impexp(self.screen, userpass) data_items = [ ('Import', self.database_manager.display_all_databases_opt, importer.list_sql_files), ('Export', self.database_manager.display_all_databases_opt, importer.export) ] data = Menu(data_items, self.screen, headeroptions) browse_database_items = [ ('List Databases', self.database_manager.display_all_databases), ('Create', self.database_manager.create_new_database), ('Copy', self.database_manager.display_all_copy_database), ('Drop', self.database_manager.display_all_delete_database) ] browse_database = Menu(browse_database_items, self.screen, headeroptions) browse_table_items = [ ('List Tables', self.database_manager.display_all_databases_opt, self.table_manager.listTables), ('Create', self.database_manager.display_all_databases_opt, self.table_manager.createTable), ('Delete', self.database_manager.display_all_databases_opt, self.table_manager.list_drop_tables) ] browse_table = Menu(browse_table_items, self.screen, headeroptions) query_items = [ ('Enter A Query', self.database_manager.display_all_databases_opt, self.query_manager.do), ('Save A Query', self.query_manager.save), ('View Past Queries', self.database_manager.display_all_databases_opt, self.query_manager.get_history), ('View Saved Queries', self.database_manager.display_all_databases_opt, self.query_manager.get_saved) ] query = Menu(query_items, self.screen, headeroptions) main_menu_items = [ ('Data Management', data.display), ('Browse Databases', browse_database.display), ('Browse Tables', browse_table.display), ('Query',query.display) ] main_menu = Menu(main_menu_items, self.screen, headeroptions) main_menu.display()
def __init__(self, stdscreen, userpass): self.screen = stdscreen self.username = userpass['user'] self.password = userpass['pass'] self.database_manager = DatabaseManager(self.screen, userpass) self.screen_manager = ScreenManager(self.screen) self.table_manager = TableManager(self.screen, userpass) self.query_manager = queryDB(self.screen, userpass) headeroptions = {'user': self.username} #I ran into an error here when trying to set cursur to invisible #this if/try makes sure that both the version of curses and the #terminal support this functionality if hasattr(curses, 'curs_set'): try: curses.curs_set(0) except: pass importer = impexp(self.screen, userpass) data_items = [ ('Import', self.database_manager.display_all_databases_opt, importer.list_sql_files), ('Export', self.database_manager.display_all_databases_opt, importer.export) ] data = Menu(data_items, self.screen, headeroptions) browse_database_items = [ ('List Databases', self.database_manager.display_all_databases), ('Create', self.database_manager.create_new_database), ('Copy', self.database_manager.display_all_copy_database), ('Drop', self.database_manager.display_all_delete_database) ] browse_database = Menu(browse_database_items, self.screen, headeroptions) browse_table_items = [ ('List Tables', self.database_manager.display_all_databases_opt, self.table_manager.listTables), ('Create', self.database_manager.display_all_databases_opt, self.table_manager.createTable), ('Delete', self.database_manager.display_all_databases_opt, self.table_manager.list_drop_tables) ] browse_table = Menu(browse_table_items, self.screen, headeroptions) query_items = [ ('Enter A Query', self.database_manager.display_all_databases_opt, self.query_manager.do), ('Save A Query', self.query_manager.save), ('View Past Queries', self.database_manager.display_all_databases_opt, self.query_manager.get_history), ('View Saved Queries', self.database_manager.display_all_databases_opt, self.query_manager.get_saved) ] query = Menu(query_items, self.screen, headeroptions) main_menu_items = [('Data Management', data.display), ('Browse Databases', browse_database.display), ('Browse Tables', browse_table.display), ('Query', query.display)] main_menu = Menu(main_menu_items, self.screen, headeroptions) main_menu.display()
def submit(): _new_name = self.new_name.get() _pwd = self.new_pwd.get() _confirm_pwd = self.confirm_pwd.get() _nick_name = self.nick_name.get() _back = entry_back.get("0.0", "end") _back = _back.strip() _tel = self.tel.get() submit_list = [ self.submit_uname, self.submit_nickname, self.submit_pwd, self.submit_confirm_pwd, self.submit_tel ] submit_name = ['用户名', '昵称', '密码', '确认密码', '电话'] print(submit_list) if self.submit_confirm_pwd and self.submit_pwd and self.submit_uname and self.submit_tel and self.submit_nickname: if _pwd != _confirm_pwd: lebel_error_info_signup["text"] = "您两次密码输入不一致,请确认注册。" else: if queryDB.queryDB().duplicate_check(_new_name): lebel_error_info_signup[ "text"] = "该用户名已经被注册过,请重新输入一个新的用户名。" # messagebox.showwarning(title="注册错误",message="该用户名已经被注册过,请重新输入一个新的用户名。") else: qu = queryDB.queryDB() answer = qu.insertUser(uname=_new_name, pwd=_pwd, tel=_tel, back=_back, nickname=_nick_name) if answer: if messagebox.askokcancel(title="确认取消", message="您确认注册该账号吗?"): messagebox.showinfo(title="注册成功", message="注册成功,您的账号为:" + _new_name + ",密码:" + _pwd) top_window.destroy() else: num_error = [] for i in range(len(submit_list)): if submit_list[i] == False: num_error.append(i) if len(num_error) == 1: lebel_error_info_signup['text'] = "【{0}】中不符合要求。".format( submit_name[num_error.pop()]) elif len(num_error) == 2: lebel_error_info_signup[ 'text'] = "【{0}】|【{1}】中不符合要求。".format( submit_name[num_error.pop()], submit_name[num_error.pop()]) elif len(num_error) == 3: lebel_error_info_signup[ 'text'] = "【{0}】|【{1}】|【{2}】中不符合要求。".format( submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()]) elif len(num_error) == 4: lebel_error_info_signup[ 'text'] = "【{0}】|【{1}】|【{2}】|【{3}】中不符合要求。".format( submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()]) elif len(num_error) == 5: lebel_error_info_signup[ 'text'] = "【{0}】|【{1}】|【{2}】|【{3}】|【{4}】中不符合要求。".format( submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()], submit_name[num_error.pop()])
def start_queryDB(): queryDB()
def show(self): try: if queryDB.queryDB().selectUsers(self.uname, self.pwd): # while True: querySQL = queryDB.queryDB() tuple_info = querySQL.selectUsers(self.uname, self.pwd) cur_time = querySQL.getTestTimeAndType(self.uname)[0] print("这是mainwindow") print(tuple_info) # time.sleep(60) # 定义了一个可以分隔显示的区域 tab_control = ttk.Notebook(self.root) tab_user_info = ttk.Frame(tab_control) tab_control.add(text="用户信息", child=tab_user_info) tab_frame = Frame(tab_user_info, width=480, height=380) tab_frame.place(x=0, y=9) Label(tab_frame, text="用户名:", width=15, height=2, bg="skyblue", justify="left").place(x=0, y=0) Label(tab_frame, text=tuple_info[1], width=20, height=2, bg="lightgreen", justify="left").place(x=120, y=0) Label(tab_frame, text="昵 称:", width=15, height=2, bg="skyblue", justify="left").place(x=0, y=45) Label(tab_frame, text=tuple_info[3], width=20, height=2, bg="lightgreen", justify="left").place(x=120, y=45) Label(tab_frame, text="电 话:", width=15, height=2, bg="skyblue", justify="left").place(x=0, y=90) Label(tab_frame, text=tuple_info[4], width=20, height=2, bg="lightgreen", justify="left").place(x=120, y=90) Label(tab_frame, text="测试次数:", width=15, height=2, bg="skyblue", justify="left").place(x=0, y=135) Label(tab_frame, text=tuple_info[6], width=20, height=2, bg="lightgreen", justify="left").place(x=120, y=135) self.label_time = Label(tab_frame, text=cur_time, width=23, height=2, bg="palegreen", justify="left") self.label_time.place(x=275, y=135) Button(tab_frame, text="刷新", width=14, height=1, bg="lightgreen").place(x=480, y=135) Label(tab_frame, text="备 注:", width=15, height=2, bg="skyblue", justify="left").place(x=0, y=180) Label(tab_frame, text=tuple_info[5], width=20, height=2, bg="lightgreen", justify="left").place(x=120, y=180) Button(tab_frame, text="刷新", width=14, height=1, bg="lightgreen", command=self.freshTime).place(x=120, y=225) # ============================================================================================================== tab_character_info = ttk.Frame(tab_control) tab_control.add(text="性格信息", child=tab_character_info) # ============================================================================================================== tab_test_info = ttk.Frame(tab_control) tab_control.add(text="测试信息", child=tab_test_info) # ============================================================================================================== Label(self.root, text="九型人格测试系统V1.0", font=("", 26)).pack() tab_control.pack(expand=1, fill="both", pady=5) except Exception as e: print("这是error") logging.error(e) finally: self.root.mainloop()
def freshTime(self): querySQL = queryDB.queryDB() tuple_info = querySQL.selectUsers(self.uname, self.pwd) cur_time = querySQL.getTestTimeAndType(self.uname)[0] self.label_time['text'] = cur_time
# Reemplazamos la hora por la adecuada según el día initial_date = initial_date.replace(hour=0, minute=0, second=0) final_date = final_date.replace(hour=23, minute=59, second=59) # Pasamos a formato epoch (linux time) y quitamos los milisegundos (decimales) pasando de float a int initial_date_epoch = int(datetime.timestamp(initial_date)) final_date_epoch = int(datetime.timestamp(final_date)) queryParams = {} # Variamos la query para tener en cuenta el intervalo temporal. 's' es para especificar epoch en segundos queryParams['query'] = 'SELECT * FROM ber WHERE time >= '+str(initial_date_epoch)\ +'s AND time <= '+str(final_date_epoch)+'s' queryParams['tag'] = "obsId" queryParams['values'] = [ (i + 1) for i in range(100) ] # Cambio str(i+1) por (i+1) por coherencia con clasificador queryParams['variable'] = "BER" print("Query: ", queryParams['query']) print("\nLlegint dades de monitorització del", initial_date, "al", final_date, "...") BER_data, DB_JSON = queryDB(influxParams, queryParams) print("Classificant mesures...") new_class = pathClassifier_dyn(BER_data) print("Desant BD de visualització...") writeDB(influxParams, DB_JSON, new_class) print("Procés finalitzat correctament. Veure classificació a Grafana.")