This repository has been archived on 2025-02-25. You can view files and clone it, but cannot push or open issues or pull requests.
gitea 3814d163c5 v0.2.0.6(2024/08/09)
1. [t_change_ui: all files]
   - 修改了 logger 的实现
   - 尤其是 clibs.py,使用日志字典,重写了日志记录的功能
2024-08-09 10:47:22 +08:00

182 lines
8.5 KiB
Python

import pdfplumber
from openpyxl import load_workbook
from os import remove
from sys import argv
from commons import clibs
logger = clibs.log_prod
def p_iso(file, p_files, ws, tmpfile):
p_files.append(file)
pdf = pdfplumber.open(file)
with open(tmpfile, mode='w', encoding='utf-8') as fb:
for page in pdf.pages:
fb.write(page.extract_text())
with open(tmpfile, mode='r', encoding='utf-8') as fb:
lines = fb.readlines()
lines = [line for line in lines if not line.startswith('Page ')]
for line in lines:
if line.strip() == "Pose Accuracy and Repeatability":
index = lines.index(line)
ws.cell(row=3, column=7).value = float(lines[index+4].split()[1])
ws.cell(row=4, column=7).value = float(lines[index+5].split()[1])
ws.cell(row=5, column=7).value = float(lines[index+6].split()[1])
ws.cell(row=6, column=7).value = float(lines[index+7].split()[1])
ws.cell(row=7, column=7).value = float(lines[index+8].split()[1])
ws.cell(row=8, column=7).value = float(lines[index+4].split()[2])
ws.cell(row=9, column=7).value = float(lines[index+5].split()[2])
ws.cell(row=10, column=7).value = float(lines[index+6].split()[2])
ws.cell(row=11, column=7).value = float(lines[index+7].split()[2])
ws.cell(row=12, column=7).value = float(lines[index+8].split()[2])
elif line.strip() == 'Pose Accuracy Variation':
index = lines.index(line)
ws.cell(row=13, column=7).value = float(lines[index+4].split()[1])
ws.cell(row=14, column=7).value = float(lines[index+5].split()[1])
ws.cell(row=15, column=7).value = float(lines[index+6].split()[1])
elif line.strip() == 'Distance Accuracy':
index = lines.index(line)
ws.cell(row=16, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=17, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Stabilisation Time and Overshoot':
index = lines.index(line)
ws.cell(row=18, column=7).value = float(lines[index + 7].split()[3])
ws.cell(row=19, column=7).value = float(lines[index + 7].split()[2])
elif line.strip() == 'Velocity Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=20, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=21, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=22, column=7).value = float(lines[index + 4].split()[3])
elif line.strip()[:31] == 'Path Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=29, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=30, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Corner Overshoot and Roundoff':
index = lines.index(line)
ws.cell(row=35, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=36, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Robot Weaving':
index = lines.index(line)
ws.cell(row=41, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=42, column=7).value = float(lines[index + 4].split()[3])
ws.cell(row=43, column=7).value = float(lines[index + 4].split()[4])
else:
pass
def p_iso_100(file, p_files, ws, tmpfile):
p_files.append(file)
pdf = pdfplumber.open(file)
with open(tmpfile, mode='w', encoding='utf-8') as fb:
for page in pdf.pages:
fb.write(page.extract_text())
with open(tmpfile, mode='r', encoding='utf-8') as fb:
lines = fb.readlines()
lines = [line for line in lines if not line.startswith('Page ')]
for line in lines:
if line.strip() == 'Velocity Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=26, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=27, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=28, column=7).value = float(lines[index + 4].split()[3])
elif line.strip()[:31] == 'Path Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=33, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=34, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Corner Overshoot and Roundoff':
index = lines.index(line)
ws.cell(row=39, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=40, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Robot Weaving':
index = lines.index(line)
ws.cell(row=47, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=48, column=7).value = float(lines[index + 4].split()[3])
ws.cell(row=49, column=7).value = float(lines[index + 4].split()[4])
else:
pass
def p_iso_1000(file, p_files, ws, tmpfile):
p_files.append(file)
pdf = pdfplumber.open(file)
with open(tmpfile, mode='w', encoding='utf-8') as fb:
for page in pdf.pages:
fb.write(page.extract_text())
with open(tmpfile, mode='r', encoding='utf-8') as fb:
lines = fb.readlines()
lines = [line for line in lines if not line.startswith('Page ')]
for line in lines:
if line.strip() == 'Velocity Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=23, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=24, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=25, column=7).value = float(lines[index + 4].split()[3])
elif line.strip()[:31] == 'Path Accuracy and Repeatability':
index = lines.index(line)
ws.cell(row=31, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=32, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Corner Overshoot and Roundoff':
index = lines.index(line)
ws.cell(row=37, column=7).value = float(lines[index + 4].split()[1])
ws.cell(row=38, column=7).value = float(lines[index + 4].split()[2])
elif line.strip() == 'Robot Weaving':
index = lines.index(line)
ws.cell(row=44, column=7).value = float(lines[index + 4].split()[2])
ws.cell(row=45, column=7).value = float(lines[index + 4].split()[3])
ws.cell(row=46, column=7).value = float(lines[index + 4].split()[4])
else:
pass
def main(path, w2t):
dirs, files = clibs.traversal_files(path, 1)
try:
wb = load_workbook(path + "/iso-results.xlsx")
ws = wb.active
for i in range(3, 50):
ws.cell(row=i, column=7).value = None
tmpfile = f"{path}\\data.txt"
except Exception as Err:
w2t(f"发生错误:{Err}", 0, 2, 'red')
p_files = []
for file in files:
if file.endswith('.pdf') and file.split('\\')[-1] == 'ISO.pdf':
w2t(f"正在处理{file}......")
p_iso(file, p_files, ws, tmpfile)
w2t(f"文件{file}已处理完毕。\n")
elif file.endswith('.pdf') and file.split('\\')[-1] == 'ISO-V100.pdf':
w2t(f"正在处理{file}......")
p_iso_100(file, p_files, ws, tmpfile)
w2t(f"文件{file}已处理完毕。\n")
elif file.endswith('.pdf') and file.split('\\')[-1] == 'ISO-V1000.pdf':
w2t(f"正在处理{file}......")
p_iso_1000(file, p_files, ws, tmpfile)
w2t(f"文件{file}已处理完毕。\n")
else:
pass
wb.save(path + '/iso-results.xlsx')
wb.close()
if len(p_files) == 0:
w2t(f"目录 {path} 下没有需要处理的文件,需要确认......", 0, 3, 'red')
else:
remove(tmpfile)
w2t("------------------------------------------")
w2t("所有文件均已处理完毕!")
if __name__ == '__main__':
main(path=argv[1], w2t=argv[2])