Browse Source

优化

master
dongchangxi 2 years ago
parent
commit
46dacc2f7c
  1. 9
      libs/common.py
  2. 8
      logic/logic_main_service.py
  3. 10
      main_step1.py
  4. 30
      main_step2.py
  5. 2
      main_step3.py
  6. 12
      timer/get_task_to_db.py
  7. 2
      tools/cal_weight.py

9
libs/common.py

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import redis,sys,os,re,oss2
import platform
import xml.etree.ElementTree as ET
from PIL import ImageGrab
if platform.system() == 'Windows':
#sys.path.append('e:\\libs\\')
sys.path.append('libs')
@ -218,3 +219,11 @@ def uploadControlPointsOss(pid): @@ -218,3 +219,11 @@ def uploadControlPointsOss(pid):
localfile = os.path.join(config.workdir,str(pid), f'{str(pid)}_wait/controlpoints0.dat')
#进行上传
config.oss_bucket.put_object_from_file(filePath, localfile)
#截屏保存
def saveScreenImg(pid):
#获取当前的日志
if not os.path.exists(os.path.join("D:/screen/",time.strftime("%y-%m-%d", time.localtime()))):
os.makedirs(os.path.join("D:/screen/",time.strftime("%Y-%m-%d", time.localtime())))
screenshot = ImageGrab .grab()
screenshot.save(os.path.join("D:/screen/",time.strftime("%Y-%-%d'time .localtime()"),str(pid)+".png"))

8
logic/logic_main_service.py

@ -117,6 +117,14 @@ def need_run_stepx(task_distributed_id): @@ -117,6 +117,14 @@ def need_run_stepx(task_distributed_id):
#查询改任务的最后一个状态
if result and result["finished_at"]:
if result["step"] == "step1":
#如果是要执行 step2 ,并且当前主机是R11 R12 ,则要判断step1是否是当前的主机执行的
if hostname == "R11" or hostname == "R12":
if hostname != result["hostname"]:
return "no"
else:
return "step2"
else:
return "step2"
elif result["step"] == "step2":
return "step3"

10
main_step1.py

@ -58,9 +58,15 @@ def detect_markers(psid, pid): @@ -58,9 +58,15 @@ def detect_markers(psid, pid):
start_time = time.time()
add_photo3 = ' '
textpicCmd = ' '
if os.path.exists(os.path.join(config.workdir, pid, 'photo3')):
add_photo3 = ' -addFolder "' + os.path.join(config.workdir, pid, 'photo3') + '" '
textpicCmd ='-selectImage "'+os.path.join(config.workdir,pid,'photo3')+'\*" -enableTexturingAndColoring true'
textpicCmd ='-selectImage "'+os.path.join(config.workdir,pid,'photo2')+'\*" -enableTexturingAndColoring false'
else:
textpicCmd ='-selectImage "'+os.path.join(config.workdir,pid,'photo2')+'\*" -enableTexturingAndColoring true'
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \
-addFolder "{os.path.join(config.workdir, pid, "photo1")}" {config.r["setTextureFalse"]} -align -addFolder "{os.path.join(config.workdir, pid, "photo2")}" \
@ -70,7 +76,7 @@ def detect_markers(psid, pid): @@ -70,7 +76,7 @@ def detect_markers(psid, pid):
-exportXMP "D:\\make2\\config\\exportXMP.config.xml" \
-exportControlPointsMeasurements "{os.path.join(config.workdir, pid, f"{pid}.controlPoints.csv")}" "D:\\make2\\config\\exportControlPoints.config.xml" \
-exportReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
{textpicCmd} -save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
print(cmd)
cmd = shlex.split(cmd)
res = subprocess.run(cmd)
@ -182,6 +188,8 @@ def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorT @@ -182,6 +188,8 @@ def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorT
libs.set_photo_join_type(config.workdir, pid, 'photo2', camcerIndex, mesh='0', texture='0')
#移除当前文件夹
shutil.rmtree(os.path.join(config.workdir, pid))
# TODO: 更新本地step1任务状态,加入step2任务队列
if task_distributed_id == "":#不是分布式任务的时候就自动往下个步骤走,是分布式任务的时候就就执行当前任务
if makeloop:

30
main_step2.py

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
import os, sys, time, shutil, subprocess, shlex
import platform
import pyautogui as ag
if platform.system() == 'Windows':
sys.path.append('e:\\libs\\')
#sys.path.append('libs')
@ -23,7 +24,7 @@ def get_rcver(): @@ -23,7 +24,7 @@ def get_rcver():
def make3d(pid):
if get_rcver() == 1: # old version
#修改重建区域的大小
common.change_rcbox_s(pid,"0.999")
common.change_rcbox_s(pid,"1")
#获取影棚id
# psid = libs.getPSid(pid)
# if int(psid) == 80:
@ -34,6 +35,26 @@ def make3d(pid): @@ -34,6 +35,26 @@ def make3d(pid):
#判断是否存在photo3
if os.path.exists(os.path.join(config.workdir, pid, 'photo3')):
add_photo3 = ' -addFolder "' + os.path.join(config.workdir, pid, 'photo3') + '" -align -align '
#存在photo3 的情况下,photo2 不参与贴图
#遍历获取photo2 目录下的所有文件
directory = os.path.join(config.workdir, pid, 'photo2')
for root, dirs, files in os.walk(directory):
for file in files:
#判断file 是否以 _8.xmp 结尾
if file.endswith("_8.xmp") == False:
continue
#修改文件内容不参与贴图
libs.set_photo_join_type(config.workdir, pid, 'photo2', file.split("_")[0], mesh='0', texture='0')
else:
#设置photo2参与贴图,因为有的时候贴图会黑
directory = os.path.join(config.workdir, pid, 'photo2')
for root, dirs, files in os.walk(directory):
for file in files:
#判断file 是否以 _8.xmp 结尾
if file.endswith("_8.xmp") == False:
continue
#修改文件内容不参与贴图
libs.set_photo_join_type(config.workdir, pid, 'photo2', file.split("_")[0], mesh='0', texture='1')
if get_rcver() == 1: # old version
@ -97,14 +118,17 @@ def make3d(pid): @@ -97,14 +118,17 @@ def make3d(pid):
print(cmd)
cmd = shlex.split(cmd)
res = subprocess.run(cmd)
#保存在导出
# common.saveScreenImg(pid)
# time.sleep(1)
# ag.hotkey('alt', 'f4')
time.sleep(3)
#修改rcproj文件
flag = common.changeRcprojFile(pid)
if flag == False:
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} rcproj文件不存在')
return
#保存在导出
#创建指定文件夹
if not os.path.exists(os.path.join(config.workdir, pid, "output")):

2
main_step3.py

@ -207,7 +207,7 @@ def step3(pid,task_distributed_id=""): @@ -207,7 +207,7 @@ def step3(pid,task_distributed_id=""):
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 模型后道处理完成,共费时{libs.diff_time(start_time)}')
res = requests.post(config.urls['update_status_modelsuccess_url'], data={'id': pid})
print('上传完成更新建模成功状态:', res.text)
shutil.rmtree(os.path.join(config.workdir, pid), ignore_errors=True)
#shutil.rmtree(os.path.join(config.workdir, pid), ignore_errors=True)
libs_db.finish_task({"task_type": "make", "task_key": pid})
if task_distributed_id:
#因为step2 和step3 是一起跑的,所以这一步先注释掉更新子表的finished_at

12
timer/get_task_to_db.py

@ -24,12 +24,12 @@ def readTask(key): @@ -24,12 +24,12 @@ def readTask(key):
return
pid = pid.decode('utf-8')
psid = getPSid(pid)
#判断是否走新的建模系统
if libs_db.is_new_make_psid(psid) == False:
#如果不是走新的建模系统就塞回原来的队列
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-该任务不是走新的建模任务,塞回原来的队列-"+pid)
r.rpush('model:'+key,pid)
return
#判断是否走新的建模系统 2023-11-10 全部走新的建模系统
# if libs_db.is_new_make_psid(psid) == False:
# #如果不是走新的建模系统就塞回原来的队列
# print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"-该任务不是走新的建模任务,塞回原来的队列-"+pid)
# r.rpush('model:'+key,pid)
# return
#新的建模系统
#psid = getPSid(pid)
if key == "make10":

2
tools/cal_weight.py

@ -89,4 +89,4 @@ if __name__ == '__main__': @@ -89,4 +89,4 @@ if __name__ == '__main__':
sizes = sys.argv[3].split(',')
for pid in pids:
main(action, pid, sizes)
print('Usage: python cal_weight.py <pids>')
print('Usage: python cal_weight.py print <pids> 自定义尺寸/默认四个尺寸就不填')
Loading…
Cancel
Save