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