first commit
This commit is contained in:
1 parent
f20f6f3c34
commit
7a2b784979
36 files changed
+712
-3566
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<Configuration>
|
||||
<entry key="ModelExportFormatVersion" value="0"/>
|
||||
<entry key="MvsMeshExportCamerasAsModelPart" value="false"/>
|
||||
<entry key="MvsMeshExportTexturingAllowed" value="-1"/>
|
||||
<entry key="MvsExportIsModelCoordinates" value="0"/>
|
||||
<entry key="MvsExportIsGeoreferenced" value="0x1"/>
|
||||
<entry key="MvsExportScaleZ" value="1.0"/>
|
||||
<entry key="MvsMeshExportTileType" value="0"/>
|
||||
<entry key="MvsMeshExportNormals" value="false"/>
|
||||
<entry key="MvsExportScaleY" value="1.0"/>
|
||||
<entry key="MvsMeshExportTexAlpha" value="false"/>
|
||||
<entry key="MvsExportScaleX" value="1.0"/>
|
||||
<entry key="MvsMeshExportTexImgFormat_Color8_0" value="jpg"/>
|
||||
<entry key="MvsExportcoordinatesystemtype" value="0"/>
|
||||
<entry key="MvsMeshExportTexPixFormat_Color8_0" value="32bppBGRA"/>
|
||||
<entry key="MvsMeshExportNormalsAllowed" value="-1"/>
|
||||
<entry key="MvsMeshExportNumberFormatAllowed" value="-1"/>
|
||||
<entry key="MvsExportMoveZ" value="0.0"/>
|
||||
<entry key="MvsExportMoveX" value="0.0"/>
|
||||
<entry key="MvsExportMoveY" value="0.0"/>
|
||||
<entry key="MvsExportNormalRange" value="ZeroToOne"/>
|
||||
<entry key="MvsMeshExportInfoFile" value="true"/>
|
||||
<entry key="MvsMeshExportByParts" value="0"/>
|
||||
<entry key="MvsMeshExportClassificationAllowed" value="0"/>
|
||||
<entry key="MvsMeshExportNumberFormat" value="5"/>
|
||||
<entry key="MvsExportRotationY" value="0.0"/>
|
||||
<entry key="MvsExportNormalFlipZ" value="false"/>
|
||||
<entry key="MvsExportRotationX" value="0.0"/>
|
||||
<entry key="MvsExportNormalFlipY" value="false"/>
|
||||
<entry key="MvsMeshExportCamerasAllowed" value="0"/>
|
||||
<entry key="MvsMeshExportColors" value="true"/>
|
||||
<entry key="MvsExportNormalSpace" value="Mikktspace"/>
|
||||
<entry key="MvsExportNormalFlipX" value="false"/>
|
||||
<entry key="MvsExportTransformationPreset" value="[[Default]]"/>
|
||||
<entry key="MvsExportRotationZ" value="0.0"/>
|
||||
<entry key="MvsMeshExportFileTypeSelectionDisplay" value="0"/>
|
||||
<entry key="MvsMeshExportTexOneFile" value="1"/>
|
||||
<entry key="MvsMeshExportTexturing" value="-1"/>
|
||||
<entry key="MvsMeshExportEmbeddTxrsAllowed" value="0"/>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"workdir": "D://",
|
||||
"local_need_build": "/\\172.31.1.253/modeling/local_need_build",
|
||||
"local_complate_build":"/\\172.31.1.253/modeling/local_complate_build",
|
||||
"rcbin": "'C:\\Program Files\\Capturing Reality\\RealityCapture\\RealityCapture.exe'",
|
||||
"urls": {
|
||||
"update_status_modelsuccess_url": "http://172.16.20.13:8383/update_take_photo"
|
||||
},
|
||||
"r": {
|
||||
"setTextureTrue": "-selectAllImages -enableTexturingAndColoring true",
|
||||
"setTextureFalse": "-selectAllImages -enableTexturingAndColoring false"
|
||||
},
|
||||
"r2": {
|
||||
"init": "-disableOnlineCommunication -setProjectCoordinateSystem Local:1 -setOutputCoordinateSystem epsg:4326 -set \"sfmEnableCameraPrior=False\" -set \"sfmMaxFeaturesPerMpx=20000\" -set \"sfmMaxFeaturesPerImage=200000\" -set \"sfmImagesOverlap=High\" -set \"sfmMaxFeatureReprojectionError=1\"",
|
||||
"setRegion": "-setReconstructionRegionOnCPs 36h11:001 36h11:002 36h11:003 2.1 -moveReconstructionRegion 0 0 -2.1 -rotateReconstructionRegion 180 0 180 -setGroundPlaneFromReconstructionRegion -scaleReconstructionRegion 1.8 1.6 2.1 absolute center -moveReconstructionRegion 0 0 0.0025"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
workdir = 'D://' #建模过程数据存放的目录
|
||||
local_need_build = '/\\172.31.1.253/modeling/local_need_build' #需要建模的数据存放目录
|
||||
local_complate_build = '/\\172.31.1.253/modeling/local_complate_build' #建模完成的存放目录
|
||||
rcbin = '"C:\\Program Files\\Capturing Reality\\RealityCapture\\RealityCapture.exe"'
|
||||
urls = {
|
||||
'update_status_modelsuccess_url': 'http://172.16.20.13:8383/update_take_photo',
|
||||
}
|
||||
|
||||
r = {
|
||||
"setTextureTrue" : "-selectAllImages -enableTexturingAndColoring true",
|
||||
"setTextureFalse" : "-selectAllImages -enableTexturingAndColoring false",
|
||||
}
|
||||
|
||||
r1 = {
|
||||
"init" : "-disableOnlineCommunication -set \"sfmEnableCameraPrior=False\" -set \"sfmMaxFeaturesPerMpx=20000\" -set \"sfmMaxFeaturesPerImage=200000\" -set \"sfmImagesOverlap=High\" -set \"sfmMaxFeatureReprojectionError=1\"",
|
||||
}
|
||||
|
||||
r2 = {
|
||||
"init" : "-disableOnlineCommunication -setProjectCoordinateSystem Local:1 -setOutputCoordinateSystem epsg:4326 -set \"sfmEnableCameraPrior=False\" -set \"sfmMaxFeaturesPerMpx=20000\" -set \"sfmMaxFeaturesPerImage=200000\" -set \"sfmImagesOverlap=High\" -set \"sfmMaxFeatureReprojectionError=1\"",
|
||||
"setRegion" : "-setReconstructionRegionOnCPs 36h11:001 36h11:002 36h11:003 2.1 -moveReconstructionRegion 0 0 -2.1 -rotateReconstructionRegion 180 0 180 -setGroundPlaneFromReconstructionRegion -scaleReconstructionRegion 1.8 1.6 2.1 absolute center -moveReconstructionRegion 0 0 0.0025"
|
||||
}
|
||||
|
||||
rH = {
|
||||
"init" : "-disableOnlineCommunication -set \"sfmEnableCameraPrior=False\" -set \"sfmMaxFeaturesPerMpx=10000\" -set \"sfmMaxFeaturesPerImage=80000\" -set \"sfmImagesOverlap=High\" -set \"sfmMaxFeatureReprojectionError=2\"",
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<Configuration id="{8D21413B-0848-49A9-BF6E-8EBCCA356BC7}">
|
||||
<entry key="minMarkerMeasurements" value="0x1"/>
|
||||
<entry key="generateMarkersPaperSize" value="0"/>
|
||||
<entry key="generateMarkersMarkersPerPage" value="0x4"/>
|
||||
<entry key="generateMarkersCount" value="0x4"/>
|
||||
<entry key="markerType" value="AprilTag36h11"/>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,6 @@
|
||||
<Configuration id="{E80BAEB3-7A87-4889-B150-0CF6486D7089}">
|
||||
<entry key="icpsAcc" value="4.0"/>
|
||||
<entry key="csvCPMSep" value="2"/>
|
||||
<entry key="icpsTmode" value="1"/>
|
||||
<entry key="csvCPMIgn" value="false"/>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,8 @@
|
||||
<Configuration id="{EC40D990-B2AF-42A4-9637-1208A0FD1322}">
|
||||
<entry key="xmpMerge" value="true"/>
|
||||
<entry key="xmpExGps" value="true"/>
|
||||
<entry key="xmpFlags" value="true"/>
|
||||
<entry key="xmpCalibGroups" value="true"/>
|
||||
<entry key="xmpCamera" value="3"/>
|
||||
<entry key="xmpRig" value="true"/>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,139 @@
|
||||
import os, time, json, requests, shutil, psutil
|
||||
from tqdm import tqdm
|
||||
from PIL import Image, ImageEnhance
|
||||
import config
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
def find_blender_bin_path():
|
||||
base_path = 'C:\\Program Files\\Blender Foundation\\'
|
||||
if os.path.exists(base_path):
|
||||
for dir in os.listdir(base_path):
|
||||
if dir.startswith('Blender'):
|
||||
blender_bin_path = base_path + dir + '\\blender.exe'
|
||||
return f'"{blender_bin_path}"'
|
||||
else:
|
||||
print('未找到blender安装目录')
|
||||
exit(1)
|
||||
|
||||
# def resize_photos(photo_path, ratio=0.5):
|
||||
# for filename in os.listdir(photo_path):
|
||||
# if filename.endswith('.jpg'):
|
||||
# img = Image.open(os.path.join(photo_path, filename))
|
||||
# img = rotate_image(img)
|
||||
# w, h = img.size
|
||||
# img = img.resize((int(w * ratio), int(h * ratio)))
|
||||
# img.save(os.path.join(photo_path, filename))
|
||||
|
||||
# def rotate_image(image):
|
||||
# # 检查图像的EXIF数据是否包含方向信息
|
||||
# try:
|
||||
# exif = image._getexif()
|
||||
# orientation = exif.get(0x0112)
|
||||
# except:
|
||||
# orientation = None
|
||||
|
||||
# # 根据方向信息旋转图像
|
||||
# if orientation == 3:
|
||||
# image = image.rotate(180, expand=True)
|
||||
# elif orientation == 6:
|
||||
# image = image.rotate(270, expand=True)
|
||||
# elif orientation == 8:
|
||||
# image = image.rotate(90, expand=True)
|
||||
# return image
|
||||
|
||||
# def get_ps_adjust_photo_para(psid):
|
||||
# res = requests.get(config.urls['get_ps_adjust_photo_para_url'], params={'id': psid})
|
||||
# print(res.json())
|
||||
# paras = res.json()['data']
|
||||
# brightness_factor, saturation_factor, temperature_factor = float(paras['brightness']), float(paras['saturation']), float(paras['colorTemperature'])
|
||||
# return brightness_factor, saturation_factor, temperature_factor
|
||||
|
||||
|
||||
# def getPSid(pid):
|
||||
# res = requests.get(config.urls['get_psid_url'], params={'pid': pid})
|
||||
# print('get_psid_url:', res.url)
|
||||
# print('res:', res.text)
|
||||
# res = json.loads(res.text)
|
||||
# return str(res['data'])
|
||||
|
||||
# def getHeadCount(pid):
|
||||
# return 1
|
||||
# res = requests.get(config.urls['get_printinfo_url'], params={'id': pid})
|
||||
# print('get_printinfo_url:', res.url)
|
||||
# print('res:', res.text)
|
||||
# if res.status_code != 200:
|
||||
# print('获取人数失败,程序退出')
|
||||
# exit(1)
|
||||
# res = json.loads(res.text)
|
||||
# return res['data']['headcount']
|
||||
|
||||
# def get_ps_type(pid):
|
||||
# # return 1:圆形影棚 2:方形影棚
|
||||
# #res = requests.get(config.urls['get_ps_type_url'], params={'pid': pid})
|
||||
# return 2
|
||||
|
||||
# def find_valid_camera_on_oss(pid):
|
||||
# if get_ps_type(pid) == 1:
|
||||
# print('当前拍照影棚为:圆形影棚')
|
||||
# cameras = (103, 93, 113)
|
||||
# else:
|
||||
# print('当前拍照影棚为:方形影棚')
|
||||
# cameras = (74, 64, 84)
|
||||
# find_camera = 0
|
||||
# for camera in cameras:
|
||||
# objectkey = f'photos/{pid}/photo2/{camera}_8.jpg'
|
||||
# find = config.oss_bucket.object_exists(objectkey)
|
||||
# if find:
|
||||
# find_camera = camera
|
||||
# break
|
||||
|
||||
# print('找到有效正脸相机:', find_camera)
|
||||
# if find_camera == 0:
|
||||
# print('{cameras}没有找到照片,程序退出')
|
||||
# exit(1)
|
||||
# return find_camera
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# def set_photos_join_type(workdir, pid, photoN, mesh = '0', texture='0'):
|
||||
# photoN_path = os.path.join(workdir, pid, photoN)
|
||||
# for xmp in os.listdir(photoN_path):
|
||||
# if xmp.endswith('.xmp'):
|
||||
# xmp_path = os.path.join(photoN_path, xmp)
|
||||
# with open(xmp_path, 'r') as f:
|
||||
# lines = f.readlines()
|
||||
# lines = [line.replace('xcr:InMeshing="0"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
# lines = [line.replace('xcr:InMeshing="1"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
# lines = [line.replace('xcr:InTexturing="0"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
# lines = [line.replace('xcr:InTexturing="1"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
# with open(xmp_path, 'w') as f:
|
||||
# f.writelines(lines)
|
||||
|
||||
def set_photo_join_type(workdir, pid, photoN, camera_id, mesh = '0', texture='0'):
|
||||
if photoN == 'photo1':
|
||||
filename = os.path.join(workdir, pid, photoN, f'{camera_id}_1.xmp')
|
||||
else:
|
||||
filename = os.path.join(workdir, pid, photoN, f'{camera_id}_8.xmp')
|
||||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
lines = [line.replace('xcr:InMeshing="0"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
lines = [line.replace('xcr:InMeshing="1"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
lines = [line.replace('xcr:InTexturing="0"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
lines = [line.replace('xcr:InTexturing="1"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
with open(filename, 'w') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
||||
|
||||
def diff_time(start_time):
|
||||
# 按照分:秒的方式返回时间差
|
||||
end_time = time.time()
|
||||
diff = end_time - start_time
|
||||
m, s = divmod(diff, 60)
|
||||
return f'{int(m)}分{int(s)}秒'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import os, sys, time, shlex, subprocess, shutil, requests, cv2, numpy as np
|
||||
from PIL import Image
|
||||
import json
|
||||
|
||||
|
||||
with open('config.json', 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
|
||||
def set_photo_join_type(workdir, pid, photoN, camera_id, mesh = '0', texture='0'):
|
||||
if photoN == 'photo1':
|
||||
filename = os.path.join(workdir, pid, photoN, f'{camera_id}_1.xmp')
|
||||
else:
|
||||
filename = os.path.join(workdir, pid, photoN, f'{camera_id}_8.xmp')
|
||||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
lines = [line.replace('xcr:InMeshing="0"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
lines = [line.replace('xcr:InMeshing="1"', f'xcr:InMeshing="{mesh}"') for line in lines]
|
||||
lines = [line.replace('xcr:InTexturing="0"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
lines = [line.replace('xcr:InTexturing="1"', f'xcr:InTexturing="{texture}"') for line in lines]
|
||||
with open(filename, 'w') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
||||
|
||||
def diff_time(start_time):
|
||||
# 按照分:秒的方式返回时间差
|
||||
end_time = time.time()
|
||||
diff = end_time - start_time
|
||||
m, s = divmod(diff, 60)
|
||||
return f'{int(m)}分{int(s)}秒'
|
||||
|
||||
|
||||
def filter_dark_texture_image(pid):
|
||||
start_time = time.time()
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 开始检测射灯异常图片...')
|
||||
def get_image_v(image):
|
||||
# 图片左上角和右上角各取200*200区域,计算V通道均值
|
||||
left_rect = image[0:200, 0:200]
|
||||
right_rect = image[0:200, -200:]
|
||||
|
||||
left_hsv = cv2.cvtColor(left_rect, cv2.COLOR_BGR2HSV)
|
||||
left_v = left_hsv[:, :, 2]
|
||||
left_avg_v = np.mean(left_v)
|
||||
# print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 图片左上角V通道均值:{left_avg_v}')
|
||||
|
||||
right_hsv = cv2.cvtColor(right_rect, cv2.COLOR_BGR2HSV)
|
||||
right_v = right_hsv[:, :, 2]
|
||||
right_avg_v = np.mean(right_v)
|
||||
# print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 图片右上角V通道均值:{right_avg_v}')
|
||||
return (left_avg_v + right_avg_v) / 2
|
||||
|
||||
v_list = []
|
||||
for filename in os.listdir(os.path.join(config['workdir'], pid, 'photo2')):
|
||||
if filename.endswith(".jpg"):
|
||||
image = cv2.imread(os.path.join(config['workdir'], pid, 'photo2', filename))
|
||||
v = get_image_v(image)
|
||||
item = {'filename': filename, 'v': v}
|
||||
v_list.append(item)
|
||||
v_list.sort(key=lambda x: x['v'])
|
||||
v_list = v_list[5: -5]
|
||||
avg_v = np.mean([item['v'] for item in v_list])
|
||||
for item in v_list:
|
||||
if abs(item['v'] - avg_v) > 50:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 图片{item["filename"]} V通道值{item["v"]},低于平均值{avg_v},将不参与贴图')
|
||||
set_photo_join_type(config['workdir'], pid, 'photo2', item['filename'].split('_')[0], mesh='1', texture='0')
|
||||
|
||||
# 复制xmp文件到photo3目录,如果photo3目录存在的话
|
||||
if os.path.exists(os.path.join(config['workdir'], pid, 'photo3')):
|
||||
shutil.copyfile(os.path.join(config['workdir'], pid, 'photo2', item['filename'].replace('jpg', 'xmp')), os.path.join(config['workdir'], pid, 'photo3', item['filename'].replace('jpg', 'xmp')))
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 射灯异常图片检测完成,共费时{diff_time(start_time)}')
|
||||
|
||||
def detect_markers(psid, pid):
|
||||
def fix_region():
|
||||
region_filename = os.path.join(config['workdir'], pid, f'{pid}.rcbox')
|
||||
with open(region_filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
lines = [line.replace('"NONE" globalCoordinateSystemWkt="NONE" globalCoordinateSystemName="NONE"', '"+proj=geocent +ellps=WGS84 +no_defs" globalCoordinateSystemName="local:1 - Euclidean"') for line in lines]
|
||||
|
||||
start_time = time.time()
|
||||
textpicCmd ='-selectImage "'+os.path.join(config['workdir'],pid,'photo2')+'\*" -enableTexturingAndColoring true'
|
||||
|
||||
#获取当前的工作目录
|
||||
dirCurr = os.getcwd()
|
||||
|
||||
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")}" \
|
||||
-align -selectAllImages \
|
||||
-detectMarkers "{dirCurr}\detectMarkers.config.xml" \
|
||||
-defineDistance 36h11:001 36h11:002 1 -defineDistance 36h11:002 36h11:004 1 -defineDistance 36h11:004 36h11:003 1 -defineDistance 36h11:003 36h11:001 1 -align -align -update {config["r2"]["setRegion"]} \
|
||||
-exportXMP "{dirCurr}\exportXMP.config.xml" \
|
||||
-exportControlPointsMeasurements "{os.path.join(config["workdir"], pid, f"{pid}.controlPoints.csv")}" "{dirCurr}\exportControlPoints.config.xml" \
|
||||
-exportReconstructionRegion "{os.path.join(config["workdir"], pid, f"{pid}.rcbox")}" \
|
||||
{textpicCmd} -save "{os.path.join(config["workdir"], pid, f"{pid}.rcproj")}" -quit'
|
||||
print(cmd)
|
||||
cmd = shlex.split(cmd)
|
||||
res = subprocess.run(cmd)
|
||||
time.sleep(3)
|
||||
fix_region()
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 定位点检测完成, 共费时{diff_time(start_time)}')
|
||||
|
||||
def step1(pid,headsCount):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 开始处理{pid}建模任务')
|
||||
start_time = time.time()
|
||||
# 检测图片定位点,定位异常及时上报微信通知给客服人员,人工判断是否需要重新拍摄或更换地贴。定义定位点距离,导出相机位姿信息
|
||||
detect_markers(0, pid)
|
||||
# 处理图片,检测photo2中的异常图片不参与贴图,以免破坏贴图效果,默认不检测射灯异常图片,以节省算力成本
|
||||
filter_dark_texture_image(pid)
|
||||
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} step1图片预处理完成,共费时{diff_time(start_time)}')
|
||||
# os.system(f'python {os.getcwd()}/main_step2.py {pid}')
|
||||
step2(pid,headsCount)
|
||||
|
||||
def step2(pid,headsCount):
|
||||
dirCurr = os.getcwd()
|
||||
simplify_value = 1000000 * int(headsCount)
|
||||
calulate_type = 'calculateNormalModel'
|
||||
cmd = f'{config["rcbin"]} {config["r2"]["init"]} -setInstanceName {pid} \
|
||||
-load "{os.path.join(config["workdir"], pid, f"{pid}.rcproj")}" \
|
||||
-{calulate_type} \
|
||||
-selectLargestModelComponent -invertTrianglesSelection -removeSelectedTriangles -simplify {simplify_value} -smooth -closeHoles -cleanModel -calculateTexture \
|
||||
-save "{os.path.join(config["workdir"], pid, f"{pid}.rcproj")}" \
|
||||
-exportSelectedModel "{os.path.join(config["workdir"], pid, "output", f"{pid}.obj")}" "{dirCurr}\\ModelExportParams.xml" -quit'
|
||||
print(cmd)
|
||||
cmd = shlex.split(cmd)
|
||||
res = subprocess.run(cmd)
|
||||
#阻塞判断是否导出完成
|
||||
while True:
|
||||
#判断 output 目录下是否存在 三个文件
|
||||
files = os.listdir(os.path.join(config['workdir'], pid, "output"))
|
||||
if len(files) >= 3:
|
||||
break
|
||||
|
||||
#将导出的文件移动到指定目录
|
||||
sourceDir = config["local_complate_build"]
|
||||
#判断目录是否存在,不存在就创建
|
||||
if not os.path.exists(sourceDir):
|
||||
os.makedirs(sourceDir)
|
||||
|
||||
#将 output 目录里的文件移动到指定目录
|
||||
shutil.move(os.path.join(config['workdir'], pid, "output"),os.path.join(sourceDir,pid))
|
||||
#发起请求告知后端建模完成
|
||||
try:
|
||||
res = requests.post(url, data={'id': pid,'status':5000})
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid:{pid} 任务完成- {res.text}')
|
||||
except Exception as e:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid:{pid} - 建模完成状态变更失败 - {e}')
|
||||
|
||||
|
||||
def main(pid,headsCount):
|
||||
step1(pid, headsCount)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
url = config['urls']['update_status_modelsuccess_url']
|
||||
if url == "":
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 请配置建模完成回调地址')
|
||||
exit()
|
||||
|
||||
# 取云端redis任务,完成第一步的数据预处理后,将数据放入共享存储目录,将第二步任务塞入本地mysql队列
|
||||
# 默认循环值守,可传参数运行单一任务,以方便调试
|
||||
pid = '0'
|
||||
if len(sys.argv) == 3:
|
||||
pids = sys.argv[1].split(',')
|
||||
headsCount = sys.argv[2]
|
||||
for pid in pids:
|
||||
main(pid,headsCount)
|
||||
exit()
|
||||
|
||||
#获取文件夹下的所有文件
|
||||
needBuildDir = config['local_need_build']
|
||||
workdir = config['workdir']
|
||||
if workdir == '':
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 请配置建模工作目录')
|
||||
exit()
|
||||
|
||||
#不存在就创建工作目录
|
||||
if not os.path.exists(workdir):
|
||||
os.makedirs(workdir)
|
||||
|
||||
if not os.path.exists(needBuildDir):
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 需要建模目录不存在- {needBuildDir}')
|
||||
exit()
|
||||
except Exception as e:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 初始化异常 - {e}')
|
||||
|
||||
|
||||
#遍历文件夹下的所有文件进行处理
|
||||
try:
|
||||
while True:
|
||||
time.sleep(5)
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 建模任务循环开始')
|
||||
for pid in os.listdir(needBuildDir):
|
||||
if not os.path.isdir(os.path.join(needBuildDir,pid)):
|
||||
continue
|
||||
|
||||
#判断是否存在 canDo.txt 文件,如果不存在就跳过
|
||||
if not os.path.exists(os.path.join(needBuildDir,pid,"canDo.txt")):
|
||||
continue
|
||||
|
||||
#读取 canDo.txt 文件内容
|
||||
headsCounts = 1
|
||||
with open(os.path.join(needBuildDir,pid,"canDo.txt"),"r") as f:
|
||||
headsCounts = f.read()
|
||||
|
||||
|
||||
#判断文件夹里是否存在 do.txt , 如果存在就跳过,不存在就创建
|
||||
if os.path.exists(os.path.join(needBuildDir,pid,"do.txt")):
|
||||
continue
|
||||
else:
|
||||
with open(os.path.join(needBuildDir,pid,"do.txt"),"w") as f:
|
||||
f.write("1")
|
||||
|
||||
#判断是否已经存在了,存在就删除
|
||||
if os.path.exists(os.path.join(workdir,pid)):
|
||||
shutil.rmtree(os.path.join(workdir,pid))
|
||||
|
||||
#将文件夹移动到工作目录
|
||||
shutil.move(os.path.join(needBuildDir,pid),os.path.join(workdir,pid))
|
||||
#执行建模流程,建模中的流程
|
||||
try:
|
||||
requests.post(url, data={'id': pid,'status':4000})
|
||||
except Exception as e:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid:{pid} - 状态变更失败 - {e}')
|
||||
#continue
|
||||
|
||||
main(pid,headsCounts)
|
||||
except Exception as e:
|
||||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 建模任务循环异常 - {e}')
|
||||
exit()
|
||||
|
||||
Reference in new issue
Block a user