def Statistics(self,threshold, Test_Version, Test_Batch): Time_Stamp = int(time.time()) sql = "select * from %s WHERE test_version='%s' AND test_batch='%s' ;" % ( 'start_recording', Test_Version, Test_Batch) Total_Type = Query_DB().query_db_all(sql)[-1]['Total_Type'] # 查测试类型数 sql = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' ;" % ( 'results_summary', Test_Version, Test_Batch) A = Query_DB().getnum(sql) # 查询汇总进度 if Total_Type > A: datalist = Statistics().results_summary(threshold, Test_Version, Test_Batch, Time_Stamp) Total = len(datalist) logger.info('写入数据中……') for i in range(A, Total): InsertDB().insert_Result('results_summary', datalist[i]) elif Total_Type == A: logger.info('结果汇总页已经汇总完成,无需再次汇总!') else: logger.error('未知错误:预期总数%s,实际生成数%s' % (Total_Type, A)) sql = "select * from %s WHERE test_version='%s' AND test_batch='%s' ;" % ('summary', Test_Version, Test_Batch) datalist = Query_DB().query_db_all(sql) # 查询 if len(datalist) == 0: logger.info('写入数据中……') Statistics().summary_hz(threshold, Test_Version, Test_Batch, Time_Stamp) elif len(datalist) == 1: logger.info('汇总语页数据,已经写入完成,无需再次汇总!') else: logger.error('未知错误,计数:%s ,数据:%s' % (len(datalist), datalist))
def get_start_recording(self): #获取版本和批次号 sql = "select * from %s WHERE deletes=0;" % ('algorithm_version') sql_batch = "select * from %s WHERE deletes=0;" % ('sample_batch') list_row_version = Query_DB().query_db_all(sql) list_row_batch = Query_DB().query_db_all(sql_batch) Test_Batch = [] Test_Version = [] dicdata = {} Test_Version.sort() Test_Version.sort() for i in list_row_batch: Test_Batch.append(i['batch']) dicdata.update({i['batch']: i}) for i in list_row_version: Test_Version.append(i['version']) dic = { "message": "操作成功", "result_code": "0000", #"counts": len(list_row), 'Test_Batch': list(set(Test_Batch)), 'Test_Version': list(set(Test_Version)), #"datalist":list_row , 'dicdata': dicdata } return json.dumps(dic)
def Addtestinfo(self, dicdata): #添加算法 table_name = 'algorithm_version' dic_value = list(dicdata.values()) version, Test_Time, developer, deletes = dic_value Test_Time = Test_Time.replace('T', " ") sql_chachong = "select count(*) from %s WHERE version='%s';" % ( table_name, version) sql_chachong_0 = "select count(*) from %s WHERE deletes=0 and version='%s';" % ( table_name, version) sql_chachong_1 = "select count(*) from %s WHERE deletes=1 and version='%s';" % ( table_name, version) if Query_DB().getnum(sql_chachong_0) != 0: #显示的存在,提示已存在 dic = { "message": "该版本号在数据库中已存在,请重新添加!", "result_code": "0001", "datalist": [], } return json.dumps(dic) elif Query_DB().getnum(sql_chachong_1) != 0: #不显示的存在,更新它 sql = "UPDATE %s SET version='%s',Test_Time='%s',developer='%s',deletes=%s WHERE version='%s';" % ( table_name, version, Test_Time, developer, deletes, version) logger.info(sql) InsertDB().insert_all_data(sql) dic = { "message": "操作成功", "result_code": "0000", "datalist": [], } return json.dumps(dic) elif Query_DB().getnum(sql_chachong) == 0: #均不在的插入 # logger.info([test_batch, test_version, test_time, template, test_chart, expected_range, test_type, test_value, Timeconsuming, result, Color, Template_path, TestChart_path]) # SQL 插入语句 sql = "INSERT INTO %s (version,Test_Time,developer,deletes) \ VALUES ('%s','%s','%s',%s)" % \ (table_name, version, Test_Time, developer, deletes) logger.info(sql) InsertDB().insert_all_data(sql) dic = { "message": "操作成功", "result_code": "0000", "datalist": [], } return json.dumps(dic)
def SampleBatch(self, dicdata): #添加样本 table_name = 'sample_batch' dic_value = list(dicdata.values()) batch, types_num, total_num, Test_Time, deletes, batch_path = dic_value Test_Time = Test_Time.replace('T', " ") sql_chachong_0 = "select count(*) from %s WHERE deletes=0 and batch='%s';" % ( table_name, batch) sql_chachong_1 = "select count(*) from %s WHERE deletes=1 and batch='%s';" % ( table_name, batch) sql_chachong = "select count(*) from %s WHERE batch='%s';" % ( table_name, batch) if Query_DB().getnum(sql_chachong_0) != 0: dic = { "message": "该批次样本在数据库中已存在,请重新添加!", "result_code": "0001", "datalist": [], } return json.dumps(dic) elif Query_DB().getnum(sql_chachong_1) != 0: # sql = "UPDATE %s SET (batch,types_num,total_num,Test_Time,deletes,batch_path) \ # VALUES ('%s',%s,%s,'%s',%s,'%s') WHERE batch=%s;" % \ # (table_name, batch,types_num,total_num,Test_Time,deletes,batch_path,batch) sql = "UPDATE %s SET batch='%s',types_num=%s,total_num=%s,Test_Time='%s',deletes=%s,batch_path='%s' WHERE batch='%s';" % ( table_name, batch, types_num, total_num, Test_Time, deletes, batch_path, batch) InsertDB().insert_all_data(sql) dic = { "message": "操作成功", "result_code": "0000", "datalist": [], } return json.dumps(dic) elif Query_DB().getnum(sql_chachong) == 0: # logger.info([test_batch, test_version, test_time, template, test_chart, expected_range, test_type, test_value, Timeconsuming, result, Color, Template_path, TestChart_path]) # SQL 插入语句 sql = "INSERT INTO %s (batch,types_num,total_num,Test_Time,deletes,batch_path) VALUES ('%s',%s,%s,'%s',%s,'%s')" % \ (table_name, batch, types_num, total_num, Test_Time, deletes, batch_path) InsertDB().insert_all_data(sql) dic = { "message": "操作成功", "result_code": "0000", "datalist": [], } return json.dumps(dic)
def Proportion_zb(self, test_version, test_batch): dic_test = { '0~10%': 'AND Accuracy <=0.1', '10%~30%': 'And 0.1<Accuracy And Accuracy<=0.3', '30%~50%': 'And 0.3<Accuracy And Accuracy<=0.5 ', '50%~60%': 'And 0.5<Accuracy And Accuracy<=0.6 ', '60%~70%': 'And 0.6<Accuracy And Accuracy<=0.7 ', '70%~80%': 'And 0.7<Accuracy And Accuracy<=0.8 ', '80%~90%': 'And 0.8<Accuracy And Accuracy<=0.9 ', '90%~95%': 'And 0.9<Accuracy And Accuracy<=0.95 ', '95%~100%': 'And 0.95<Accuracy And Accuracy<=1 ', } listdata = [] for k, v in dic_test.items(): sql = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' %s ;" % ( 'results_summary', test_version, test_batch, v) print(sql) num = Query_DB().getnum(sql) # 查询测试进度 listdata.append([k, str(num)]) dic = { "message": "操作成功", "result_code": "0000", "datalist": listdata, } return json.dumps(dic)
def login_ajax_check(self, dic): logger.info(dic) sql_all = "select * from users WHERE user_name='%s' and pwd='%s';" % ( dic['username'], dic['password']) list_all = Query_DB().query_db_all(sql_all) if len(list_all) == 0: dic = { "message": "账户或密码错误", "result_code": "0001", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic) elif len(list_all) == 1: dic = { "message": "登录成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic) else: dic = { "message": "未知错误", "result_code": "4000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic)
def results_summary(self,threshold, Test_Version, Test_Batch, Time_Stamp): # 获取汇总测试数据 now = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(Time_Stamp)) table_name1 = 'test_record_sheet' Codelist = Query_DB().query_db_rowlist(table_name1, Test_Version, Test_Batch, 8) # 获取值列表 datalist = [] for i in range(len(Codelist)): sql_pass = "******" % ( table_name1, Test_Version, Test_Batch, Codelist[i]) sql_num = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' AND Code=%s ;" % ( table_name1, Test_Version, Test_Batch, Codelist[i]) sql_fial = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' AND Code=%s AND Result='FAIL';" % ( table_name1, Test_Version, Test_Batch, Codelist[i]) sql_error = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' AND Code=%s AND Result='ERROR';" % ( table_name1, Test_Version, Test_Batch, Codelist[i]) Test_Number = Query_DB().getnum(sql_num) PASS = Query_DB().getnum(sql_pass) FAIL = Query_DB().getnum(sql_fial) ERROR = Query_DB().getnum(sql_error) Accuracy = PASS / Test_Number if Accuracy >= threshold: Accuracylist = [Accuracy, 'c6efce_006100'] # ["%.2f%%" % (Accuracy * 100), ['c6efce','006100']] else: Accuracylist = [Accuracy, 'ffc7ce_9c0006'] # ["%.2f%%" % (Accuracy * 100), ['ffc7ce', '9c0006']] dic = { 'Test_ID': i + 1, 'Test_Batch': Test_Batch, 'Test_Version': Test_Version, 'Test_Time': now, 'Time_Stamp': Time_Stamp, 'Cultural_Name': cf.get("Data", str(Codelist[i])), 'Code': Codelist[i], 'Test_Number': Test_Number, 'PASS': PASS, "FAIL": FAIL, 'ERROR': ERROR, 'Accuracy': Accuracylist[0], 'Color': Accuracylist[1] } logger.info(dic) datalist.append(dic) # InsertDB().insert_Result('results_summary', dic) return datalist
def get_pic_data(self, dicdata): #获取测试记录页数据 table_name = 'test_record_sheet' test_version, test_batch, Code, Test_Chart = list(dicdata.values()) sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s' AND Code=%s AND Test_Chart='%s';" % ( table_name, test_version, test_batch, Code, Test_Chart) list_all = Query_DB().query_db_all(sql_all) sql_attribute = "select * from culturaldata WHERE code=%s;" % (Code) attribute = Query_DB().query_db_all(sql_attribute) #属性 dic = { "message": "操作成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, 'attribute': attribute } return json.dumps(dic)
def get_record_sheet_data(self, test_version, test_batch): #获取测试记录页数据 table_name = 'test_record_sheet' sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s';" % ( table_name, test_version, test_batch) list_all = Query_DB().query_db_all(sql_all) dic = { "message": "操作成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic)
def getform(self, dic): #获取数据 sql_all = "select * from %s WHERE deletes=0 ORDER BY %s DESC;" % ( dic['table_name'], dic['Latest_name']) list_all = Query_DB().query_db_all(sql_all) dic = { "message": "操作成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic)
def get_results_summary_data(self, test_version, test_batch): #获取汇总页的数据 table_name = 'results_summary' sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s';" % ( table_name, test_version, test_batch) list_all = Query_DB().query_db_all(sql_all) # del list_all[0]['deletes'] dic = { "message": "操作成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic)
def get_summary_data(self, test_version, test_batch): #获取汇总的结果 table_name = 'summary' sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s';" % ( table_name, test_version, test_batch) list_all = Query_DB().query_db_all(sql_all) logger.info(list_all) dic = { "message": "操作成功", "result_code": "0000", "counts": len(list_all), "datalist": list_all, } return json.dumps(dic)
def get_failimage(test_version, test_batch): table_name = 'test_record_sheet' sql = "select * from %s WHERE test_version='%s' AND test_batch='%s' and Result='FAIL';" % ( table_name, test_version, test_batch) list = Query_DB().query_db_all(sql) n = 1 for i in list: Image_Path = i['Image_Path'].replace('/', '\\') #print(Image_Path) code = Image_Path.split("\\")[-2] Failimgae(Image_Path, code) logger.info('%s/%s,复制《%s》……' % (n, len(list), Image_Path.split('\\')[-1])) n += 1
def download(self,filename, Test_Version, Test_Batch): # 下载数据到表格 addr=os.getcwd() + '\\excle\\'+filename logger.info('开始获取导出数据……') data = (CulturalAPI().get_summary_data(Test_Version, Test_Batch)) data1 = (CulturalAPI().get_results_summary_data(Test_Version, Test_Batch)) sql = "select * from %s WHERE test_version='%s' AND test_batch='%s' ;" % ( 'test_record_sheet', Test_Version, Test_Batch) logger.info(data) logger.info(data1) summary = json.loads(data)['datalist'][0] results_summary = json.loads(data1)['datalist'] record_sheet = Query_DB().query_db_all(sql) logger.info('开始导出数据到Excle!') ExportExcle(addr, record_sheet) SummaryExcle(addr, results_summary) VerticalExcle(addr, summary) logger.info('导出Excle完成!')
def Linechart(self, test_version, test_batch): dicdata = {"文物编号": [], "准确率": [], "文物名称": []} table_name = 'results_summary' sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s';" % ( table_name, test_version, test_batch) list_all = Query_DB().query_db_all(sql_all) for i in list_all: dicdata["文物编号"].append(i['Code']) dicdata["准确率"].append(i['Accuracy']) dicdata["文物名称"].append('') #i['Cultural_Name'] dic = { "message": "操作成功", "result_code": "0000", "datalist": dicdata, } return json.dumps(dic)
def del_summary_data(self, dics): #删除一个汇总结果 dic_values = list(dics.values()) dic_keys = list(dics.keys()) #sql_all = "select * from %s WHERE test_version='%s' AND test_batch='%s';" % (table_name, test_version, test_batch) sql_all = "UPDATE %s SET deletes=1 WHERE %s='%s' and %s='%s';" % ( dic_values[0], dic_keys[1], dic_values[1], dic_keys[2], dic_values[2]) list_all = Query_DB().db_all_No_return(sql_all) logger.info(list_all) #del list_all[0]['deletes'] dic = { "message": "操作成功", "result_code": "0000", # "counts": len(list_all), # "datalist":list_all , } return json.dumps(dic)
def TestValue2(rootdir, proce,Test_Batch,Test_Version,Batchinfo):#支持多进程 Time_Stamp = int(time.time()) now =time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(Time_Stamp)) manager = Manager() lock = manager.Lock() # 产生钥匙 datalist=Pathlsit(rootdir) listPath = datalist[0] Total = Batchinfo['total_num'] sql = "select count(*) from %s WHERE test_version='%s' AND test_batch='%s' ;" % ('test_record_sheet',Test_Version,Test_Batch) A = Query_DB().getnum(sql)#查询测试进度 start_dic={"RunTime":now,"RunTime_int":Time_Stamp,"Test_Batch":Test_Batch,"Test_Version":Test_Version,"Total_Type":Batchinfo['types_num'],"Sum_Numbers": Total,"Completed":A} # logger.info(start_dic) InsertDB().insert_Start_recording( 'start_recording', start_dic)#写入启动测试记录 pool = multiprocessing.Pool(processes=proce) for i in range(A , Total): pool.apply_async(func=process, args=(listPath[i],Total,i,lock,Test_Batch,Test_Version,Batchinfo)) pool.close() pool.join() # 在join之前一定要调用close,否则报错