【python实战】-- 选择解压汇总mode进行数据汇总20250329更新
系列文章目录
文章目录
- 系列文章目录
- 前言
- 一、功能列表
- 二、程序如下:
- 总结
前言
一、功能列表
该模板用于多功能数据汇总处理:
1、用于解压压缩包,输入指定路径,即可解压多级压缩文件;
2、镜筒反射率、LAB文件汇总;
3、镜片反射率数据汇总,区分S1、S2;
4、统计Lab,L值、a值、b值的NG占比;(新增)
5、按指定字符或正则表达式分类文件;(新增)
二、程序如下:
代码如下(示例):
import os
import shutil
import zipfile
import pandas as pd
import xlrd
import xlwt
import csv
from xlutils.copy import copy
from openpyxl import Workbook
from openpyxl import load_workbook
from os.path import dirname
from decimal import Decimal
from openpyxl.utils.dataframe import dataframe_to_rows
# 读写2007 excel
import openpyxl
from openpyxl.styles import numbers
from openpyxl.styles import Alignment
import glob
import tkinter as tk
from tkinter import messagebox
from tkinter import simpledialog
import re
from shapely.geometry import Polygon, Pointdef del_old_zip(file_path):os.remove(file_path)
def decompress(file_path,root):z = zipfile.ZipFile(f"{file_path}","r")z.extractall(path=f"{root}")for names in z.namelist():if names.endswith(file_flag):z.close()return 1z.close()return 0
def start_dir_make(root,dirname):os.chdir(root)os.mkdir(dirname)return os.path.join(root,dirname)
def rem_dir_extra(root,father_dir_name):try:for item in os.listdir(os.path.join(root,father_dir_name)):if not os.path.isdir(os.path.join(root,father_dir_name,item)):continueif item == father_dir_name and len(os.listdir(os.path.join(root,father_dir_name))) == 1:os.chdir(root)os.rename(father_dir_name,father_dir_name + '-old')shutil.move(os.path.join(root,father_dir_name + '-old', item),os.path.join(root))os.rmdir(os.path.join(root,father_dir_name + '-old'))rem_dir_extra(root,item)else:rem_dir_extra(os.path.join(root,father_dir_name),item)except Exception as e:print("清除文件夹出错"+str(e))
def get_allfile_msg(file_dir):for root, dirs, files in os.walk(file_dir):return root, dirs, [file for file in files if file.endswith('.xls') or file.endswith('.xlsx') or file.endswith('.csv')]
def get_allfile_url(root, files):allFile_url = []for file_name in files:file_url = root + "/" + file_nameallFile_url.append(file_url)return allFile_url
def get_file_name(path, suffix = ['.xlsx', '.xls','.csv']): #'.xlsx', '.xls',tmp_lst = []for root,dirs,files in os.walk(path):for file in files:tmp_lst.append(os.path.join(root, file))return tmp_lst
def extract_last_part_of_path(path):return os.path.basename(path)
#定义读取csv_pandas
def read_csv_file(file_path):#参数:error_bad_lines=False跳过错误的行 delimiter=',',encoding = 'gbk',header = 0, engine='python' sep = r"\s+\s{0}" encoding = "iso-8859-1"return pd.read_csv(file_path,encoding = 'latin1',sep = r"\s+\s{0}",dtype=object,quotechar="'",delimiter=',',doublequote=True,engine="python",header = 1) #第2行作为表头
def read_csv_file1(file_path):#参数:error_bad_lines=False跳过错误的行 delimiter=',',encoding = 'gbk',header = 0, engine='python' sep = r"\s+\s{0}" encoding = "iso-8859-1"return pd.read_csv(file_path,encoding = 'latin1',sep = r"\s+\s{0}",dtype=object,quotechar="'",delimiter=',',doublequote=True,engine="python",header = None,skiprows=lambda x:x not in [2,3,4]) #第2行作为表头
def count_and_list_folders(target_dir):try:if not os.path.exists(target_dir):raise FileNotFoundError(f"目录不存在:{target_dir}")if not os.path.isdir(target_dir):raise NotADirectoryError(f"路径不是目录:{target_dir}")folders = [entry.name for entry in os.scandir(target_dir) if entry.is_dir()] return foldersexcept Exception as e:print(f"错误:{str(e)}")
if __name__ == '__main__':#反射率标准S1和S2标准一致wave1start = 430wave1end = 530wave1standard = 1.5wave2start = 550wave2end = 780wave2standard = 1.1#**********************sort = input("请选择镜片还是镜筒:\n 1-解压 7-镜筒,9-镜片 lab-统计lab异常占比 c-分类汇总文件 \n")if sort == "1":zippath = input("请输入需解压的文件路径:\n")parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!") elif sort == "7":mode = input("请选择汇总模式: 1-待补充 2-汇总单机种 \n") if mode == "1":print("待补充,请期待")elif mode == "2": Summarypath = input("请输入汇总路径:汇总路径格式为:701/77b113e5-b3ad-4be2-8bcf-1544d5d901da/1.csv \n")#item = input("请输入汇总件号:(例如:39642A-701) \n")#user_input = input("请输入汇总model,LAB-L OR 反射率-F \n")position = input("请输入位置类型:上中下左右-5,上中下-3 \n")if position == "5":file_dir = Summarypathfolder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())count = 0item = 701with os.scandir(file_dir) as it:wb = Workbook()ws1 = wb.create_sheet('F')ws2 = wb.create_sheet('L') ws1.cell(row = 1,column = 1).value = '文件名' ws1.cell(row = 2,column = 1).value = 'wave' ws2.cell(row = 2,column = 1).value = 'L*' ws2.cell(row = 3,column = 1).value = 'a*' ws2.cell(row = 4,column = 1).value = 'b*' alignment = Alignment(horizontal='center',vertical='center')titles = ['data1','data2','data3','data4']for l in range(380,1051):ws1.cell(l-377,1).value = lws1.cell(l-377,1).alignment = alignmentcontinue#*******************************for entry in it:count += 1c = countm = c - 1if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.name+"\\"print(file_dir1)for root,dirs,files in os.walk(file_dir1):files_F = ['1.csv', '2.csv', '3.csv', '4.csv', '5.csv']files_L = ['1Add.csv', '2Add.csv', '3Add.csv', '4Add.csv', '5Add.csv']z = 0for f in files_F:z += 1y = z - 1df = read_csv_file(file_dir1+f)df = df.iloc[:,1:5]for k,title in enumerate(titles,2): ws1.cell(row = 2,column = k+4*y+4*m).value = titlews1.cell(row = 2,column = k+4*y+4*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+3,column = j+1+4*y+4*m).value = valuez = 0for l in files_L:z += 1y = z - 1df = read_csv_file1(file_dir1+l)df = df.iloc[0:3,1:5]for k,title in enumerate(titles,2): ws2.cell(row = 1,column = k+4*y+4*m).value = titlews2.cell(row = 1,column = k+4*y+4*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+2,column = j+1+4*y+4*m).value = value output_file_path=os.path.join(file_dir,f'Summaryout{item}.xlsx')wb.remove(wb['Sheet'])wb.save(output_file_path) elif position == "3":file_dir = Summarypathfolder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())count = 0item = 701with os.scandir(file_dir) as it:wb = Workbook()ws1 = wb.create_sheet('F')ws2 = wb.create_sheet('L') ws1.cell(row = 1,column = 1).value = '文件名' ws1.cell(row = 2,column = 1).value = 'wave' ws2.cell(row = 2,column = 1).value = 'L*' ws2.cell(row = 3,column = 1).value = 'a*' ws2.cell(row = 4,column = 1).value = 'b*' alignment = Alignment(horizontal='center',vertical='center')titles = ['data1','data2','data3','data4']for l in range(380,1051):ws1.cell(l-377,1).value = lws1.cell(l-377,1).alignment = alignmentcontinue#*******************************for entry in it:count += 1c = countm = c - 1if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.name+"\\"print(file_dir1)for root,dirs,files in os.walk(file_dir1):files_F = ['1.csv', '2.csv', '3.csv']files_L = ['1Add.csv', '2Add.csv', '3Add.csv']z = 0for f in files_F:z += 1y = z - 1df = read_csv_file(file_dir1+f)df = df.iloc[:,1:5]for k,title in enumerate(titles,2): ws1.cell(row = 2,column = k+4*y+4*m).value = titlews1.cell(row = 2,column = k+4*y+4*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+3,column = j+1+4*y+4*m).value = valuez = 0for l in files_L:z += 1y = z - 1df = read_csv_file1(file_dir1+l)df = df.iloc[0:3,1:5]for k,title in enumerate(titles,2): ws2.cell(row = 1,column = k+4*y+4*m).value = titlews2.cell(row = 1,column = k+4*y+4*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+2,column = j+1+4*y+4*m).value = value output_file_path=os.path.join(file_dir,f'Summaryout{item}.xlsx')wb.remove(wb['Sheet'])wb.save(output_file_path) else:print("指令错误,请重新运行。")else:print("指令错误,请重新运行。") elif sort == "9":mode = input("请选择汇总模式: 1待补充 2汇总单镜片 3解压汇总单镜片 4汇总单机种多镜片 5汇总多机种\n") if mode == "1":print("待补充,请期待")elif mode == "2": Summarypath = input("请输入汇总路径:路径格式:901/77b113e5-b3ad-4be2-8bcf-1544d5d901da \n")item = input("请输入汇总件号:(例如:39642A) \n")user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")standerd_input = input("是否需要标准?\n")if standerd_input == "Y":wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2") #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = Summarypathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs) #file_dir下的文件夹个数count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part) #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws2.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws2.cell(row = 2,column = n+2+3*m).value = cal1ws2.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max() cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max() cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet']) wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") elif standerd_input == "N":wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2") #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = Summarypathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs) #file_dir下的文件夹个数count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part) #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet']) wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") else:print("非指定指令!")elif mode == "3":zippath = input("请输入需解压的文件路径:\n")item = input("请输入汇总件号:(例如:39642A) \n")standerd_input = input("是否需要标准? \n")if standerd_input == "Y":parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!")print("请输入汇总model,S1或S2或S1S2或S1&S2")wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")#设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = parent_pathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs) #file_dir下的文件夹个数user_input = input("请输入S1或S2或S1S2或S1&S2\n")count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part) #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws2.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws2.cell(row = 2,column = n+2+3*m).value = cal1ws2.cell(row = 3,column = n+2+3*m).value = cal2continue#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max() cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max() cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet']) wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") elif standerd_input == "N":parent_path = zippathfile_flag = '.zip'flag = 1while flag:for root,dirs,files in os.walk(parent_path):for name in files:if name.endswith(file_flag):new_ws = start_dir_make(root,name.replace(file_flag,""))zip_path = os.path.join(root,name)flag = decompress(zip_path,new_ws)del_old_zip(zip_path)rem_dir_extra(root,name.replace(file_flag,""))print(f'{root}\\{name}'.join(['文件:','\n解压完成\n']))rem_dir_extra(os.path.split(parent_path)[0],os.path.split(parent_path)[1])print("解压完成,请检查!!")print("请输入汇总model,S1或S2或S1S2或S1&S2")wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2")#设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************#读取指定文件夹#file_dir = os.getcwd()file_dir = parent_pathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs) #file_dir下的文件夹个数user_input = input("请输入S1或S2或S1S2或S1&S2\n")count = 0for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {m} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part) #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1":df = df.iloc[:,1:4]df = df.astype(float)#print(df)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S2":df = df.iloc[:,4:7]df = df.astype(float)#print(df)#文件名输出区域ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "S1&S2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "S1":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S2'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet']) wb.save(output_file_path)elif user_input == "S1&S2":output_file_path=os.path.join(current_path,f'Summaryout{item}{user_input}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") else:print("非指定指令!")elif mode == "4":parent_path = input("请输入汇总路径:路径格式:39827A/901/000b1664-57f5-4de9-adf2-c029898a669c \n")#parent_path = r"D:\Users\gxcaoty\Desktop\桌面文件\2025.2.21\TO柳洋text\39827A"file_dir = parent_pathitem_1 = input("请输入汇总机种:(例如:39642A)\n")item_p = input("请输入汇总P数: (例如:5)\n")item_2 = int('90'+str(item_p))standerd_input = input("是否需要标准? \n")if standerd_input == "Y":folder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())print(folder_count)user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")#standerd_input = input("是否需要标准?\n") with os.scandir(file_dir) as it:for entry in it:if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.nameprint(file_dir1)file_dir2 = file_dir1.replace("\\","")count = 0wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2") #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 1,column = 1).value = '判定'ws.cell(row = 1,column = 1).alignment = alignmentws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 1,column = 1).value = '判定'ws1.cell(row = 1,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 1,column = 1).value = '判定'ws2.cell(row = 1,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*******************************for root,dirs,files in os.walk(file_dir1):for file_path in glob.glob(os.path.join(root,'*.csv')):for j in range(901,item_2+1):item = item_1 + '-' + str(j)if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {c} 个文件!")try:last_part = extract_last_part_of_path(xl)filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1&S2":df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws1.cell(row = 2,column = 1).value = combinedwave1ws2.cell(row = 2,column = 1).value = combinedwave1ws1.cell(row = 3,column = 1).value = combinedwave2ws2.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,3):cal1 = df1.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df1.iloc[wave2start-380+2:wave2end-380+2,n].max() cal3 = df2.iloc[wave1start-380+2:wave1end-380+2,n].max() cal4 = df2.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws1.cell(row = 1,column = n+2+3*m).value = "OK"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws1.cell(row = 1,column = n+2+3*m).value = "NG"ws1.cell(row = 1,column = n+2+3*m).alignment = alignmentif cal3 <= wave1standard and cal4 <= wave2standard :ws2.cell(row = 1,column = n+2+3*m).value = "OK"ws2.cell(row = 1,column = n+2+3*m).alignment = alignmentelse:ws2.cell(row = 1,column = n+2+3*m).value = "NG"ws2.cell(row = 1,column = n+2+3*m).alignment = alignment#print(ave1,ave2)ws1.cell(row = 2,column = n+2+3*m).value = cal1ws1.cell(row = 3,column = n+2+3*m).value = cal2ws2.cell(row = 2,column = n+2+3*m).value = cal3ws2.cell(row = 3,column = n+2+3*m).value = cal4continue#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#**********************************************************combinedwave1 = f'{wave1start},{wave1end},{wave1standard}'combinedwave2 = f'{wave2start},{wave2end},{wave2standard}'#print(combinedwave1)ws.cell(row = 2,column = 1).value = combinedwave1ws.cell(row = 3,column = 1).value = combinedwave2#***********************************************************#计算判定区域for n in range(0,6):cal1 = df.iloc[wave1start-380+2:wave1end-380+2,n].max() cal2 = df.iloc[wave2start-380+2:wave2end-380+2,n].max() if cal1 <= wave1standard and cal2 <= wave2standard :ws.cell(row = 1,column = n+2+6*m).value = "OK"ws.cell(row = 1,column = n+2+6*m).alignment = alignmentelse:ws.cell(row = 1,column = n+2+6*m).value = "NG"ws.cell(row = 1,column = n+2+6*m).alignment = alignment#print(ave1,ave2)ws.cell(row = 2,column = n+2+6*m).value = cal1ws.cell(row = 3,column = n+2+6*m).value = cal2continue#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelse :print("指定错误,请重新运行!")except Exception as e:print(e) if user_input == "S1&S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else:print("指令错误,请重新运行!")elif standerd_input == "N":print("请输入汇总model,S1或S2或S1S2或S1&S2") folder_count = sum(1 for _ in os.scandir(file_dir) if _.is_dir())print(folder_count)user_input = input("请输入汇总model,S1或S2或S1S2或S1&S2 \n")#standerd_input = input("是否需要标准?\n") with os.scandir(file_dir) as it:for entry in it:if entry.is_dir():print(entry.name)file_dir1 = file_dir+'\\'+entry.nameprint(file_dir1)file_dir2 = file_dir1.replace("\\","")count = 0wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2") #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*******************************for root,dirs,files in os.walk(file_dir1):for file_path in glob.glob(os.path.join(root,'*.csv')):for j in range(901,item_2+1):item = item_1 + '-' + str(j)if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {c} 个文件!")try:last_part = extract_last_part_of_path(xl)filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "S1&S2":df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelif user_input == "S1S2":df = df.iloc[:,1:7]df = df.astype(float)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelse:print("指令错误,请重新运行!")except Exception as e:print(e) if user_input == "S1&S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)elif user_input == "S1S2":output_file_path=os.path.join(entry,f'Summaryout{item_1}{"-"}{user_input}{entry.name}.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else:print("指令错误,请重新运行!")elif mode == "5":#读取指定文件夹#file_dir = os.getcwd()Summarypath = input("请输入汇总路径:路径格式:合并/每个件号一个文件夹\n") #Summarypath = r"D:\Users\gxcaoty\Desktop\11\合并" folders_name = count_and_list_folders(Summarypath)print(folders_name)user_input = input("请输入汇总model,1-S1S2或2-S1&S2 \n")for fol in folders_name:fol_path = Summarypath + '\\' + folitem = str(fol) file_dir = fol_path #Summarypathcurrent_path = os.path.dirname(os.path.abspath(__file__))#file_dir = r"D:\Users\gxcaoty\Desktop\39526-905\一车间"root, dirs, files = get_allfile_msg(file_dir)allFile_url = get_allfile_url(root, files)dir_numbers = len(dirs) #file_dir下的文件夹个数count = 0wb = Workbook()#ws = wb.active#ws.title="Summary"ws = wb.create_sheet("S1S2")ws1 = wb.create_sheet("S1")ws2 = wb.create_sheet("S2") #设置所有单元格的对齐方式为居中alignment = Alignment(horizontal='center',vertical='center') titlesS1 = ['data1','data2','data3'] titlesS2 = ['data4','data5','data6'] titlesS1S2 = ['data1','data2','data3','data4','data5','data6']#第一列波段设置区域ws.cell(row = 5,column = 1).value = '文件名'ws.cell(row = 5,column = 1).alignment = alignmentws.cell(row = 6,column = 1).value = 'wave'ws.cell(row = 6,column = 1).alignment = alignmentws1.cell(row = 5,column = 1).value = '文件名'ws1.cell(row = 5,column = 1).alignment = alignmentws1.cell(row = 6,column = 1).value = 'wave'ws1.cell(row = 6,column = 1).alignment = alignmentws2.cell(row = 5,column = 1).value = '文件名'ws2.cell(row = 5,column = 1).alignment = alignmentws2.cell(row = 6,column = 1).value = 'wave'ws2.cell(row = 6,column = 1).alignment = alignmentfor l in range(380,1051):ws.cell(l-373,1).value = lws.cell(l-373,1).alignment = alignmentws1.cell(l-373,1).value = lws1.cell(l-373,1).alignment = alignmentws2.cell(l-373,1).value = lws2.cell(l-373,1).alignment = alignmentcontinue#*****************************************************************for root,dirs,files in os.walk(file_dir):for file_path in glob.glob(os.path.join(root,'*.csv')):if item in file_path and 'Add' not in file_path:print(file_path)xl = file_pathcount += 1c = countm = c - 1print(f"共发现 {c} 个文件!")#print(files_chose)try:last_part = extract_last_part_of_path(xl)#print(last_part) #filename为文件名filename = xl csv_data = read_csv_file(filename)df = csv_dataif user_input == "1":df = df.iloc[:,1:7]df = df.astype(float)#print(df)#文件名输出区域ws.cell(row = 5,column = 2+6*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1S2,2): ws.cell(row = 6,column = k+6*m).value = titlews.cell(row = 6,column = k+6*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws.cell(row = i+7,column = j+1+6*m).value = valueelif user_input == "2":#df = df.iloc[:,1:7]df1 = df.iloc[:,1:4]df2 = df.iloc[:,4:7]df1 = df1.astype(float)df2 = df2.astype(float)#文件名输出区域ws1.cell(row = 5,column = 2+3*m).value = last_part ws2.cell(row = 5,column = 2+3*m).value = last_part #标题输出区域(data1~data6)for k,title in enumerate(titlesS1,2): ws1.cell(row = 6,column = k+3*m).value = titlews1.cell(row = 6,column = k+3*m).alignment = alignmentcontinuefor k,title in enumerate(titlesS2,2): ws2.cell(row = 6,column = k+3*m).value = titlews2.cell(row = 6,column = k+3*m).alignment = alignmentcontinue#源数据输出区域for i ,row in df1.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws1.cell(row = i+7,column = j+1+3*m).value = valuefor i ,row in df2.iterrows():#print(i)for j ,value in enumerate(row,start=1):ws2.cell(row = i+7,column = j+1+3*m).value = valueelse:print("非指定指令")except Exception as e:print(e)if user_input == "1":output_file_path=os.path.join(current_path,f'Summaryout{item}S1S2.xlsx')wb.remove(wb['S1'])wb.remove(wb['S2'])wb.remove(wb['Sheet']) wb.save(output_file_path)elif user_input == "2":output_file_path=os.path.join(current_path,f'Summaryout{item}S1&S2.xlsx')wb.remove(wb['S1S2'])wb.remove(wb['Sheet'])wb.save(output_file_path)else :print("请检查程序!") else:print("非指定指令!!")elif sort == "lab":#定义平面ab标准L_p = 1.3a1,a2,a3,a4 = -0.1,0.15,0.75,-0.67b1,b2,b3,b4 = 0,0,-2.3,-2.3trapezoid_points_p = [(a1,b1),(a2,b2),(a3,b3),(a4,b4)]trapezoid_p = Polygon(trapezoid_points_p)#定义斜面ab标准L_x = 1.3c1,c2,c3,c4 = -0.1,0.15,0.75,-0.67d1,d2,d3,d4 = 0,0,-2.3,-2.3trapezoid_points_x = [(c1,d1),(c2,d2),(c3,d3),(c4,d4)]trapezoid_x = Polygon(trapezoid_points_x)jh = input("请输入统计件号:例如:39441A (路径下需包含的文件名例如39441A.xlsx) \n")facial = input("请输入统计面别:1-平面 2-斜面 3-平面/斜面 \n")if facial == "1":file_path = jh + ".xlsx"df = pd.read_excel(file_path,sheet_name="Sheet1",header=0) #usecols=[10,11]df_p = df[df.iloc[:,5] !="斜面"]df_p = df_p.iloc[:,[10,11,12]]points_p = df_p.values.tolist()inside_count_p = outside_count_p = y_condition_points_p = z_over_p = 0for x,y,z in points_p:point_p = Point(x,y)if trapezoid_p.contains(point_p):inside_count_p += 1else:outside_count_p += 1if (-2.3<y<0) and (not trapezoid_p.contains(point_p)):y_condition_points_p += 1if z > L_p:z_over_p += 1L_NGrate_p = (z_over_p/(inside_count_p+outside_count_p))passrate_p = (inside_count_p/(inside_count_p+outside_count_p))NGrate_p = (outside_count_p/(inside_count_p+outside_count_p))a_NGrate_p = (y_condition_points_p/(inside_count_p+outside_count_p))b_NGrate_p = ((outside_count_p-y_condition_points_p)/(inside_count_p+outside_count_p))print("以下为平面测试数据a值和b值NG占比分析")print(f"总测试点数:{inside_count_p+outside_count_p}")print(f"梯形内部OK点数:{inside_count_p} 通过率:{passrate_p:.2%}")print(f"梯形外部NG点数:{outside_count_p} NG率:{NGrate_p:.2%}")print(f"L值NG点数:{z_over_p} L值NG率:{L_NGrate_p:.2%}")print(f"a值NG点数:{y_condition_points_p} a值NG率:{a_NGrate_p:.2%}") #y∈(-2.3,0)且在外部的点数print(f"b值NG点数:{outside_count_p-y_condition_points_p} b值NG率:{b_NGrate_p:.2%}") elif facial == "2":file_path = jh + ".xlsx"df = pd.read_excel(file_path,sheet_name="Sheet1",header=0) #usecols=[10,11]df_x = df[df.iloc[:,5] !="平面"]df_x = df_x.iloc[:,[10,11,12]]points_x = df_x.values.tolist()inside_count_x = outside_count_x = y_condition_points_x = z_over_x = 0for x,y,z in points_x:point_x = Point(x,y)if trapezoid_x.contains(point_x):inside_count_x += 1else:outside_count_x += 1if (-2.3<y<0) and (not trapezoid_x.contains(point_x)):y_condition_points_x += 1if z > L_x:z_over_x += 1L_NGrate_x = (z_over_x/(inside_count_x+outside_count_x))passrate_x = (inside_count_x/(inside_count_x+outside_count_x))NGrate_x = (outside_count_x/(inside_count_x+outside_count_x))a_NGrate_x = (y_condition_points_x/(inside_count_x+outside_count_x))b_NGrate_x = ((outside_count_x-y_condition_points_x)/(inside_count_x+outside_count_x))print("以下为斜面测试数据a值和b值NG占比分析")print(f"总测试点数:{inside_count_x+outside_count_x}")print(f"梯形内部OK点数:{inside_count_x} 通过率:{passrate_x:.2%}")print(f"梯形外部NG点数:{outside_count_x} NG率:{NGrate_x:.2%}")print(f"L值NG点数:{z_over_x} L值NG率:{L_NGrate_x:.2%}")print(f"a值NG点数:{y_condition_points_x} a值NG率:{a_NGrate_x:.2%}") #y∈(-2.3,0)且在外部的点数print(f"b值NG点数:{outside_count_x-y_condition_points_x} b值NG率:{b_NGrate_x:.2%}") elif facial == "3":file_path = jh + ".xlsx"df = pd.read_excel(file_path,sheet_name="Sheet1",header=0) #usecols=[10,11]df_p = df[df.iloc[:,5] !="斜面"]df_p = df_p.iloc[:,[10,11,12]]points_p = df_p.values.tolist()inside_count_p = outside_count_p = y_condition_points_p = z_over_p = 0df_x = df[df.iloc[:,5] !="平面"]df_x = df_x.iloc[:,[10,11,12]]points_x = df_x.values.tolist()inside_count_x = outside_count_x = y_condition_points_x = z_over_x = 0for x1,y1,z1 in points_p:point_p = Point(x1,y1)if trapezoid_p.contains(point_p):inside_count_p += 1else:outside_count_p += 1if (-2.3<y1<0) and (not trapezoid_p.contains(point_p)):y_condition_points_p += 1if z1 > L_p:z_over_p += 1L_NGrate_p = (z_over_p/(inside_count_p+outside_count_p))passrate_p = (inside_count_p/(inside_count_p+outside_count_p))NGrate_p = (outside_count_p/(inside_count_p+outside_count_p))a_NGrate_p = (y_condition_points_p/(inside_count_p+outside_count_p))b_NGrate_p = ((outside_count_p-y_condition_points_p)/(inside_count_p+outside_count_p))for x2,y2,z2 in points_x:point_x = Point(x2,y2)if trapezoid_x.contains(point_x):inside_count_x += 1else:outside_count_x += 1if (-2.3<y2<0) and (not trapezoid_x.contains(point_x)):y_condition_points_x += 1if z2 > L_x:z_over_x += 1L_NGrate_x = (z_over_x/(inside_count_x+outside_count_x))passrate_x = (inside_count_x/(inside_count_x+outside_count_x))NGrate_x = (outside_count_x/(inside_count_x+outside_count_x))a_NGrate_x = (y_condition_points_x/(inside_count_x+outside_count_x))b_NGrate_x = ((outside_count_x-y_condition_points_x)/(inside_count_x+outside_count_x))print("以下为平面测试数据a值和b值NG占比分析:")print(f"总测试点数:{inside_count_p+outside_count_p}")print(f"梯形内部OK点数:{inside_count_p} 通过率:{passrate_p:.2%}")print(f"梯形外部NG点数:{outside_count_p} NG率:{NGrate_p:.2%}")print(f"L值NG点数:{z_over_p} L值NG率:{L_NGrate_p:.2%}")print(f"a值NG点数:{y_condition_points_p} a值NG率:{a_NGrate_p:.2%}") #y∈(-2.3,0)且在外部的点数print(f"b值NG点数:{outside_count_p-y_condition_points_p} b值NG率:{b_NGrate_p:.2%}") print("\n") print("以下为斜面测试数据a值和b值NG占比分析:")print(f"总测试点数:{inside_count_x+outside_count_x}")print(f"梯形内部OK点数:{inside_count_x} 通过率:{passrate_x:.2%}")print(f"梯形外部NG点数:{outside_count_x} NG率:{NGrate_x:.2%}")print(f"L值NG点数:{z_over_x} L值NG率:{L_NGrate_x:.2%}")print(f"a值NG点数:{y_condition_points_x} a值NG率:{a_NGrate_x:.2%}") #y∈(-2.3,0)且在外部的点数print(f"b值NG点数:{outside_count_x-y_condition_points_x} b值NG率:{b_NGrate_x:.2%}") else:print("指令错误,请重新输入。")elif sort =="c":sortmode = input("请输入分类模式: \n 1-按所需要包含的字符和不需要包含的字符分类(指定汇总前路径和汇总后目标路径) \n 2-按正则表达式自动分类汇总 \n")if sortmode == "1":source_dir = input("请输入源文件目录(分类前):\n")destination_dir = input("请输入目标路径(分类后):\n")include_char = input("请输入需要包含的字符(例如:39473A-905):\n") exclude_char = input("请输入需要排除的字符(例如Add): \n")# 确保目标目录存在os.makedirs(destination_dir, exist_ok=True)# 查找所有包含特定字符但不包含其他特定字符的CSV文件for filename in glob.glob(f"{source_dir}/**/*{include_char}*[!{exclude_char}].csv", recursive=True):# 将这些文件复制到目标目录shutil.copy(filename, destination_dir)elif sortmode == "2":folder_path = input("请输入要处理的文件夹路径(一级目录下):\n")jhgeshi = input("请输入件号格式:1-39441A-400 2-3596A-400 3-2M010A-400 4-所有类型 \n")if jhgeshi == "1":pattern = re.compile(r"(\d{5}[A-Z]-\d{3})")elif jhgeshi == "2":pattern = re.compile(r"(\d{4}[A-Z]-\d{3})")elif jhgeshi == "3":pattern = re.compile(r"(\d[A-Z]\d{3}[A-Z]-\d{3})")elif jhgeshi == "4":patterns = [re.compile(r"(\d{5}[A-Z]-\d{3})"),re.compile(r"(\d{4}[A-Z]-\d{3})"),re.compile(r"(\d[A-Z]\d{3}[A-Z]-\d{3})")]else:print("指令错误,请重新输入。")if jhgeshi == "1" or jhgeshi == "2" or jhgeshi == "3":count = 0for filename in os.listdir(folder_path):file_path = os.path.join(folder_path,filename)if not os.path.isfile(file_path):continuematch = pattern.search(filename)if match:count += 1folder_name = match.group(1)new_folder = os.path.join(folder_path,folder_name)os.makedirs(new_folder,exist_ok=True)dest_path = os.path.join(new_folder,filename)shutil.move(file_path,dest_path)print(f"文件'{filename}'已移动到'{folder_name}'文件夹。")print(f"\n处理完成!共找到{count}个匹配的文件。")elif jhgeshi == "4":count = 0for pat in patterns: for filename in os.listdir(folder_path):file_path = os.path.join(folder_path,filename)if not os.path.isfile(file_path):continuepattern = patmatch = pattern.search(filename)if match:count += 1folder_name = match.group(1)new_folder = os.path.join(folder_path,folder_name)os.makedirs(new_folder,exist_ok=True)dest_path = os.path.join(new_folder,filename)shutil.move(file_path,dest_path)print(f"文件'{filename}'已移动到'{folder_name}'文件夹。")print(f"\n处理完成!共找到{count}个匹配的文件。")else:print("非指定指令!!")else:print("非指定指令!!")
总结
分享:
我们的生活是否幸福并不是依靠外在的环境,而是依靠我们内在的信念。要想成为自己命运的主宰,我们就必须形成自己的信念。只要我们能坚定自己的内在信念,我们就能掌控自己外在的生活。所以,请把让自己感觉快乐幸福和有助于我们实现目标的观念变成自己信念。
相关文章:
【python实战】-- 选择解压汇总mode进行数据汇总20250329更新
系列文章目录 文章目录 系列文章目录前言一、功能列表二、程序如下:总结 前言 一、功能列表 该模板用于多功能数据汇总处理: 1、用于解压压缩包,输入指定路径,即可解压多级压缩文件; 2、镜筒反射率、LAB文件汇总&…...
Java 程序员面试题:从基础到高阶的深度解析
引言 Java 作为全球最流行的编程语言之一,其面试题不仅考察候选人的编程能力,更关注对底层原理和架构设计的理解。本文将系统梳理 Java 面试中的高频考点,结合代码示例与原理分析,助您从容应对技术面试。 一、Java 基础语法与核…...
JSP(实验):带验证码的用户登录
[实验目的] 1.掌握应用request对象获取表单提交的数据。 2.掌握解决获取表单提交数据产生中文乱码的问题。 3.掌握使用response对象进行定时跳转功能。 4.掌握使用session对象完成登录和注销功能。 [实验要求] 设计带验证码…...
【安全运营】关于攻击面管理相关概念的梳理(二)
CYNC(持续可见性和网络控制) CYNC(Continuous Visibility and Network Control)即“持续可见性和网络控制”,是一个与网络安全和IT运营管理相关的概念。它强调的是在一个组织的数字环境中,确保对所有资产、…...
【Linux篇】进程入门指南:操作系统中的第一步
步入进程世界:初学者必懂的操作系统概念 一. 冯诺依曼体系结构1.1 背景与历史1.2 组成部分1.3 意义 二. 进程2.1 进程概念2.1.1 PCB(进程控制块) 2.2 查看进程2.2.1 使用系统文件查看2.2.2 使⽤top和ps这些⽤⼾级⼯具来获取2.2.3 通过系统调用…...
Linux进程状态补充(10)
文章目录 前言一、阻塞二、挂起三、运行R四、休眠D五、四个重要概念总结 前言 上篇内容大家看的云里雾里,这实在是正常不过,因为例如 写实拷贝 等一些概念的深层原理我还没有讲解,大家不用紧张,我们继续往下学习就行!&…...
STM32_HAL开发环境搭建【Keil(MDK-ARM)、STM32F1xx_DFP、 ST-Link、STM32CubeMX】
安装Keil(MDK-ARM)【集成开发环境IDE】 我们会在Keil(MDK-ARM)上去编写代码、编译代码、烧写代码、调试代码。 Keil(MDK-ARM)的安装方法: 教学视频的第02分03秒开始看。 安装过程中请修改一下下面两个路径,避免占用C盘空间。 Core就是Keil(MDK-ARM)的…...
全自动数字网络机器人:重塑未来的无形引擎 ——从金融量化到万物互联,为何必须“ALL IN”?
全自动数字网络机器人:重塑未来的无形引擎 ——从金融量化到万物互联,为何必须“ALL IN”? (2025年3月29日) “未来十年,代码将比石油更具价值。” —— DeepSeek创始人梁文锋 一、数据洪流与AI进化&#…...
每日一题之修建灌木
问题描述 爱丽丝要完成一项修剪灌木的工作。 有 N 棵灌木整齐的从左到右排成一排。爱丽丝在每天傍晩会修剪一棵灌 木, 让灌木的高度变为 0 厘米。爱丽丝修剪灌木的顺序是从最左侧的灌木开始, 每天向右修剪一棵灌木。当修剪了最右侧的灌木后, 她会调转方向, 下一天开 始向左修…...
智能仪表板DevExpress Dashboard v24.2新版亮点:支持.NET 9
使用DevExpress BI Dashboard,再选择合适的UI元素(图表、数据透视表、数据卡、计量器、地图和网格),删除相应参数、值和序列的数据字段,就可以轻松地为执行主管和商业用户创建有洞察力、信息丰富的、跨平台和设备的决策…...
ubuntu下终端打不开的排查思路和解决方法
问题现象描述:ubuntu开机后系统桌面显示正常,其他图形化的app也都能打开无异常,唯独只有terminal终端打不开,无论是鼠标点击终端软件,还是ctrlaltt,还是altF2后输入gnome-terminal后按回车,这三…...
鸿蒙项目源码-天气预报app-原创!原创!原创!
鸿蒙天气预报项目源码包运行成功含文档ArkTS语言。 我半个月写的原创作品,请尊重原创。 原创作品,盗版必究!!!! 原创作品,盗版必究!!!! 原创作品…...
Turtle事件处理(键盘与鼠标交互)
Turtle 提供了 事件驱动编程,允许我们使用 键盘 和 鼠标 控制 Turtle,从而实现交互式绘图。例如,我们可以让 Turtle 响应 按键、鼠标点击 和 拖动 事件,使其根据用户的输入进行移动、旋转或绘制图形。 1. 事件机制概述 Turtle 的事件处理主要依赖 turtle.Screen() 提供的 …...
算法基础——模拟
目录 1 多项式输出 2.蛇形方阵 3.字符串的展开 模拟,顾名思义,就是题⽬让你做什么你就做什么,考察的是将思路转化成代码的代码能⼒。这类题⼀般较为简单,属于竞赛⾥⾯的签到题(但是,万事⽆绝对ÿ…...
惠普(HP)和联想(Lenovo)作为全球两大电脑品牌,并不是简单的“拼接电脑”
惠普(HP)和联想(Lenovo)作为全球两大电脑品牌,并不是简单的“拼接电脑”,它们都有自己的核心技术、专利设计和生态体系。以下是它们“自己的”核心部分: 1. 关键自研技术 品牌自研技术/专利说明…...
一些练习 C 语言的小游戏
一些练习 C 语言的小游戏 — 1. 猜数字游戏 描述:程序随机生成一个数字,玩家需要猜测这个数字,并根据提示(太高或太低)调整猜测,直到猜中为止。 功能点: 随机数生成 (rand() 函数)。循环和…...
曲线拟合 | Matlab基于贝叶斯多项式的曲线拟合
效果一览 代码功能 代码功能简述 目标:实现贝叶斯多项式曲线拟合,动态展示随着数据点逐步增加,模型后验分布的更新过程。 核心步骤: 数据生成:在区间[0,1]生成带噪声的正弦曲线作为训练数据。 参数设置:…...
Python 序列构成的数组(对序列使用+和_)
对序列使用和* Python 程序员会默认序列是支持 和 * 操作的。通常 号两侧的序列由 相同类型的数据所构成,在拼接的过程中,两个被操作的序列都不会被 修改,Python 会新建一个包含同样类型数据的序列来作为拼接的结果。 如果想要把一个序列…...
洛谷题单1-P5703 【深基2.例5】苹果采购-python-流程图重构
题目描述 现在需要采购一些苹果,每名同学都可以分到固定数量的苹果,并且已经知道了同学的数量,请问需要采购多少个苹果? 输入格式 输入两个不超过 1 0 9 10^9 109 正整数,分别表示每人分到的数量和同学的人数。 输…...
计算机网络 用deepseek帮助整理的复习资料(一)
### 计算机网络基础知识整理 --- #### **一、网络类型** 1. **局域网 (LAN)** - **定义**:覆盖小范围(如家庭、教室、公司)。 - **特点**:高带宽、低延迟,设备通过交换机互联。 - **示例**࿱…...
虚拟电商-话费充值业务(二)话费充值对接供应商模块开发
一、对接供应商模块开发 供应商对接模块chongba_recharge_supplier主要负责的就是调用外部的供应商系统进行充值下单,这种调用是一种基于HTTP协议的调用。 此外在供应商对接模块中主要是实现的业务逻辑有: 1:余额或押金不足情况下的失败轮…...
DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加行拖拽排序功能示例3,TableView16_03 拖拽视觉反馈示例
前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加行拖拽排序功能示例3,TableView16_03 拖…...
游戏引擎学习第186天
回顾并规划今天的任务 现在,我们站在了一个关键的时刻,准备突破,拥有一些优秀的性能分析代码。从目前来看,我们已经能够看到时间的消耗情况,我对这一点感到非常兴奋。昨天的直播中我们勉强让一些东西工作了࿰…...
树的基础_遍历(蓝桥云课)
一些树上问题: 树的直径: import java.util.*;public class TreeDiameter {static List<List<Integer>> tree; // 用邻接表存储树结构static int[] depth; // 记录每个节点的深度public static void main(String[] args) {S…...
29_项目
目录 http.js 1、先注册账号 register.html 2、再登录 login.html 3、首页 index.html 4 详情 details.html cart.html css index.css register.css details.css 演示 进阶 http.js let baseURL "http://localhost:8888"; let resgiterApi baseURL &…...
vue搭建一个树形菜单项目
首先搭建项目需要先通过步骤搭建一个vue的项目,然后创建一个component文件,里面新建一个index.vue页面来。 这是引入的element-ui组件库里的组件,来实现我的路由,渲染的是我存储的动态路由,所以需要先安装并且引用。 …...
Python包管理完全指南:pip常用命令与最佳实践
一、pip核心功能解析 作为Python官方推荐的包管理工具,pip承担着以下关键职责: 从PyPI(Python Package Index)仓库安装/卸载第三方库管理项目依赖关系和版本控制支持本地/私有仓库的包安装维护虚拟环境中的包隔离 二、20个必知…...
Eigen 3
本文来源:腾讯元宝 Eigen 3 是一个专注于线性代数运算的高性能 C 模板库,广泛应用于科学计算、机器学习、计算机视觉等领域。以下是其核心特性与功能的综合介绍: 1. 核心定义与设计理念 纯头文件库:Eigen 3 无需编译或链接…...
数字化转型国家标准- GB/T 45341-2025《数字化转型管理 参考架构》
GB/T 45341-2025《数字化转型管理 参考架构》 前言一、数字化转型的根本任务二、标准的主要内容2.1、 核心概念2.2、总体框架2.3、 主要视角2.4、过程方法2.5、 发展阶段与水平档次 前言 在工业和信息化部和国家标准化管理委员会的指导下,全国信息化和工业化融合管…...
Redis 源码硬核解析系列专题 - 第三篇:核心数据结构之字典(Dict)
1. 引言 字典(Dict)是Redis的核心数据结构之一,用于实现键值存储(Redis数据库的核心)和内部元数据管理(如客户端状态)。Redis的字典基于哈希表实现,支持高效的增删改查操作。本篇将深入剖析其源码实现,包括哈希表结构、冲突解决和渐进式rehash机制。 2. 字典的结构体…...
JS—异步编程:3分钟掌握异步编程
个人博客:haichenyi.com。感谢关注 一. 目录 一–目录二–引言三–JavaScript 事件循环机制四–定时器的秘密:setTimeout 和 setInterval五–异步编程模型对比 二. 引言 在现代Web开发中,异步编程是提升性能的关键技术。无论是脚本加载&am…...
Linux C语言调用第三方库,第三方库如何编译安装
在 Linux 环境下使用 C 语言调用第三方库时,通常需要先对第三方库进行编译和安装。以下为你详细介绍一般的编译安装步骤,并给出不同类型第三方库(如使用 Makefile、CMake 构建系统)的具体示例。 一般步骤 1. 获取第三方库源码 …...
gogs私服搭建
一.介绍: gogs是一个用Go语言开发的自助Git服务,目标是简单、快速搭建Git服务, 支持多种平台,包括Linux、Windows等。它类似于GitHub,但更轻量,适合个人或小团队使用, 在简化git服务搭建流程的…...
python和c中作用域的差异
好的,我将详细列举 Python 和 C 语言在作用域规则上的主要差异,并为每种差异提供具体的代码示例,以便更清晰地理解它们之间的不同。 1. 块级作用域(Block Scope) C 语言 在 C 语言中,任何用 {} 包裹的代…...
C++ 中将函数作为参数传递
C 中将函数作为参数传递 1. 通过指针传递函数 函数可以通过传递函数的地址来作为参数传递;简而言之,就是通过指针实现这一点。 示例代码 #include <iostream> using namespace std;// 定义加法和减法函数 #include <iostream> #include …...
【C++】右值引用与完美转发
目录 一、右值引用: 1、左值与右值: 2、左值引用和右值引用: 二、右值引用的使用场景: 1、左值引用的使用场景: 2、右值引用的使用场景: 移动构造 移动赋值 三、完美转发: 1、万能引用…...
批量合并 PDF 文档,支持合并成单个文档,也支持按文件夹合并 PDF 文档
在日常工作中,合并多个 PDF 文档为一个文件是非常常见的需求。通过合并 PDF,不仅能够更方便地进行管理,还能在特定场景下(如批量打印)提高效率。那么,当我们需要批量合并多个 PDF 文件时,是否有…...
SQL Server 备份相关信息查看
目录标题 一、统计每个数据库在不同备份目录和备份类型下的备份次数,以及最后一次备份的时间整体功能详细解释 二、查询所有完整数据库备份的信息,包括备份集 ID、数据库名称、备份开始时间和备份文件的物理设备名称,并按备份开始时间降序排列…...
Flutter_学习记录_AppBar中取消leading的占位展示
将leading设置为null将automaticallyImplyLeading设置为false 看看automaticallyImplyLeading的说明: Controls whether we should try to imply the leading widget if null. If true and [AppBar.leading] is null, automatically try to deduce what the leading…...
多省发布!第27届中国机器人及人工智能大赛各赛区比赛通知
01 大赛介绍 中国机器人及人工智能大赛是由中国人工智能学会主办的极具影响力的全国性学科竞赛,旨在推动我国机器人及人工智能技术的创新与应用,促进相关专业的人才培养。作为全国高校学科竞赛A类赛事,该比赛吸引了众多高校和科研机构的积极…...
leetcode199 二叉树的右视图
小问题:if(!q.empty()) 这个条件会导致只处理一层,而不会处理所有层。正确的做法应该是用 while(!q.empty()) 循环处理每一层。 class Solution { public:vector<int> rightSideView(TreeNode* root) {vector<int> res;queue<TreeNode…...
大模型评测框架evalscope、openCompass
一、evalscope使用说明 1、如何使用智增增的接口: VLLM_USE_MODELSCOPETrue evalscope eval \--model qwen2.5-14b-instruct \--api-url https://api.zhizengzeng.com/v1/chat/completions \--api-key skxxx \--eval-type service \--datasets gsm8k \--limit 10 …...
接口自动化——初识pytest
缩写单词含义.passed通过Ffailed失败(用例执行时报错)Eerror出错(fixture执行报错)sskipped跳过Xxpassed预期外的通过(不符合预期)xxfailed预期内的失败(符合预期) 1.pytest 配置 1…...
SkyWalking实战
1、下载SkyWalking APM 1.手动下载 Downloads | Apache SkyWalkinghttps://skywalking.apache.org/downloads/ 2.链接下载 https://dlcdn.apache.org/skywalking/10.2.0/apache-skywalking-apm-10.2.0.tar.gzhttps://dlcdn.apache.org/skywalking/10.2.0/apache-skywalking-…...
游戏AI实现-GOAP
GOAP原理: GOAP(面向目标的行动规划,Goal - Oriented Action Planning) 旨在让智能体通过选择一系列行动来达成特定目标。它基于对世界状态的理解,每个行动都有前提条件和效果。智能体通过分析当前世界状态与目标状态…...
Baklib内容中台的核心优势是什么?
智能化知识管理引擎 Baklib的智能化知识管理引擎通过多源数据整合与智能分类技术,实现企业知识资产的自动化归集与动态更新。系统内置的语义分析算法可自动识别文档主题,结合自然语言处理技术生成结构化标签体系,大幅降低人工标注成本。针对…...
windows第二十章 单文档应用程序
文章目录 单文档定义新建一个单文档应用程序单文档应用程序组成:APP应用程序类框架类(窗口类)视图类(窗口类,属于框架的子窗口)文档类(对数据进行保存读取操作) 直接用向导创建单文档…...
eBay多账号安全运营技术体系:从环境隔离到智能风控的工程化实践
一、多账号运营风险模型解析 (技术化重构关联检测机制) 环境指纹维度: 浏览器指纹参数:Canvas/WebGL渲染特征(差异度要求≥98%) 设备指纹参数:GPU型号/声卡特征(识别准确率92%&…...
《Python Web网站部署应知应会》No4:基于Flask的调用AI大模型的高性能博客网站的设计思路和实战(上)
基于Flask的调用AI大模型的高性能博客网站的设计思路和实战(上) 摘要 本文详细探讨了一个基于Flask框架的高性能博客系统的设计与实现,该系统集成了本地AI大模型生成内容的功能。我们重点关注如何在高并发、高负载状态下保持系统的高性能和…...
vulnhub-Node1
一、信息收集 1、扫靶机ip arp-scan -l 2、端口扫描 淦,只有22端口和3000端口,访问一下3000端口吧,估计是个网页 nmap -p- -Pn -sC -sV -n 192.168.66.130PORT STATE SERVICE VERSION 22/tcp open ssh OpenSS…...