config.py 2.2 KB

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