diff --git a/Generate_Report.py b/Generate_Report.py index 561fb8d..fd42563 100644 --- a/Generate_Report.py +++ b/Generate_Report.py @@ -12,7 +12,8 @@ from tools.content_tools import ( from tools.get_pictures import ( make_Thumbnail,resize_and_reduce_quality, - get_picture_nums,find_image,collect_defect_data + get_picture_nums,find_image,collect_defect_data, + process_picture_data ) from tools.Get_Json import (get_project_info,get_jizu_info, @@ -179,7 +180,11 @@ async def generate_report(base_info, baogao_info): temperature = shigong_data['temperature'] #温度 wind_speed = shigong_data['windSpeed'] #风速 weather = get_weather(shigong_data["weatherCode"]) #天气 + #拉取图片数据 picture_data = get_picture(turbine_id) + #获取缺陷图列表和典型图列表 + defect_pictures, typical_pictures = process_picture_data(picture_data, image_source_to_find) + #处理图片数据 date_year_month = get_year_month(baogao_date) diff --git a/tools/API.py b/tools/API.py index 7e4a6f3..0a1db69 100644 --- a/tools/API.py +++ b/tools/API.py @@ -4,4 +4,4 @@ GETJIZUINFO = "/turbine/detail/{turbineId}" GETSHIGONGINFO = "/t-construction/list" GETWEATHERINFO = "/weather-type/{weatherCode}" GETPICTURELIST = "/image/list" -GETPARTLIST = "/part/list" \ No newline at end of file +GETPARTLIST = "/part/list" diff --git a/tools/Get_Json.py b/tools/Get_Json.py index 594e888..7334787 100644 --- a/tools/Get_Json.py +++ b/tools/Get_Json.py @@ -53,7 +53,7 @@ def get_part_list(turbineId : str) -> dict: -def get_picture(turbineId : str): +def get_picture(turbineId : str) -> list[dict]: """获取对应机组所有图片 Args: @@ -61,40 +61,32 @@ def get_picture(turbineId : str): Return: list: 包含所有图片信息的列表(按部件分list) [ - [ - { - "imageId": "字符串", - "imageName": "字符串", - "imagePath": "字符串", - "partId": "字符串", - "partName": "字符串", - "imageResolution": "字符串", - "focalDistance": "字符串/None", - "shootingTime": "字符串/None", - "cameraManufacturer": "字符串/None", - "cameraModel": "字符串/None", - "weather": "字符串/None", - "weatherLabel": "字符串/None", - "humidness": "数值/None", - "temperature": "字符串/None", - "windLevel": "数值/None", - "shootingMethod": "字符串/None", - "shootingMethodLabel": "字符串/None", - "shootingDistance": "数值/None", - "collectorName": "字符串/None", - "imageType": "None", - "imageTypeLabel": "None", - "audioList": "None", - "gps": "字符串/None" - }, - ... - ], - [ - { - // 相同结构的字典对象 - }, - ... - ] + { + "imageId": "图片id", + "imageName": "图片名", + "imagePath": "图片路径", + "partId": "部件id", + "partName": "部件名", + "imageResolution": "字符串", + "focalDistance": "字符串/None", + "shootingTime": "字符串/None", + "cameraManufacturer": "字符串/None", + "cameraModel": "字符串/None", + "weather": "字符串/None", + "weatherLabel": "字符串/None", + "humidness": "数值/None", + "temperature": "字符串/None", + "windLevel": "数值/None", + "shootingMethod": "字符串/None", + "shootingMethodLabel": "字符串/None", + "shootingDistance": "数值/None", + "collectorName": "字符串/None", + "imageType": "None", + "imageTypeLabel": "None", + "audioList": "None", + "gps": "字符串/None" + }, + ... ] """ picturerul = DTURL + GETPICTURELIST @@ -104,6 +96,15 @@ def get_picture(turbineId : str): params = { "partId" : part_id, } - result.append(get_data(picturerul, params = params)) + for images in get_data(picturerul, params = params): + result.append(images) + print(f"图片数据获取成功:{result}") return result + +def find_defect_record(defect_pictures : list[dict]): + """查找缺陷图片的缺陷记录 + + Args: + defect_pictures (list[dict]): 缺陷图列表 + """ \ No newline at end of file diff --git a/tools/__pycache__/Get_Json.cpython-313.pyc b/tools/__pycache__/Get_Json.cpython-313.pyc index ab1f69d..f884804 100644 Binary files a/tools/__pycache__/Get_Json.cpython-313.pyc and b/tools/__pycache__/Get_Json.cpython-313.pyc differ diff --git a/tools/__pycache__/get_pictures.cpython-313.pyc b/tools/__pycache__/get_pictures.cpython-313.pyc index 33bab75..1fe9702 100644 Binary files a/tools/__pycache__/get_pictures.cpython-313.pyc and b/tools/__pycache__/get_pictures.cpython-313.pyc differ diff --git a/tools/get_pictures.py b/tools/get_pictures.py index 897d05d..d77594b 100644 --- a/tools/get_pictures.py +++ b/tools/get_pictures.py @@ -231,4 +231,27 @@ def create_thumbnail(file_path: str, size: tuple) -> Image: return new_img except Exception as e: print(f"图片处理有问题:{e}") - return None \ No newline at end of file + return None + +def process_picture_data(picture_data : list[dict], + image_source_to_find : list[str], + quexian_type : str, + dianxing_type : str) -> tuple[list[str], list[str]]: + """处理从数据库获取的图片数据 + + Args: + picture_data (list[dict]): 图片数据 + image_source_to_find (list[str]): 要查找的图片来源枚举(外内防雷) + quexian_type (str): 缺陷类型枚举值 + dianxing_type (str): 典型类型枚举值 + Returns: + tuple( + defct_pictures, 缺陷图列表 + dianxing_pictures 典型图列表 + ) + """ + #过滤目标来源的图片数据 + picture_data = [pic for pic in picture_data if pic['imageSource'] in image_source_to_find] + #分别择出缺陷图和典型图 + return [pic for pic in picture_data if pic['imageType'] == quexian_type], [pic for pic in picture_data if pic['imageType'] == dianxing_type] + \ No newline at end of file