|
@@ -9,6 +9,7 @@ import os
|
|
import sys
|
|
import sys
|
|
import logging
|
|
import logging
|
|
import subprocess
|
|
import subprocess
|
|
|
|
+import time
|
|
from typing import Dict, Any, Optional
|
|
from typing import Dict, Any, Optional
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
|
|
|
|
@@ -203,11 +204,12 @@ class CdPredictionWrapper:
|
|
|
|
|
|
return output_files
|
|
return output_files
|
|
|
|
|
|
- def get_latest_outputs(self, output_type: str = "all") -> Dict[str, Optional[str]]:
|
|
|
|
|
|
+ def get_latest_outputs(self, output_type: str = "all", model_type: str = None) -> Dict[str, Optional[str]]:
|
|
"""
|
|
"""
|
|
获取最新的输出文件
|
|
获取最新的输出文件
|
|
|
|
|
|
@param {str} output_type - 输出类型 ("maps", "histograms", "rasters", "all")
|
|
@param {str} output_type - 输出类型 ("maps", "histograms", "rasters", "all")
|
|
|
|
+ @param {str} model_type - 模型类型 ("crop", "effective", None为获取所有)
|
|
@returns {Dict[str, Optional[str]]} 最新输出文件路径
|
|
@returns {Dict[str, Optional[str]]} 最新输出文件路径
|
|
"""
|
|
"""
|
|
try:
|
|
try:
|
|
@@ -223,7 +225,8 @@ class CdPredictionWrapper:
|
|
if os.path.exists(figures_dir):
|
|
if os.path.exists(figures_dir):
|
|
for file in os.listdir(figures_dir):
|
|
for file in os.listdir(figures_dir):
|
|
if "Prediction" in file and "results" in file and file.endswith(('.jpg', '.png')):
|
|
if "Prediction" in file and "results" in file and file.endswith(('.jpg', '.png')):
|
|
- map_files.append(os.path.join(figures_dir, file))
|
|
|
|
|
|
+ file_path = os.path.join(figures_dir, file)
|
|
|
|
+ map_files.append(file_path)
|
|
|
|
|
|
latest_files["latest_map"] = max(map_files, key=os.path.getctime) if map_files else None
|
|
latest_files["latest_map"] = max(map_files, key=os.path.getctime) if map_files else None
|
|
|
|
|
|
@@ -233,7 +236,8 @@ class CdPredictionWrapper:
|
|
if os.path.exists(figures_dir):
|
|
if os.path.exists(figures_dir):
|
|
for file in os.listdir(figures_dir):
|
|
for file in os.listdir(figures_dir):
|
|
if ("frequency" in file.lower() or "histogram" in file.lower()) and file.endswith(('.jpg', '.png')):
|
|
if ("frequency" in file.lower() or "histogram" in file.lower()) and file.endswith(('.jpg', '.png')):
|
|
- histogram_files.append(os.path.join(figures_dir, file))
|
|
|
|
|
|
+ file_path = os.path.join(figures_dir, file)
|
|
|
|
+ histogram_files.append(file_path)
|
|
|
|
|
|
latest_files["latest_histogram"] = max(histogram_files, key=os.path.getctime) if histogram_files else None
|
|
latest_files["latest_histogram"] = max(histogram_files, key=os.path.getctime) if histogram_files else None
|
|
|
|
|
|
@@ -243,12 +247,22 @@ class CdPredictionWrapper:
|
|
if os.path.exists(raster_dir):
|
|
if os.path.exists(raster_dir):
|
|
for file in os.listdir(raster_dir):
|
|
for file in os.listdir(raster_dir):
|
|
if file.startswith('output') and file.endswith('.tif'):
|
|
if file.startswith('output') and file.endswith('.tif'):
|
|
- raster_files.append(os.path.join(raster_dir, file))
|
|
|
|
|
|
+ file_path = os.path.join(raster_dir, file)
|
|
|
|
+ raster_files.append(file_path)
|
|
|
|
|
|
latest_files["latest_raster"] = max(raster_files, key=os.path.getctime) if raster_files else None
|
|
latest_files["latest_raster"] = max(raster_files, key=os.path.getctime) if raster_files else None
|
|
|
|
|
|
|
|
+ # 添加调试信息
|
|
|
|
+ self.logger.info(f"获取最新输出文件 - 模型类型: {model_type}, 输出类型: {output_type}")
|
|
|
|
+ for key, value in latest_files.items():
|
|
|
|
+ if value:
|
|
|
|
+ self.logger.info(f" {key}: {os.path.basename(value)}")
|
|
|
|
+ else:
|
|
|
|
+ self.logger.warning(f" {key}: 未找到文件")
|
|
|
|
+
|
|
return latest_files
|
|
return latest_files
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
self.logger.error(f"获取最新输出文件失败: {str(e)}")
|
|
self.logger.error(f"获取最新输出文件失败: {str(e)}")
|
|
- return {}
|
|
|
|
|
|
+ return {}
|
|
|
|
+
|