config.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """Module core/configs provide project base settings"""
  2. import glob
  3. import json
  4. import logging
  5. import os
  6. import os.path
  7. class Settings:
  8. PROJECT_NAME: str = 'Kraken'
  9. DEVICE = 'neo'
  10. CONFIG_INFO = {
  11. 'host': '127.0.0.1',
  12. 'port': 8712,
  13. 'channel_count': 9,
  14. 'sample_rate': 1000,
  15. 'delay_milliseconds': 40,
  16. 'buffer_plot_size_seconds': 0.04,
  17. 'channel_labels': [
  18. 'C3',
  19. 'FC3',
  20. 'CP5',
  21. 'CP1',
  22. 'C4',
  23. 'FC4',
  24. 'CP2',
  25. 'CP6',
  26. 'FP1'
  27. ]
  28. }
  29. PROJECT_VERSION: str = '0.0.1'
  30. DATA_PATH = './db/data'
  31. TRAIN_PARAMS = {
  32. 'instruct_duration': 2 * 1000,
  33. 'rest_stim_duration': 60 * 1000,
  34. 'prepare_duration': 1.5 * 1000,
  35. 'mi_duration': 5 * 1000,
  36. 'rest_duration': 5 * 1000,
  37. 'sample_duration': 3 * 1000 # 训练样本长度
  38. } # milliseconds
  39. def __init__(self):
  40. self.config = {"lang": "zh"}
  41. def get_message(self):
  42. self.message = {}
  43. msg_list = glob.glob('./static/config/message*.json')
  44. for msg in msg_list:
  45. filename = os.path.basename(msg)
  46. msg_code, ext = os.path.splitext(filename)
  47. with open(msg, 'r', encoding='utf8') as file:
  48. self.message[msg_code.split('_')[1]] = json.load(file)
  49. return self.message
  50. settings = Settings()
  51. def setup_logging(default_path='logging.json',
  52. default_level=logging.INFO,
  53. env_key='LOG_CFG'):
  54. """Setup logging configuration
  55. """
  56. path = default_path
  57. value = os.getenv(env_key, None)
  58. if value:
  59. path = value
  60. if os.path.exists(path):
  61. with open(path, 'rt', encoding='utf-8') as f:
  62. config = json.load(f)
  63. logging.config.dictConfig(config)
  64. else:
  65. logging.basicConfig(level=default_level)
  66. def set_deepface_env():
  67. # os.environ['DEEPFACE_HOME'] = Path(__file__).resolve().parent.as_posix()
  68. os.environ['DEEPFACE_HOME'] = settings.get_resource_dir(['']).as_posix()