config.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from pathlib import Path
  2. from typing import Dict, List
  3. from enum import Enum
  4. import json
  5. class Settings:
  6. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  7. CONFIG_PATH = BASE_PATH / 'Config.json'
  8. API_ImageData_prefix: str = "/api/image_data"
  9. DATA_DIR = BASE_PATH / "Data"
  10. SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
  11. # --- 数据库配置 ---
  12. DB_NAME = 'card_score_database'
  13. DB_TABLE_NAME = 'image_records'
  14. DATABASE_CONFIG: Dict[str, str] = {
  15. 'user': 'root',
  16. 'password': '123456',
  17. 'host': '127.0.0.1',
  18. }
  19. # 连接到指定数据库的配置
  20. DATABASE_CONFIG_WITH_DB: Dict[str, str] = {
  21. **DATABASE_CONFIG,
  22. 'database': DB_NAME
  23. }
  24. def set_config(self):
  25. with open(self.CONFIG_PATH, 'r') as f:
  26. config_json = json.load(f)
  27. self.DATABASE_CONFIG = config_json["mysql_config"]
  28. self.DB_NAME = config_json["database_name"]
  29. self.DB_TABLE_NAME = config_json["database_table_name"]
  30. settings = Settings()
  31. print(f"项目根目录: {settings.BASE_PATH}")
  32. print(f"数据存储目录: {settings.DATA_DIR}")
  33. # DefectType = Enum("InferenceType", {name: name for name in settings.DEFECT_TYPE})
  34. # print()