settings.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. from dotenv import load_dotenv, find_dotenv
  2. from pathlib import Path # Python 3.6+ only
  3. import configparser, json
  4. from numpy import true_divide
  5. from databases import (
  6. create_all_database,
  7. DeviceConfig,
  8. SysConfigs,
  9. CRUD,
  10. batch_insert_sys_configs,
  11. SqlQuery,
  12. batch_insert_device_configs,
  13. )
  14. # 初始化数据表
  15. create_all_database()
  16. session = SqlQuery()
  17. device_config_crud = CRUD(DeviceConfig)
  18. all_devices = device_config_crud.read_all(session)
  19. if len(all_devices) == 0:
  20. # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
  21. actions = json.load(open("action.json", encoding="utf-8"))
  22. batch_insert_device_configs(session, actions)
  23. sys_config_crud = CRUD(SysConfigs)
  24. all_sys_configs = sys_config_crud.read_all(session)
  25. if len(all_sys_configs) == 0:
  26. # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
  27. sys_config_json = json.load(open("sys_configs.json", encoding="utf-8"))
  28. batch_insert_sys_configs(session, sys_config_json)
  29. # 初始化数据表---结束
  30. def get_config_by_items(config_dict):
  31. __config_dict = {}
  32. for i, k in config_dict:
  33. __config_dict[i] = k
  34. return __config_dict
  35. def getSysConfigs(key,item,default=None):
  36. session = SqlQuery()
  37. crud = CRUD(SysConfigs)
  38. one_item = crud.read(session, conditions={"key": key})
  39. config = json.loads(one_item.value)
  40. return config.get(item, default)
  41. def get_dict_value(_dict, key, default=None):
  42. if key in _dict:
  43. return _dict[key]
  44. else:
  45. return default
  46. MACHINE_LEVEL = getSysConfigs("other_configs", "device_speed", "二档")
  47. IS_TEST = False
  48. IS_MCU = True
  49. IS_LIN_SHI_TEST = False
  50. PhotographSeconds = float(
  51. getSysConfigs("take_photo_configs", "camera_delay", "0.5")
  52. ) # 拍照停留时间
  53. def moveSpeed(level: str = None):
  54. config = {
  55. "一档": {
  56. "camera_high_motor": {
  57. "max_speed": 10000,
  58. "up_speed": 800,
  59. "down_speed": 700,
  60. },
  61. "turntable_steering": {
  62. "max_speed": 6000,
  63. "up_speed": 500,
  64. "down_speed": 400,
  65. },
  66. },
  67. "二档": {
  68. "camera_high_motor": {
  69. "max_speed": 7000,
  70. "up_speed": 600,
  71. "down_speed": 500,
  72. },
  73. "turntable_steering": {
  74. "max_speed": 4500,
  75. "up_speed": 350,
  76. "down_speed": 300,
  77. },
  78. },
  79. "三档": {
  80. "camera_high_motor": {
  81. "max_speed": 3500,
  82. "up_speed": 400,
  83. "down_speed": 300,
  84. },
  85. "turntable_steering": {
  86. "max_speed": 3000,
  87. "up_speed": 200,
  88. "down_speed": 200,
  89. },
  90. },
  91. }
  92. if level is None:
  93. return config[MACHINE_LEVEL]
  94. else:
  95. return config[level]
  96. config = configparser.ConfigParser()
  97. config_name = "config.ini"
  98. config.read(config_name, encoding="utf-8")
  99. # 应用名称
  100. APP_NAME = config.get("app", "app_name")
  101. # 应用版本号
  102. APP_VERSION = config.get("app", "version")
  103. # 是否开启调试模式
  104. IS_DEBUG = config.get("app", "debug")
  105. # 应用端口号
  106. PORT = config.get("app", "port")
  107. # 应用线程数
  108. APP_WORKS = config.get("app", "works")
  109. # 应用host地址
  110. APP_HOST = config.get("app", "host")
  111. # 应用服务启动名称
  112. APP_RUN = config.get("app", "app_run")
  113. # 日志名称
  114. LOG_FILE_NAME = config.get("log", "log_file_name")
  115. # 最大字节数
  116. MAX_BYTES = config.get("log", "max_bytes")
  117. print("Max bytes is", MAX_BYTES)
  118. # 备份数量
  119. BACKUP_COUNTS = config.get("log", "backup_counts")
  120. # 远程服务器地址
  121. HLM_HOST = config.get("log", "hlm_host")
  122. PROJECT = config.get("app", "project")
  123. # ----------------------------------
  124. mcu_config_dict = config.items("mcu_config")
  125. _mcu_config_dict = {}
  126. for i, k in mcu_config_dict:
  127. _mcu_config_dict[i] = int(k)
  128. # print(_mcu_config_dict)
  129. _config_mcu_config = get_config_by_items(config.items("mcu_config"))
  130. LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"]
  131. LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"]
  132. LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"]
  133. LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"]
  134. RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"]
  135. RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"]
  136. RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"]
  137. RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"]
  138. NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步
  139. MOVE_UP = _mcu_config_dict["move_up"]
  140. MOVE_DOWN = _mcu_config_dict["move_down"]
  141. STOP = _mcu_config_dict["stop"]
  142. DOMAIN = (
  143. "https://dev2.valimart.net"
  144. if config.get("app", "debug") == "false"
  145. else "https://dev2.pubdata.cn"
  146. )
  147. Company = "惠利玛"
  148. is_test_plugins = true_divide
  149. OUT_PIC_MODE = "."+getSysConfigs("basic_configs", "image_out_format", "png") # ".png"
  150. OUT_PIC_SIZE = int(getSysConfigs("basic_configs", "main_image_size", "800")) # 主图大小
  151. Mode = getSysConfigs("other_configs", "product_type", "鞋类") # 程序执行类
  152. OUT_PIC_FACTOR = float(
  153. getSysConfigs("basic_configs", "image_sharpening", "1")
  154. ) # 图片锐化
  155. RESIZE_IMAGE_MODE = 1
  156. GRENERATE_MAIN_PIC_BRIGHTNESS = 254 # 色阶是否调整到位判断
  157. RUNNING_MODE = getSysConfigs("other_configs", "running_mode", "普通模式")
  158. DEFAULT_CUTOUT_MODE = getSysConfigs("other_configs", "cutout_mode", "普通抠图")
  159. CUTOUT_MODE = 0 if getSysConfigs("other_configs", "cutout_mode", "普通抠图") =="普通抠图" else 1