Commit 45596338 authored by wux51's avatar wux51

update

parents 1bb844f0 f84612eb
# waae-algorithm-tools
waae工具
\ No newline at end of file
...@@ -5,6 +5,7 @@ import os.path as osp ...@@ -5,6 +5,7 @@ import os.path as osp
import shutil import shutil
from datetime import date from datetime import date
from collections import defaultdict as dd from collections import defaultdict as dd
from moviepy import ImageSequenceClip
import pandas as pd import pandas as pd
...@@ -43,12 +44,14 @@ def process_data(data, entry): ...@@ -43,12 +44,14 @@ def process_data(data, entry):
def process_page(data, page_id): def process_page(data, page_id):
# 根据page_id,确定页面截图和主page的路径 # 根据page_id,确定页面截图和主page的路径
page = data[int(page_id)] page = data[int(page_id)]
screenshot_path = []
screenshot_path = [os.path.basename(box["local_image_path_full"]) for box in page["focus_boxes"]]
image_path = page['img_path'] image_path = page['img_path']
return screenshot_path, image_path return screenshot_path, image_path
def process(file_list, data, entry, img_save_path, save_path): def process(file_list, data, entry, video_save_path, save_path):
result_finial = {} result_finial = {}
cnt = 0 cnt = 0
...@@ -60,6 +63,8 @@ def process(file_list, data, entry, img_save_path, save_path): ...@@ -60,6 +63,8 @@ def process(file_list, data, entry, img_save_path, save_path):
try: try:
errors = report['check_result']['errors'] errors = report['check_result']['errors']
pages = report['check_result']['pages'] pages = report['check_result']['pages']
app_name = report['appName']
task_id = report['hcTaskId']
except: except:
continue continue
for k in errors: for k in errors:
...@@ -78,10 +83,18 @@ def process(file_list, data, entry, img_save_path, save_path): ...@@ -78,10 +83,18 @@ def process(file_list, data, entry, img_save_path, save_path):
for page_id in result: for page_id in result:
id = f'{save_path}_{cnt}' id = f'{save_path}_{cnt}'
video_path = osp.join('todo', f'{id}.mp4') video_path = osp.join(video_save_path, f'{app_name}-{task_id}-{page_id}.mp4')
screenshot_path, image_path = process_page(pages, page_id) screenshot_path, image_path = process_page(pages, page_id)
image_path = osp.join(file, 'screenshots', image_path.split('/')[-1]) image_path = osp.join(file, 'screenshots', image_path.split('/')[-1])
img_path = osp.join(img_save_path, f'{id}.png')
img_path = osp.join(save_path, f'{id}.png')
# 当前页面的所有截图
screenshot_path = [osp.join(file, 'screenshots',item) for item in screenshot_path]
# 合成视频
images_to_video(screenshot_path,video_path,fps=1)
result_finial[id] = {'页面名': f'{id}', '合成视频路径': video_path, result_finial[id] = {'页面名': f'{id}', '合成视频路径': video_path,
'页面截图路径': image_path, '页面截图路径': image_path,
'所有截图路径': screenshot_path} '所有截图路径': screenshot_path}
...@@ -103,18 +116,23 @@ def load_file_path(path): ...@@ -103,18 +116,23 @@ def load_file_path(path):
return file_list return file_list
def images_to_video(image_files, output_video_path, fps=1):
clip = ImageSequenceClip(image_files, fps=fps)
clip.write_videofile(output_video_path)
print(f"视频已成功保存至:{output_video_path}")
def run(path='/AIAssd/aia/waae/tasks'): def run(tast_dir='task_dir',map_dict_path='app_video_map.txt'):
save_path = str(date.today()).replace('-', '_') save_path = str(date.today()).replace('-', '_')
video_save_path = osp.join(save_path, 'videos') video_save_path = osp.join(save_path, 'videos')
report_save_path = osp.join(save_path, 'app_video_report.json') report_save_path = osp.join(save_path, 'app_video_report.json')
report_save_path_excel = osp.join(save_path, 'app_video_report.xlsx') report_save_path_excel = osp.join(save_path, 'app_video_report.xlsx')
os.makedirs(video_save_path, exist_ok=True) os.makedirs(video_save_path, exist_ok=True)
file_list = load_file_path(path) file_list = load_file_path(tast_dir)
print(len(file_list))
with open('app_video_map.txt', 'r') as f: with open(map_dict_path, 'r') as f:
data1 = f.readlines() data1 = f.readlines()
data = dd(list) data = dd(list)
keys = dd() keys = dd()
...@@ -139,4 +157,5 @@ def run(path='/AIAssd/aia/waae/tasks'): ...@@ -139,4 +157,5 @@ def run(path='/AIAssd/aia/waae/tasks'):
create_excel_with_columns(result_finial, report_save_path_excel) create_excel_with_columns(result_finial, report_save_path_excel)
if __name__ == '__main__': if __name__ == '__main__':
# TODO: 使用时,传入waae数据根目录(task_dir)和检测的条目(app_video_map.txt)
run() run()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment