cd_prediction_config.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """
  2. Cd预测集成配置文件
  3. @description: 管理Cd预测功能集成到AcidMap系统的相关配置
  4. @author: AcidMap Team
  5. @version: 1.0.0
  6. """
  7. import os
  8. from typing import Dict, Any
  9. class CdPredictionConfig:
  10. """
  11. Cd预测配置类
  12. @description: 管理Cd预测系统在AcidMap中的配置信息
  13. @example
  14. >>> config = CdPredictionConfig()
  15. >>> print(config.get_cd_system_path())
  16. """
  17. def __init__(self):
  18. """
  19. 初始化配置
  20. @description: 设置基本路径和配置信息
  21. """
  22. # 获取项目根目录
  23. self.project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  24. # Cd预测系统路径
  25. self.cd_system_path = os.path.join(self.project_root, "Cd_Prediction_Integrated_System")
  26. # 输出目录配置
  27. self.output_base_dir = os.path.join(self.project_root, "app", "static", "cd_predictions")
  28. # 子目录配置
  29. self.directories = {
  30. "figures": os.path.join(self.output_base_dir, "figures"),
  31. "raster": os.path.join(self.output_base_dir, "raster"),
  32. "reports": os.path.join(self.output_base_dir, "reports"),
  33. "data": os.path.join(self.output_base_dir, "data")
  34. }
  35. # API响应配置
  36. self.api_config = {
  37. "max_prediction_files": 10, # 最多保留的预测文件数量
  38. "file_cleanup_days": 7, # 文件清理天数
  39. "default_image_format": "jpg",
  40. "supported_formats": ["jpg", "png", "tiff"]
  41. }
  42. # 确保目录存在
  43. self._ensure_directories()
  44. def _ensure_directories(self):
  45. """
  46. 确保所有必要的目录存在
  47. @description: 创建输出目录结构
  48. """
  49. # 创建基础输出目录
  50. os.makedirs(self.output_base_dir, exist_ok=True)
  51. # 创建子目录
  52. for directory in self.directories.values():
  53. os.makedirs(directory, exist_ok=True)
  54. def get_cd_system_path(self) -> str:
  55. """
  56. 获取Cd预测系统路径
  57. @returns {str} Cd预测系统的绝对路径
  58. """
  59. return self.cd_system_path
  60. def get_output_dir(self, dir_type: str = "base") -> str:
  61. """
  62. 获取输出目录路径
  63. @param {str} dir_type - 目录类型 (base/figures/raster/reports/data)
  64. @returns {str} 指定类型的输出目录路径
  65. @throws {KeyError} 当目录类型不存在时抛出
  66. """
  67. if dir_type == "base":
  68. return self.output_base_dir
  69. if dir_type not in self.directories:
  70. raise KeyError(f"不支持的目录类型: {dir_type}")
  71. return self.directories[dir_type]
  72. def get_api_config(self) -> Dict[str, Any]:
  73. """
  74. 获取API配置信息
  75. @returns {Dict[str, Any]} API相关配置
  76. """
  77. return self.api_config.copy()
  78. def get_full_config(self) -> Dict[str, Any]:
  79. """
  80. 获取完整配置信息
  81. @returns {Dict[str, Any]} 所有配置信息
  82. """
  83. return {
  84. "project_root": self.project_root,
  85. "cd_system_path": self.cd_system_path,
  86. "output_base_dir": self.output_base_dir,
  87. "directories": self.directories.copy(),
  88. "api_config": self.api_config.copy()
  89. }
  90. # 全局配置实例
  91. cd_config = CdPredictionConfig()