settings.py 9.4 KB

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