settings.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. from wsgiref import headers
  2. from dotenv import load_dotenv, find_dotenv
  3. from pathlib import Path # Python 3.6+ only
  4. import configparser, json, pytz
  5. import requests
  6. import pillow_avif
  7. TIME_ZONE = pytz.timezone("Asia/Shanghai")
  8. from numpy import true_divide
  9. from databases import (
  10. create_all_database,
  11. DeviceConfig,
  12. SysConfigs,
  13. CRUD,
  14. batch_insert_sys_configs,
  15. SqlQuery,
  16. batch_insert_device_configs,
  17. )
  18. # 初始化数据表
  19. create_all_database()
  20. session = SqlQuery()
  21. device_config_crud = CRUD(DeviceConfig)
  22. all_devices = device_config_crud.read_all(session)
  23. if len(all_devices) == 0:
  24. # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
  25. action_tabs = json.load(open("action_tabs.json", encoding="utf-8"))
  26. actions = json.load(open("action.json", encoding="utf-8"))
  27. batch_insert_device_configs(session, action_tabs, actions)
  28. sys_config_crud = CRUD(SysConfigs)
  29. all_sys_configs = sys_config_crud.read_all(session)
  30. if len(all_sys_configs) == 0:
  31. # 如果配置表中一条数据都没有,就将初始化数据全部插入到数据表中
  32. sys_config_json = json.load(open("sys_configs.json", encoding="utf-8"))
  33. batch_insert_sys_configs(session, sys_config_json)
  34. # 初始化数据表---结束
  35. def get_config_by_items(config_dict):
  36. __config_dict = {}
  37. for i, k in config_dict:
  38. __config_dict[i] = k
  39. return __config_dict
  40. keys = ["面料", "里料"]
  41. def getSysConfigs(key, item, default=None):
  42. session = SqlQuery()
  43. crud = CRUD(SysConfigs)
  44. one_item = crud.read(session, conditions={"key": key})
  45. config = json.loads(one_item.value)
  46. if item == "main_image_size":
  47. print(item, config.get(item, default))
  48. return config.get(item, default)
  49. def get_dict_value(_dict, key, default=None):
  50. if key in _dict:
  51. return _dict[key]
  52. else:
  53. return default
  54. MACHINE_LEVEL = (
  55. "二档"
  56. if getSysConfigs("other_configs", "device_speed", "二档") == ""
  57. else getSysConfigs("other_configs", "device_speed", "二档")
  58. )
  59. IS_TEST = False
  60. IS_MCU = True
  61. IS_LIN_SHI_TEST = False
  62. PhotographSeconds = float(
  63. 0.5
  64. if getSysConfigs("take_photo_configs", "camera_delay", "0.5") == ""
  65. else getSysConfigs("take_photo_configs", "camera_delay", "0.5")
  66. ) # 拍照停留时间
  67. def moveSpeed(level: str = None):
  68. config = {
  69. "一档": {
  70. "camera_high_motor": {
  71. "max_speed": 10000,
  72. "up_speed": 800,
  73. "down_speed": 700,
  74. },
  75. "turntable_steering": {
  76. "max_speed": 6000,
  77. "up_speed": 500,
  78. "down_speed": 400,
  79. },
  80. },
  81. "二档": {
  82. "camera_high_motor": {
  83. "max_speed": 7000,
  84. "up_speed": 600,
  85. "down_speed": 500,
  86. },
  87. "turntable_steering": {
  88. "max_speed": 4500,
  89. "up_speed": 350,
  90. "down_speed": 300,
  91. },
  92. },
  93. "三档": {
  94. "camera_high_motor": {
  95. "max_speed": 3500,
  96. "up_speed": 400,
  97. "down_speed": 300,
  98. },
  99. "turntable_steering": {
  100. "max_speed": 3000,
  101. "up_speed": 200,
  102. "down_speed": 200,
  103. },
  104. },
  105. }
  106. if level is None:
  107. return config[MACHINE_LEVEL]
  108. else:
  109. return config[level]
  110. config = configparser.ConfigParser()
  111. config_name = "config.ini"
  112. config.read(config_name, encoding="utf-8")
  113. # 应用名称
  114. APP_NAME = config.get("app", "app_name")
  115. # 应用版本号
  116. APP_VERSION = config.get("app", "version")
  117. # 是否开启调试模式
  118. IS_DEBUG = config.get("app", "debug")
  119. IS_UPLOAD_HLM = True if config.get("app", "is_upload") == "true" else False
  120. # 应用端口号
  121. PORT = config.get("app", "port")
  122. # 应用线程数
  123. APP_WORKS = config.get("app", "works")
  124. # 应用host地址
  125. APP_HOST = config.get("app", "host")
  126. # 应用服务启动名称
  127. APP_RUN = config.get("app", "app_run")
  128. # 日志名称
  129. LOG_FILE_NAME = config.get("log", "log_file_name")
  130. # 最大字节数
  131. MAX_BYTES = config.get("log", "max_bytes")
  132. print("Max bytes is", MAX_BYTES)
  133. # 备份数量
  134. BACKUP_COUNTS = config.get("log", "backup_counts")
  135. # 远程服务器地址
  136. HLM_HOST = config.get("log", "hlm_host")
  137. PROJECT = config.get("app", "project")
  138. # ----------------------------------
  139. mcu_config_dict = config.items("mcu_config")
  140. _mcu_config_dict = {}
  141. for i, k in mcu_config_dict:
  142. _mcu_config_dict[i] = int(k)
  143. # print(_mcu_config_dict)
  144. _config_mcu_config = get_config_by_items(config.items("mcu_config"))
  145. LEFT_FOOT_ACTION = _mcu_config_dict["left_foot_action"]
  146. LEFT_FOOT_PHOTOGRAPH = _mcu_config_dict["left_foot_photograph"]
  147. LEFT_FOOT_ACTION_1 = _mcu_config_dict["left_foot_action_1"]
  148. LEFT_FOOT_ACTION_2 = _mcu_config_dict["left_foot_action_2"]
  149. RIGHT_FOOT_ACTION = _mcu_config_dict["right_foot_action"]
  150. RIGHT_FOOT_PHOTOGRAPH = _mcu_config_dict["right_foot_photograph"]
  151. RIGHT_FOOT_ACTION_1 = _mcu_config_dict["right_foot_action_1"]
  152. RIGHT_FOOT_ACTION_2 = _mcu_config_dict["right_foot_action_2"]
  153. NEXT_STEP = int(get_dict_value(_config_mcu_config, "next_step", 6)) # 下一步
  154. MOVE_UP = _mcu_config_dict["move_up"]
  155. MOVE_DOWN = _mcu_config_dict["move_down"]
  156. STOP = _mcu_config_dict["stop"]
  157. DOMAIN = (
  158. "https://dev2.valimart.net"
  159. if config.get("app", "env") != "dev"
  160. else "https://dev2.pubdata.cn"
  161. )
  162. Company = "惠利玛"
  163. is_test_plugins = true_divide
  164. OUT_PIC_MODE = "." + getSysConfigs("basic_configs", "image_out_format", "png") # ".png"
  165. OUT_PIC_SIZE = (
  166. [1600]
  167. if getSysConfigs("basic_configs", "main_image_size", [1600]) == ""
  168. else getSysConfigs("basic_configs", "main_image_size", [1600])
  169. ) # 主图大小
  170. Mode = getSysConfigs("other_configs", "product_type", "鞋类") # 程序执行类
  171. OUT_PIC_FACTOR = float(
  172. 1
  173. if getSysConfigs("basic_configs", "image_sharpening", "1") == ""
  174. else getSysConfigs("basic_configs", "image_sharpening", "1")
  175. ) # 图片锐化
  176. RESIZE_IMAGE_MODE = 1
  177. GRENERATE_MAIN_PIC_BRIGHTNESS = 254 # 色阶是否调整到位判断
  178. RUNNING_MODE = getSysConfigs("other_configs", "running_mode", "普通模式")
  179. DEFAULT_CUTOUT_MODE = getSysConfigs("other_configs", "cutout_mode", "普通抠图")
  180. CUTOUT_MODE = (
  181. 0 if getSysConfigs("other_configs", "cutout_mode", "普通抠图") == "普通抠图" else 1
  182. )
  183. import importlib
  184. # plugins = [
  185. # # "custom_plugins.plugins.detail_template.huilima.detail_huilima1.DetailPicGet",
  186. # ".custom_plugins.plugins.detail_template.huilima.detail_huilima1.DetailPicGet",
  187. # # "custom_plugins.plugins.detail_template.huilima.detail_huilima2.DetailPicGet",
  188. # # "custom_plugins.plugins.detail_template.huilima.detail_huilima3.DetailPicGet",
  189. # # "custom_plugins.plugins.detail_template.huilima.detail_huilima4.DetailPicGet",
  190. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie1",
  191. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie2",
  192. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie3",
  193. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie4",
  194. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie5",
  195. # # "custom_plugins.plugins.detail_template.xiaosushuoxie.detail_xiaosushuoxie6",
  196. # # "custom_plugins.plugins.detail_template.hongqingting.detail_hongqingting1.DetailPicGet",
  197. # # "custom_plugins.plugins_mode.detail_generate_base.DetailBase",
  198. # # "custom_plugins.plugins_mode.pic_deal.PictureProcessing",
  199. # ]
  200. # def load_plugin(plugin_path):
  201. # module_name, class_name = plugin_path.rsplit(".", 1)
  202. # module = importlib.import_module(module_name)
  203. # return getattr(module, class_name)
  204. # loaded_plugins = [load_plugin(p.lstrip(".")) for p in plugins]
  205. OUT_PIC_QUALITY = "普通"
  206. GRENERATE_MAIN_PIC_BRIGHTNESS = int(
  207. getSysConfigs("other_configs", "grenerate_main_pic_brightness", 254)
  208. ) # 色阶是否调整到位判断
  209. SHADOW_PROCESSING = int(
  210. getSysConfigs("other_configs", "shadow_processing", 0)
  211. ) # 0表示要直线和曲线,1 表示只要直线
  212. LOWER_Y = int(
  213. getSysConfigs("other_configs", "lower_y", 4)
  214. ) # 鞋底以下多少距离作为阴影蒙版
  215. CHECK_LOWER_Y = int(
  216. getSysConfigs("other_configs", "check_lower_y", 4)
  217. ) # 检测亮度区域,倒数第几行
  218. IS_GET_GREEN_MASK = (
  219. True if getSysConfigs("other_configs", "is_get_green_mask", "否") == "是" else False
  220. ) # 是否进行绿幕抠图
  221. IMAGE_SAVE_MAX_WORKERS = int(
  222. getSysConfigs("other_configs", "image_save_max_workers", 4)
  223. ) # 批量保存的线程大小
  224. COLOR_GRADATION_CYCLES = int(
  225. getSysConfigs("other_configs", "color_gradation_cycles", 22)
  226. ) # 色阶处理循环次数
  227. def recordDataPoint(token=None, page="", uuid=None, data=""):
  228. """记录日志"""
  229. if token == None:
  230. return
  231. if page == "":
  232. return
  233. if uuid == None:
  234. return
  235. headers = {"Content-Type": "application/json", "authorization": "Bearer " + token}
  236. params = {
  237. "site": 1,
  238. "type": 5,
  239. "channel": "aigc-camera",
  240. "uuid": uuid,
  241. "page": page,
  242. "page_url": "/",
  243. "describe": {"action": page, "data": data},
  244. "time": 0,
  245. }
  246. return requests.post(
  247. headers=headers, data=json.dumps(params), url=DOMAIN + "/api/record/point"
  248. )