How to use handle_csv method in autotest

Best Python code snippet using autotest_python

welcome.py

Source:welcome.py Github

copy

Full Screen

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()...

Full Screen

Full Screen

croped_and_predict.py

Source:croped_and_predict.py Github

copy

Full Screen

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', : ]...

Full Screen

Full Screen

find_removeable.py

Source:find_removeable.py Github

copy

Full Screen

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)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful