123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- """
- Cd预测集成配置文件
- @description: 管理Cd预测功能集成到AcidMap系统的相关配置
- @author: AcidMap Team
- @version: 1.0.0
- """
- import os
- from typing import Dict, Any
- class CdPredictionConfig:
- """
- Cd预测配置类
-
- @description: 管理Cd预测系统在AcidMap中的配置信息
- @example
- >>> config = CdPredictionConfig()
- >>> print(config.get_cd_system_path())
- """
-
- def __init__(self):
- """
- 初始化配置
-
- @description: 设置基本路径和配置信息
- """
- # 获取项目根目录
- self.project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-
- # Cd预测系统路径
- self.cd_system_path = os.path.join(self.project_root, "Cd_Prediction_Integrated_System")
-
- # 输出目录配置
- self.output_base_dir = os.path.join(self.project_root, "app", "static", "cd_predictions")
-
- # 子目录配置
- self.directories = {
- "figures": os.path.join(self.output_base_dir, "figures"),
- "raster": os.path.join(self.output_base_dir, "raster"),
- "reports": os.path.join(self.output_base_dir, "reports"),
- "data": os.path.join(self.output_base_dir, "data")
- }
-
- # API响应配置
- self.api_config = {
- "max_prediction_files": 10, # 最多保留的预测文件数量
- "file_cleanup_days": 7, # 文件清理天数
- "default_image_format": "jpg",
- "supported_formats": ["jpg", "png", "tiff"]
- }
-
- # 确保目录存在
- self._ensure_directories()
-
- def _ensure_directories(self):
- """
- 确保所有必要的目录存在
-
- @description: 创建输出目录结构
- """
- # 创建基础输出目录
- os.makedirs(self.output_base_dir, exist_ok=True)
-
- # 创建子目录
- for directory in self.directories.values():
- os.makedirs(directory, exist_ok=True)
-
- def get_cd_system_path(self) -> str:
- """
- 获取Cd预测系统路径
-
- @returns {str} Cd预测系统的绝对路径
- """
- return self.cd_system_path
-
- def get_output_dir(self, dir_type: str = "base") -> str:
- """
- 获取输出目录路径
-
- @param {str} dir_type - 目录类型 (base/figures/raster/reports/data)
- @returns {str} 指定类型的输出目录路径
- @throws {KeyError} 当目录类型不存在时抛出
- """
- if dir_type == "base":
- return self.output_base_dir
-
- if dir_type not in self.directories:
- raise KeyError(f"不支持的目录类型: {dir_type}")
-
- return self.directories[dir_type]
-
- def get_api_config(self) -> Dict[str, Any]:
- """
- 获取API配置信息
-
- @returns {Dict[str, Any]} API相关配置
- """
- return self.api_config.copy()
-
- def get_full_config(self) -> Dict[str, Any]:
- """
- 获取完整配置信息
-
- @returns {Dict[str, Any]} 所有配置信息
- """
- return {
- "project_root": self.project_root,
- "cd_system_path": self.cd_system_path,
- "output_base_dir": self.output_base_dir,
- "directories": self.directories.copy(),
- "api_config": self.api_config.copy()
- }
- # 全局配置实例
- cd_config = CdPredictionConfig()
|