config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. 'channel_labels': [
  16. 'CH001',
  17. 'CH002',
  18. 'CH003',
  19. 'CH004',
  20. 'CH005',
  21. 'CH006',
  22. 'CH007',
  23. 'CH008',
  24. 'STIM'
  25. ],
  26. 'strips': [['CH001', 'CH002', 'CH003', 'CH004'],
  27. ['CH005', 'CH006', 'CH007', 'CH008']],
  28. }
  29. FINGERMODEL_IDS = {
  30. 'rest': 0,
  31. 'cylinder': 1,
  32. 'ball': 2,
  33. 'flex': 3,
  34. 'double': 4,
  35. 'treble': 5
  36. }
  37. FINGERMODEL_IDS_INVERSE = {
  38. 0: 'rest',
  39. 1: 'cylinder',
  40. 2: 'ball',
  41. 3: 'flex',
  42. 4: 'double',
  43. 5: 'treble'
  44. }
  45. PROJECT_VERSION: str = '0.0.1'
  46. DATA_PATH = './data'
  47. def __init__(self):
  48. self.config = {"lang": "zh"}
  49. def get_message(self):
  50. self.message = {}
  51. msg_list = glob.glob('./static/config/message*.json')
  52. for msg in msg_list:
  53. filename = os.path.basename(msg)
  54. msg_code, ext = os.path.splitext(filename)
  55. with open(msg, 'r', encoding='utf8') as file:
  56. self.message[msg_code.split('_')[1]] = json.load(file)
  57. return self.message
  58. settings = Settings()
  59. def setup_logging(default_path='logging.json',
  60. default_level=logging.INFO,
  61. env_key='LOG_CFG'):
  62. """Setup logging configuration
  63. """
  64. path = default_path
  65. value = os.getenv(env_key, None)
  66. if value:
  67. path = value
  68. if os.path.exists(path):
  69. with open(path, 'rt', encoding='utf-8') as f:
  70. config = json.load(f)
  71. logging.config.dictConfig(config)
  72. else:
  73. logging.basicConfig(level=default_level)
  74. def set_deepface_env():
  75. # os.environ['DEEPFACE_HOME'] = Path(__file__).resolve().parent.as_posix()
  76. os.environ['DEEPFACE_HOME'] = settings.get_resource_dir(['']).as_posix()