settings.py 10 KB

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