Best Python code snippet using autotest_python
welcome.py
Source: welcome.py
1import sys2import os3from PyQt5.QtCore import pyqtSignal4from PyQt5.QtGui import QFont5from PyQt5.QtWidgets import (6 QApplication,7 QWidget,8 QPushButton,9 QLabel,10 QComboBox,11 QTableWidget,12 QAbstractItemView,13 QTableWidgetItem,14 QHeaderView)15import csv16import pandas as pd17import numpy as np18from enger_charge_project.interface.standard_tech import Ui_Form as Std_Tech_Form19class Handle_CSV(object):20 def __init__(self, table):21 self.table = table22 def read_from_file(self):23 """读åcsvæ件çå
容å°QTableWidget对象ä¸"""24 i = 0 # åå§åä¸ä¸ªè®¡æ°å¨25 with open('energy_charge_info.csv', encoding="gbk") as f:26 reader = csv.reader(f)27 for row in reader:28 for content in row:29 if content == 'æ¶é´':30 break # è¿éè½ç¶ç¨çbreakï¼ä½æ¯åé常çç¨æ³ä¸ä¸æ ·31 new_item = QTableWidgetItem(content)32 self.table.setItem(i - 1, row.index(content), new_item) # åï¼ è¡ï¼ å
容33 # å¢å ä¸ä¸ªè®¡æ°34 i += 135 def write_to_file(self):36 # TODO æ天å37 pass38class StandardTechTnterface():39 pass40class WelocomeInterface(QWidget):41 def __init__(self):42 super().__init__()43 self.title = '欢è¿ä½¿ç¨è¡ç¥èè½çµå大æ°æ®ç³»ç»ï¼'44 self.left = 1045 self.top = 1046 self.width = 84047 self.height = 68048 self.initUI()49 def initUI(self):50 self.setWindowTitle(self.title)51 self.setGeometry(self.left, self.top, self.width, self.height)52 # æ¥çæé®53 self.button_watch = QPushButton('æ¥ç', self)54 self.button_watch.setToolTip('å¯ä»¥ç¹å»æ¥çå
·ä½ççµè´¹ç»æ')55 self.button_watch.move(200, 100)56 self.button_watch.clicked.connect(self.watch_energy_charge_table)57 # ä¿®æ¹æé®58 self.button_update = QPushButton("ä¿®æ¹", self)59 self.button_update.setToolTip("å¯ä»¥ç¹å»ä¿®æ¹å
·ä½ççµè´¹ç»æ")60 self.button_update.move(400, 100)61 self.button_update.clicked.connect(self.update_energy_charge_table)62 # è¿åæé®63 self.button_back = QPushButton('è¿å', self)64 # self.label_back = QLabel("è¿å", self.table_energy_charge)65 self.button_back.move(600, 100)66 self.button_back.clicked.connect(self.go_back_welcome)67 # 欢è¿æ è¯68 font = QFont()69 font.setFamily("Algerian")70 font.setPointSize(16)71 self.label_welcome = QLabel("欢è¿ä½¿ç¨è¡ç¥èè½çµå大æ°æ®ç³»ç»ï¼", self)72 self.label_welcome.move(140, 50)73 self.label_welcome.setFont(font)74 # çµè´¹ç»ææ ç¾75 self.label_energy_charge_structure = QLabel("çµè´¹ç»æ", self)76 self.label_energy_charge_structure.move(100, 100)77 # 设å¤éæ©æ ç¾78 self.label_equipment = QLabel("设å¤éæ©", self)79 self.label_equipment.move(100, 150)80 # ä¸æææ¬æ¡81 self.ComboBox_equipment_options = QComboBox(self)82 self.ComboBox_equipment_options.move(200, 150)83 items = ['%då·ä¸é¢ç' % item for item in range(1, 11)]84 items += ["%då·è¿åç" % item for item in range(1, 7)]85 self.ComboBox_equipment_options.addItems(items)86 # ä¸æææ¬æ¡çä¿¡å·æºå¶87 self.ComboBox_equipment_options.currentIndexChanged[str].connect(self.get_value)88 # çµè´¹ä»·æ ¼è¡¨ å®ä¾å89 self.table_energy_charge = QTableWidget(self)90 self.table_energy_charge.resize(640, 400)91 self.table_energy_charge.move(60, 200)92 self.table_energy_charge.setToolTip("åå»è¿è¡ä¿®æ¹")93 # 设置表头çèæ¯è²ä¸ºç°è²94 self.table_energy_charge.horizontalHeader().setStyleSheet('QHeaderView::section{background:grey}')95 self.table_energy_charge.setRowCount(24) # 23è¡96 self.table_energy_charge.setColumnCount(3) # 3å97 # 设置éå
容èªå¨è°æ´å宽98 self.table_energy_charge.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)99 self.table_energy_charge.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)100 self.table_energy_charge.setHorizontalHeaderLabels(['æ¶é´', "å³°å¼ç±»å", "çµä»·(å
/度)"]) # å建表头101 self.table_energy_charge.hide() # å¿
é¡»ï¼é»è®¤éè102 # æ åå·¥èºåºççé¢103 self.std_tech_form = Std_Tech_Form()104 self.std_tech_form.setupUi(self.std_tech_form)105 self.show()106 def watch_energy_charge_table(self):107 """æ¥ççµè´¹ä»·æ ¼è¡¨"""108 # 注æï¼ è¯»åçæ¶åç¦æ¢ç¼è¾109 self.table_energy_charge.hide()110 self.table_energy_charge.setEditTriggers(QAbstractItemView.NoEditTriggers) # TODO æé®é¢111 # ä»æ件读å112 handle_csv = Handle_CSV(self.table_energy_charge)113 handle_csv.read_from_file()114 # å±ç¤º115 self.table_energy_charge.show()116 def update_energy_charge_table(self):117 # ä»æ件读å(è¿ä¸æ¥å¿
é¡»çï¼ å½ä¸è¿è¡æ¥çç´æ¥ä¿®æ¹çæ¶åï¼ é»è®¤è¦æä¸è¥¿ä¾ä¿®æ¹)118 self.table_energy_charge.hide()119 self.table_energy_charge.setEditTriggers(QAbstractItemView.DoubleClicked) # åå»è¿å
¥ä¿®æ¹ç¶æ120 # ä»æ件读å121 handle_csv = Handle_CSV(self.table_energy_charge)122 handle_csv.read_from_file()123 self.table_energy_charge.show()124 # TODO åååå
¥æ件ï¼ä»¥ä¾ä¸ä¸æ¬¡è¯»å125 item = self.table_energy_charge.selectedItems()126 try:127 origin_item_content = item[0].text()128 except Exception as e:129 pass130 else:131 row = self.table_energy_charge.currentRow() # è¡å·ï¼ ä»0å¼å§è®¡æ°132 col = self.table_energy_charge.currentColumn() # åå·ï¼ä»0å¼å§è®¡æ°133 if len(item) == 0:134 pass135 else:136 print(item[0].text())137 print(col)138 print(row)139 def go_back_welcome(self):140 self.table_energy_charge.hide()141 def get_value(self, value):142 """è·åä¸æå表çå
å®¹ï¼ å¹¶æå°"""143 print(value)144 name = value145 # for k, v in name_dic.items():146 # if v == value:147 # print(k, v)148 # imei = imei_dic.get(k, None)149 #150 # data = check_exist_std_hub(name, imei)151 # TODO 跳转å°å¯¹åºçå·¥èºä¸152 self.std_tech_form.show()153 self.std_tech_form.pushButton_2.clicked.connect(self.std_tech_form.get_time_data)154 # sys.exit(app.exec_())155if __name__ == '__main__':156 app = QApplication(sys.argv)157 welcome_interface = WelocomeInterface()...
croped_and_predict.py
Source: croped_and_predict.py
1import numpy as np2from PIL import Image3import os4from Model import *5import pandas as pd6def crop_image(filepath, box, width, height, nparray=False):7 res = []8 assert len(box) == 49 x1, y1, x2, y2 = box10 x1, y1, x2, y2 = round(x1), round(y1), round(x2), round(y2)11 res = Image.open(filepath).crop((x1,y1,x2,y2)).resize((width,height), Image.ANTIALIAS)12 if nparray:13 # res = np.array( list(map(lambda x:np.array(x),res)) )14 res = np.array(res)15 return res16def crop_image_generator(rootpath, filepaths, all_image_bboxes, width, height):17 i = 018 while i < len(filepaths):19 croped_images = crop_image(os.path.join(rootpath, filepaths[i]), all_image_bboxes[i], width, height, nparray=True)20 croped_images = np.expand_dims(croped_images,axis=0) / 255.021 i += 122 yield croped_images23def classify_main(rootpath, filepaths, all_image_bboxes):24 class_indices = {'0': 0, '1': 1, '10': 2, '11': 3, '12': 4, '13': 5, '14': 6, '15': 7, '16': 8, '17': 9, '18': 10, '19': 11, '2': 12, '20': 13, '21': 14, '22': 15, '23': 16, '24': 17, '25': 18, '26': 19, '27': 20, '28': 21, '29': 22, '3': 23, '30': 24, '31': 25, '32': 26, '33': 27, '34': 28, '35': 29, '36': 30, '37': 31, '38': 32, '39': 33, '4': 34, '40': 35, '41': 36, '42': 37, '43': 38, '44': 39, '45': 40, '46': 41, '47': 42, '48': 43, '49': 44, '5': 45, '50': 46, '51': 47, '52': 48, '53': 49, '54': 50, '55': 51, '56': 52, '57': 53, '58': 54, '59': 55, '6': 56, '60': 57, '7': 58, '8': 59, '9': 60}25 class_indices = dict((v,k) for k,v in class_indices.items())26 width = 22427 height = 11228 model = DenseNetTransfer((height,width,3), channel=4)29 model.load_weights("Transfer-densenet.h5", by_name=True)30 handle = open("temp.txt", "w+")31 # ret = []32 gen = crop_image_generator(rootpath, filepaths, all_image_bboxes, width,height)33 # åç´ å¼å½ä¸å34 predict_res = model.predict_generator(gen, steps=len(filepaths), use_multiprocessing=True, max_queue_size=100)35 label = np.argmax(predict_res, axis=1)36 label = [ class_indices[l] for l in label ]37 score = np.max(predict_res, axis=1)38 for k,l in enumerate(label):39 # if l == "0":40 # continue41 handle.write("{} {} {}\n".format(filepaths[k], l, score[k]) )42 # return ret43if __name__ == '__main__':44 rootpath = "/home/Signboard/second/datasets/test/"45 temp_res_file = "merge.txt"46 handle_csv = pd.read_csv(temp_res_file, sep=' ', names=['filepath', "label", 'score', 'xmin', 'ymin', 'xmax', 'ymax'],47 dtype={"filepath":"str"})48 all_image_bboxes = handle_csv.loc[:,['xmin', 'ymin', 'xmax', 'ymax']].values49 classify_main(rootpath, handle_csv['filepath'].tolist(), all_image_bboxes)50 res_csv = pd.read_csv("temp.txt", sep=' ', names=['filepath', "label", 'score'], dtype={"filepath":"str", "label":"str", "score":"str"})51 handle_csv['label'] = res_csv['label']52 handle_csv['score'] = res_csv['score']53 handle_csv['xmin'] = handle_csv['xmin'].map(lambda x:str(int(round(x))) )54 handle_csv['ymin'] = handle_csv['ymin'].map(lambda x:str(int(round(x))) )55 handle_csv['xmax'] = handle_csv['xmax'].map(lambda x:str(int(round(x))) )56 handle_csv['ymax'] = handle_csv['ymax'].map(lambda x:str(int(round(x))) )57 handle_csv = handle_csv.loc[ handle_csv['label'] != '0', : ]...
find_removeable.py
Source: find_removeable.py
1import pandas as pd2import numpy as np3import os4import itertools5def MergeResult(Submission_path):6 fileLists = os.listdir(Submission_path)7 true_label = pd.read_csv("test_groundtruth.csv", sep=' ', names=['id', 'label_true'])8 for fileList in itertools.combinations(fileLists, 2):9 if fileList[0].split(".")[-1] != "csv" or fileList[1].split(".")[-1] != "csv":10 continue11 # ç»è®¡æ¯ä¸è¡æ¬¡æ°åºç°æå¤çæ°å12 result_handle_1 = pd.read_csv(os.path.join(Submission_path,fileList[0]),sep=' ',names=['id','label_1'])13 result_handle_2 = pd.read_csv(os.path.join(Submission_path,fileList[1]),sep=' ',names=['id','label_2'])14 handle_csv = true_label.merge(result_handle_1, how='left', on='id').merge(result_handle_2, how="left", on="id")15 result_1_index = set(handle_csv[ handle_csv['label_1'] == handle_csv['label_true'] ].index)16 result_2_index = set(handle_csv[ handle_csv['label_2'] == handle_csv['label_true'] ].index)17 if result_1_index & result_2_index == result_2_index:18 print("Dropable:{}, compared to {}".format(fileList[1], fileList[0]))19 elif result_1_index & result_2_index == result_1_index:20 print("Dropable:{}, compared to {}".format(fileList[0], fileList[1]))21if __name__ == '__main__':22 Submission_path = "../Submission"23 test_truth = "test_groundtruth.csv"24 MergeResult(Submission_path)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!