代码更新
This commit is contained in:
1 parent
c93c9b630e
commit
09d6c3106b
5 files changed
+374
-525
No files matched your search
@@ -1,6 +1,8 @@
|
||||
|
||||
# -------------------------- 开始:运行模式 -------------------------------
|
||||
|
||||
version = "0.11.251212.1"
|
||||
|
||||
from enum import Enum
|
||||
class run_mode(Enum):
|
||||
formal = 1
|
||||
@@ -25,6 +27,7 @@ redis_config = {
|
||||
url_send_layout = 'https://mp.api.suwa3d.com/api/printTypeSettingOrder/printTypeSettingOrderSuccess'
|
||||
url_get_info_by_printIds = "https://mp.api.suwa3d.com/api/printOrder/getInfoByPrintIds?print_ids="
|
||||
url_get_oss_suffix_by_orderId = f"https://mp.api.suwa3d.com/api/order/getOssSuffixByOrderId?order_id="
|
||||
url_get_info_by_print_batch_id = f"https://mp.api.suwa3d.com/api/printOrder/getInfoByPrintBatchId?batch_id="
|
||||
|
||||
# -------------------------- 结束:网络配置 -------------------------------
|
||||
|
||||
@@ -48,9 +51,9 @@ small_machine_size = [380, 345, 250]
|
||||
# -------------------------- 开始:测试相关 -------------------------------
|
||||
|
||||
# local_data= {'machine_print_counts': 150, 'machine_type': 'big_machine', 'pre_batch_id': 9910032, 'print_machine_id': 14, 'print_orders': [{'counts': 1, 'layout_z': 35.62070959151145, 'model_weight': 41.862, 'order_id': 917900, 'pid': 376666, 'print_id': 126318}, {'counts': 1, 'layout_z': 31.380497732946978, 'model_weight': 35.158, 'order_id': 917810, 'pid': 376562, 'print_id': 126413}, {'counts': 1, 'layout_z': 26.136854969886777, 'model_weight': 21.403, 'order_id': 917820, 'pid': 376572, 'print_id': 126414}, {'counts': 1, 'layout_z': 37.967177899738104, 'model_weight': 30.48, 'order_id': 917922, 'pid': 376684, 'print_id': 126415}, {'counts': 1, 'layout_z': 20.368887098446734, 'model_weight': 13.097, 'order_id': 918228, 'pid': 377198, 'print_id': 126417}, {'counts': 1, 'layout_z': 21.4227336927951, 'model_weight': 15.859, 'order_id': 917576, 'pid': 376345, 'print_id': 126769}, {'counts': 1, 'layout_z': 27.539947066784066, 'model_weight': 25.185, 'order_id': 917811, 'pid': 376564, 'print_id': 126875}, {'counts': 1, 'layout_z': 31.692723822970393, 'model_weight': 32.796, 'order_id': 917821, 'pid': 376592, 'print_id': 126876}, {'counts': 1, 'layout_z': 20.20031720146163, 'model_weight': 8.664, 'order_id': 917822, 'pid': 376602, 'print_id': 126877}, {'counts': 1, 'layout_z': 22.41680629925537, 'model_weight': 15.206, 'order_id': 917827, 'pid': 376616, 'print_id': 126878}, {'counts': 1, 'layout_z': 25.443981671314514, 'model_weight': 11.965, 'order_id': 917879, 'pid': 376635, 'print_id': 126879}, {'counts': 1, 'layout_z': 31.09222672704002, 'model_weight': 20.318, 'order_id': 917902, 'pid': 376667, 'print_id': 126882}, {'counts': 1, 'layout_z': 30.3317820592175, 'model_weight': 32.964, 'order_id': 917903, 'pid': 376668, 'print_id': 126884}, {'counts': 1, 'layout_z': 28.69639626624317, 'model_weight': 27.751, 'order_id': 917904, 'pid': 376669, 'print_id': 126885}, {'counts': 1, 'layout_z': 28.043180029163203, 'model_weight': 19.866, 'order_id': 917917, 'pid': 376677, 'print_id': 126886}, {'counts': 1, 'layout_z': 28.58783468947201, 'model_weight': 25.505, 'order_id': 918196, 'pid': 377126, 'print_id': 126888}, {'counts': 1, 'layout_z': 43.55871899466554, 'model_weight': 63.512, 'order_id': 918201, 'pid': 377131, 'print_id': 126890}, {'counts': 1, 'layout_z': 32.52479624889478, 'model_weight': 22.943, 'order_id': 918203, 'pid': 377133, 'print_id': 126891}, {'counts': 1, 'layout_z': 33.21834123013511, 'model_weight': 42.163, 'order_id': 918206, 'pid': 377139, 'print_id': 126892}, {'counts': 1, 'layout_z': 27.81674335447885, 'model_weight': 15.455, 'order_id': 918207, 'pid': 377141, 'print_id': 126893}, {'counts': 1, 'layout_z': 29.78203639784899, 'model_weight': 29.696, 'order_id': 918231, 'pid': 377201, 'print_id': 126894}, {'counts': 1, 'layout_z': 23.66875736859606, 'model_weight': 13.39, 'order_id': 915637, 'pid': 373135, 'print_id': 126895}, {'counts': 1, 'layout_z': 29.00408914521088, 'model_weight': 19.553, 'order_id': 918246, 'pid': 377209, 'print_id': 126897}, {'counts': 1, 'layout_z': 24.44397251338635, 'model_weight': 15.424, 'order_id': 918325, 'pid': 376974, 'print_id': 126899}, {'counts': 1, 'layout_z': 31.755406379699707, 'model_weight': 31.131, 'order_id': 918492, 'pid': 377584, 'print_id': 126900}, {'counts': 1, 'layout_z': 38.03699946264237, 'model_weight': 47.412, 'order_id': 918493, 'pid': 377587, 'print_id': 126901}, {'counts': 1, 'layout_z': 43.52919799223749, 'model_weight': 37.842, 'order_id': 918494, 'pid': 377589, 'print_id': 126902}, {'counts': 1, 'layout_z': 25.906302369108843, 'model_weight': 18.64, 'order_id': 918495, 'pid': 377590, 'print_id': 126903}, {'counts': 1, 'layout_z': 36.02611978829816, 'model_weight': 43.814, 'order_id': 918496, 'pid': 377591, 'print_id': 126904}, {'counts': 1, 'layout_z': 26.020689766262052, 'model_weight': 18.513, 'order_id': 918497, 'pid': 377594, 'print_id': 126905}, {'counts': 1, 'layout_z': 23.988078117370605, 'model_weight': 15.753, 'order_id': 918498, 'pid': 377596, 'print_id': 126906}, {'counts': 1, 'layout_z': 27.457814063914604, 'model_weight': 23.507, 'order_id': 918500, 'pid': 377601, 'print_id': 126908}, {'counts': 1, 'layout_z': 29.306090320672993, 'model_weight': 25.043, 'order_id': 918501, 'pid': 377605, 'print_id': 126909}, {'counts': 1, 'layout_z': 29.070231478924583, 'model_weight': 25.598, 'order_id': 918504, 'pid': 377606, 'print_id': 126910}, {'counts': 1, 'layout_z': 24.314504768436095, 'model_weight': 18.68, 'order_id': 918555, 'pid': 377684, 'print_id': 126911}, {'counts': 1, 'layout_z': 37.52979171030315, 'model_weight': 53.541, 'order_id': 918558, 'pid': 377689, 'print_id': 126913}, {'counts': 1, 'layout_z': 26.530791960490333, 'model_weight': 15.082, 'order_id': 918560, 'pid': 377702, 'print_id': 126915}, {'counts': 1, 'layout_z': 23.604568481445312, 'model_weight': 21.614, 'order_id': 918583, 'pid': 377748, 'print_id': 126917}, {'counts': 1, 'layout_z': 27.865868478825355, 'model_weight': 22.6, 'order_id': 918636, 'pid': 37Line truncated
|
||||
# local_data= {"machine_print_counts":50, 'machine_type': 'small_machine',"pre_batch_id":991112,"print_machine_id":22,"print_orders":[{"counts":1,"layout_z":3.543965775898459,"model_weight":12.833,"order_id":857420,"pid":268473,"print_id":85240},{"counts":1,"layout_z":7.798861189952786,"model_weight":13.784,"order_id":875986,"pid":305425,"print_id":88136}]}
|
||||
local_data= {"machine_print_counts":50, 'machine_type': 'small_machine',"pre_batch_id":991112,"print_machine_id":22,"print_orders":[{"counts":1,"layout_z":3.543965775898459,"model_weight":12.833,"order_id":857420,"pid":268473,"print_id":85240},{"counts":1,"layout_z":7.798861189952786,"model_weight":13.784,"order_id":875986,"pid":305425,"print_id":88136}]}
|
||||
# local_data= {'machine_print_counts': 130, 'machine_type': 'big_machine', 'pre_batch_id': 9910188, 'print_machine_id': 15, 'print_orders': [{'counts': 1, 'layout_z': 32.65071311811036, 'model_weight': 68.084, 'order_id': 926400, 'pid': 389256, 'print_id': 134168}, {'counts': 1, 'layout_z': 31.780598561603746, 'model_weight': 25.511, 'order_id': 926573, 'pid': 389465, 'print_id': 134170}, {'counts': 1, 'layout_z': 5.202356934547428, 'model_weight': 11.705, 'order_id': 925909, 'pid': 388682, 'print_id': 134178}, {'counts': 1, 'layout_z': 5.1447470188140905, 'model_weight': 12.186, 'order_id': 925910, 'pid': 388683, 'print_id': 134179}, {'counts': 1, 'layout_z': 5.013986945152283, 'model_weight': 11.364, 'order_id': 925932, 'pid': 388707, 'print_id': 134180}, {'counts': 1, 'layout_z': 5.020000934600831, 'model_weight': 11.396, 'order_id': 926770, 'pid': 389842, 'print_id': 134183}, {'counts': 1, 'layout_z': 40.05588230441501, 'model_weight': 60.578, 'order_id': 926776, 'pid': 389895, 'print_id': 134185}, {'counts': 1, 'layout_z': 46.23669371110479, 'model_weight': 56.196, 'order_id': 926778, 'pid': 389918, 'print_id': 134186}, {'counts': 1, 'layout_z': 24.822566986083984, 'model_weight': 31.522, 'order_id': 926268, 'pid': 389067, 'print_id': 134211}, {'counts': 1, 'layout_z': 25.085425667575343, 'model_weight': 31.077, 'order_id': 926267, 'pid': 389066, 'print_id': 134212}, {'counts': 1, 'layout_z': 18.154759649173364, 'model_weight': 6.256, 'order_id': 927059, 'pid': 390269, 'print_id': 134216}, {'counts': 1, 'layout_z': 24.2420189021486, 'model_weight': 14.472, 'order_id': 927065, 'pid': 390275, 'print_id': 134220}, {'counts': 1, 'layout_z': 16.757099114319693, 'model_weight': 5.335, 'order_id': 927078, 'pid': 390299, 'print_id': 134226}, {'counts': 1, 'layout_z': 18.796780948141503, 'model_weight': 7.295, 'order_id': 927079, 'pid': 390300, 'print_id': 134228}, {'counts': 1, 'layout_z': 17.920740666248633, 'model_weight': 7.869, 'order_id': 927082, 'pid': 390303, 'print_id': 134229}, {'counts': 1, 'layout_z': 16.320665859825066, 'model_weight': 4.73, 'order_id': 927081, 'pid': 390302, 'print_id': 134230}, {'counts': 1, 'layout_z': 23.250497020255544, 'model_weight': 15.567, 'order_id': 927100, 'pid': 390331, 'print_id': 134242}, {'counts': 1, 'layout_z': 26.276874511435977, 'model_weight': 19.813, 'order_id': 927103, 'pid': 390334, 'print_id': 134246}, {'counts': 1, 'layout_z': 17.08049576865031, 'model_weight': 5.858, 'order_id': 927111, 'pid': 390342, 'print_id': 134254}, {'counts': 1, 'layout_z': 19.196685578562278, 'model_weight': 6.465, 'order_id': 927117, 'pid': 390347, 'print_id': 134261}, {'counts': 1, 'layout_z': 26.507062216602122, 'model_weight': 14.287, 'order_id': 927116, 'pid': 390346, 'print_id': 134262}, {'counts': 1, 'layout_z': 16.440782827635232, 'model_weight': 5.493, 'order_id': 927118, 'pid': 390348, 'print_id': 134263}, {'counts': 1, 'layout_z': 41.42868301509347, 'model_weight': 68.274, 'order_id': 927122, 'pid': 390354, 'print_id': 134264}, {'counts': 1, 'layout_z': 15.705368176518945, 'model_weight': 4.423, 'order_id': 927119, 'pid': 390349, 'print_id': 134265}, {'counts': 1, 'layout_z': 16.363223697461702, 'model_weight': 5.634, 'order_id': 927120, 'pid': 390351, 'print_id': 134266}, {'counts': 1, 'layout_z': 24.653417686230497, 'model_weight': 17.851, 'order_id': 927121, 'pid': 390353, 'print_id': 134267}, {'counts': 1, 'layout_z': 24.327745611835496, 'model_weight': 28.23, 'order_id': 926040, 'pid': 388832, 'print_id': 134268}, {'counts': 1, 'layout_z': 27.301779030909188, 'model_weight': 23.926, 'order_id': 923281, 'pid': 385001, 'print_id': 134269}, {'counts': 1, 'layout_z': 25.869120288866796, 'model_weight': 32.329, 'order_id': 926077, 'pid': 388864, 'print_id': 134270}, {'counts': 1, 'layout_z': 36.37214874852985, 'model_weight': 65.744, 'order_id': 926086, 'pid': 388873, 'print_id': 134271}, {'counts': 1, 'layout_z': 37.44403689090713, 'model_weight': 80.67, 'order_id': 926097, 'pid': 388884, 'print_id': 134273}, {'counts': 1, 'layout_z': 27.890566642299536, 'model_weight': 22.715, 'order_id': 927127, 'pid': 390372, 'print_id': 134274}, {'counts': 1, 'layout_z': 17.392635113631542, 'model_weight': 5.297, 'order_id': 927128, 'pid': 390373, 'print_id': 134275}, {'counts': 1, 'layout_z': 26.139986312446986, 'model_weight': 15.312, 'order_id': 927129, 'pid': 390375, 'print_id': 134276}, {'counts': 1, 'layout_z': 17.491576609126483, 'model_weight': 6.495, 'order_id': 927130, 'pid': 390376, 'print_id': 134277}, {'counts': 1, 'layout_z': 15.57976295844962, 'model_weight': 5.443, 'order_id': 927131, 'pid': 390377, 'print_id': 134278}, {'counts': 1, 'layout_z': 16.006999969482422, 'model_weight': 4.683, 'order_id': 927132, 'pid': 390378, 'print_id': 134279}, {'counts': 1, 'layout_z': 18.770485206437296, 'model_weight': 6.114, 'order_id': 927137, 'pid': 390383, 'print_id': 134280}, {'counts': 1, 'layout_z': 21.480148458997267, 'model_weight': 9.586, 'order_id': 927133, 'pid': 39037Line truncated
|
||||
local_data= {'machine_print_counts': 60, 'machine_type': 'small_machine', 'pre_batch_id': 10284, 'print_machine_id': 1, 'print_orders': [{'counts': 1, 'layout_z': 6.981930971145635, 'model_weight': 26.776, 'order_id': 929174, 'pid': 393697, 'print_id': 138265}, {'counts': 1, 'layout_z': 4.955404043197634, 'model_weight': 9.22, 'order_id': 931997, 'pid': 397013, 'print_id': 138846}, {'counts': 1, 'layout_z': 4.771067023277285, 'model_weight': 11.786, 'order_id': 932000, 'pid': 397016, 'print_id': 138851}, {'counts': 1, 'layout_z': 5.249161005020142, 'model_weight': 10.024, 'order_id': 932003, 'pid': 397019, 'print_id': 138854}, {'counts': 1, 'layout_z': 5.251940011978151, 'model_weight': 10.104, 'order_id': 932005, 'pid': 397021, 'print_id': 138856}, {'counts': 1, 'layout_z': 5.263678073883059, 'model_weight': 10.688, 'order_id': 932009, 'pid': 397025, 'print_id': 138875}, {'counts': 1, 'layout_z': 23.813366889953613, 'model_weight': 24.641, 'order_id': 929102, 'pid': 393961, 'print_id': 139071}, {'counts': 1, 'layout_z': 4.554790019989014, 'model_weight': 11.507, 'order_id': 933586, 'pid': 399522, 'print_id': 140121}, {'counts': 1, 'layout_z': 4.795650005340576, 'model_weight': 11.042, 'order_id': 933568, 'pid': 399331, 'print_id': 140150}, {'counts': 1, 'layout_z': 18.085672736889748, 'model_weight': 7.277, 'order_id': 933876, 'pid': 399901, 'print_id': 140261}, {'counts': 1, 'layout_z': 19.534520236131655, 'model_weight': 6.937, 'order_id': 933878, 'pid': 399903, 'print_id': 140264}, {'counts': 1, 'layout_z': 19.559980709635155, 'model_weight': 7.79, 'order_id': 933877, 'pid': 399902, 'print_id': 140265}, {'counts': 1, 'layout_z': 16.488399505615234, 'model_weight': 5.349, 'order_id': 933882, 'pid': 399907, 'print_id': 140271}, {'counts': 1, 'layout_z': 18.02717763893993, 'model_weight': 5.892, 'order_id': 933885, 'pid': 399910, 'print_id': 140277}, {'counts': 1, 'layout_z': 26.876644549545638, 'model_weight': 21.486, 'order_id': 933886, 'pid': 399911, 'print_id': 140278}, {'counts': 1, 'layout_z': 28.074640440717047, 'model_weight': 16.17, 'order_id': 933887, 'pid': 399912, 'print_id': 140280}, {'counts': 1, 'layout_z': 27.306154248118705, 'model_weight': 20.977, 'order_id': 933889, 'pid': 399927, 'print_id': 140281}, {'counts': 1, 'layout_z': 26.094746051465723, 'model_weight': 34.197, 'order_id': 933888, 'pid': 399926, 'print_id': 140282}, {'counts': 1, 'layout_z': 15.87796963527322, 'model_weight': 4.735, 'order_id': 933892, 'pid': 399930, 'print_id': 140287}, {'counts': 1, 'layout_z': 18.191209446277444, 'model_weight': 5.246, 'order_id': 933893, 'pid': 399931, 'print_id': 140288}, {'counts': 1, 'layout_z': 17.777126572389776, 'model_weight': 6.334, 'order_id': 933894, 'pid': 399932, 'print_id': 140289}, {'counts': 1, 'layout_z': 17.58385879418167, 'model_weight': 5.8, 'order_id': 933895, 'pid': 399933, 'print_id': 140290}, {'counts': 1, 'layout_z': 18.593739251800994, 'model_weight': 6.955, 'order_id': 933897, 'pid': 399935, 'print_id': 140293}, {'counts': 1, 'layout_z': 14.231568581173965, 'model_weight': 3.705, 'order_id': 933898, 'pid': 399936, 'print_id': 140294}, {'counts': 1, 'layout_z': 13.998784146949038, 'model_weight': 3.533, 'order_id': 933899, 'pid': 399937, 'print_id': 140295}, {'counts': 1, 'layout_z': 15.9964307861582, 'model_weight': 4.301, 'order_id': 933901, 'pid': 399939, 'print_id': 140297}, {'counts': 1, 'layout_z': 16.18931739014667, 'model_weight': 5.019, 'order_id': 933903, 'pid': 399941, 'print_id': 140299}, {'counts': 1, 'layout_z': 24.79611153168641, 'model_weight': 20.601, 'order_id': 933905, 'pid': 399943, 'print_id': 140301}, {'counts': 1, 'layout_z': 24.306803898330127, 'model_weight': 16.784, 'order_id': 933906, 'pid': 399944, 'print_id': 140302}, {'counts': 1, 'layout_z': 29.3158714015686, 'model_weight': 19.351, 'order_id': 933907, 'pid': 399945, 'print_id': 140303}, {'counts': 1, 'layout_z': 17.005620048049607, 'model_weight': 5.169, 'order_id': 933910, 'pid': 399948, 'print_id': 140305}, {'counts': 1, 'layout_z': 16.464274211211865, 'model_weight': 4.866, 'order_id': 933909, 'pid': 399947, 'print_id': 140306}, {'counts': 1, 'layout_z': 23.198866489386088, 'model_weight': 10.524, 'order_id': 933911, 'pid': 399949, 'print_id': 140307}, {'counts': 1, 'layout_z': 26.516445616407367, 'model_weight': 23.957, 'order_id': 933912, 'pid': 399950, 'print_id': 140308}, {'counts': 1, 'layout_z': 17.937848519147412, 'model_weight': 5.282, 'order_id': 933914, 'pid': 399952, 'print_id': 140310}, {'counts': 1, 'layout_z': 26.754205819816015, 'model_weight': 20.607, 'order_id': 933921, 'pid': 399957, 'print_id': 140315}, {'counts': 1, 'layout_z': 20.002697843362704, 'model_weight': 7.63, 'order_id': 933924, 'pid': 399960, 'print_id': 140318}, {'counts': 1, 'layout_z': 30.231639651233593, 'model_weight': 24.508, 'order_id': 933925, 'pid': 399961, 'print_id': 140319}, {'counts': 1, 'layout_z': 16.061075531610975, 'model_weight': 4.195, 'order_id': 933928, 'pid': 399964, 'print_id': Line truncated
|
||||
# local_data= {'machine_print_counts': 60, 'machine_type': 'small_machine', 'pre_batch_id': 9910284, 'print_machine_id': 1, 'print_orders': [{'counts': 1, 'layout_z': 6.981930971145635, 'model_weight': 26.776, 'order_id': 929174, 'pid': 393697, 'print_id': 138265}, {'counts': 1, 'layout_z': 4.955404043197634, 'model_weight': 9.22, 'order_id': 931997, 'pid': 397013, 'print_id': 138846}, {'counts': 1, 'layout_z': 4.771067023277285, 'model_weight': 11.786, 'order_id': 932000, 'pid': 397016, 'print_id': 138851}, {'counts': 1, 'layout_z': 5.249161005020142, 'model_weight': 10.024, 'order_id': 932003, 'pid': 397019, 'print_id': 138854}, {'counts': 1, 'layout_z': 5.251940011978151, 'model_weight': 10.104, 'order_id': 932005, 'pid': 397021, 'print_id': 138856}, {'counts': 1, 'layout_z': 5.263678073883059, 'model_weight': 10.688, 'order_id': 932009, 'pid': 397025, 'print_id': 138875}, {'counts': 1, 'layout_z': 23.813366889953613, 'model_weight': 24.641, 'order_id': 929102, 'pid': 393961, 'print_id': 139071}, {'counts': 1, 'layout_z': 4.554790019989014, 'model_weight': 11.507, 'order_id': 933586, 'pid': 399522, 'print_id': 140121}, {'counts': 1, 'layout_z': 4.795650005340576, 'model_weight': 11.042, 'order_id': 933568, 'pid': 399331, 'print_id': 140150}, {'counts': 1, 'layout_z': 18.085672736889748, 'model_weight': 7.277, 'order_id': 933876, 'pid': 399901, 'print_id': 140261}, {'counts': 1, 'layout_z': 19.534520236131655, 'model_weight': 6.937, 'order_id': 933878, 'pid': 399903, 'print_id': 140264}, {'counts': 1, 'layout_z': 19.559980709635155, 'model_weight': 7.79, 'order_id': 933877, 'pid': 399902, 'print_id': 140265}, {'counts': 1, 'layout_z': 16.488399505615234, 'model_weight': 5.349, 'order_id': 933882, 'pid': 399907, 'print_id': 140271}, {'counts': 1, 'layout_z': 18.02717763893993, 'model_weight': 5.892, 'order_id': 933885, 'pid': 399910, 'print_id': 140277}, {'counts': 1, 'layout_z': 26.876644549545638, 'model_weight': 21.486, 'order_id': 933886, 'pid': 399911, 'print_id': 140278}, {'counts': 1, 'layout_z': 28.074640440717047, 'model_weight': 16.17, 'order_id': 933887, 'pid': 399912, 'print_id': 140280}, {'counts': 1, 'layout_z': 27.306154248118705, 'model_weight': 20.977, 'order_id': 933889, 'pid': 399927, 'print_id': 140281}, {'counts': 1, 'layout_z': 26.094746051465723, 'model_weight': 34.197, 'order_id': 933888, 'pid': 399926, 'print_id': 140282}, {'counts': 1, 'layout_z': 15.87796963527322, 'model_weight': 4.735, 'order_id': 933892, 'pid': 399930, 'print_id': 140287}, {'counts': 1, 'layout_z': 18.191209446277444, 'model_weight': 5.246, 'order_id': 933893, 'pid': 399931, 'print_id': 140288}, {'counts': 1, 'layout_z': 17.777126572389776, 'model_weight': 6.334, 'order_id': 933894, 'pid': 399932, 'print_id': 140289}, {'counts': 1, 'layout_z': 17.58385879418167, 'model_weight': 5.8, 'order_id': 933895, 'pid': 399933, 'print_id': 140290}, {'counts': 1, 'layout_z': 18.593739251800994, 'model_weight': 6.955, 'order_id': 933897, 'pid': 399935, 'print_id': 140293}, {'counts': 1, 'layout_z': 14.231568581173965, 'model_weight': 3.705, 'order_id': 933898, 'pid': 399936, 'print_id': 140294}, {'counts': 1, 'layout_z': 13.998784146949038, 'model_weight': 3.533, 'order_id': 933899, 'pid': 399937, 'print_id': 140295}, {'counts': 1, 'layout_z': 15.9964307861582, 'model_weight': 4.301, 'order_id': 933901, 'pid': 399939, 'print_id': 140297}, {'counts': 1, 'layout_z': 16.18931739014667, 'model_weight': 5.019, 'order_id': 933903, 'pid': 399941, 'print_id': 140299}, {'counts': 1, 'layout_z': 24.79611153168641, 'model_weight': 20.601, 'order_id': 933905, 'pid': 399943, 'print_id': 140301}, {'counts': 1, 'layout_z': 24.306803898330127, 'model_weight': 16.784, 'order_id': 933906, 'pid': 399944, 'print_id': 140302}, {'counts': 1, 'layout_z': 29.3158714015686, 'model_weight': 19.351, 'order_id': 933907, 'pid': 399945, 'print_id': 140303}, {'counts': 1, 'layout_z': 17.005620048049607, 'model_weight': 5.169, 'order_id': 933910, 'pid': 399948, 'print_id': 140305}, {'counts': 1, 'layout_z': 16.464274211211865, 'model_weight': 4.866, 'order_id': 933909, 'pid': 399947, 'print_id': 140306}, {'counts': 1, 'layout_z': 23.198866489386088, 'model_weight': 10.524, 'order_id': 933911, 'pid': 399949, 'print_id': 140307}, {'counts': 1, 'layout_z': 26.516445616407367, 'model_weight': 23.957, 'order_id': 933912, 'pid': 399950, 'print_id': 140308}, {'counts': 1, 'layout_z': 17.937848519147412, 'model_weight': 5.282, 'order_id': 933914, 'pid': 399952, 'print_id': 140310}, {'counts': 1, 'layout_z': 26.754205819816015, 'model_weight': 20.607, 'order_id': 933921, 'pid': 399957, 'print_id': 140315}, {'counts': 1, 'layout_z': 20.002697843362704, 'model_weight': 7.63, 'order_id': 933924, 'pid': 399960, 'print_id': 140318}, {'counts': 1, 'layout_z': 30.231639651233593, 'model_weight': 24.508, 'order_id': 933925, 'pid': 399961, 'print_id': 140319}, {'counts': 1, 'layout_z': 16.061075531610975, 'model_weight': 4.195, 'order_id': 933928, 'pid': 399964, 'print_iLine truncated
|
||||
|
||||
test_print_max = 0
|
||||
|
||||
|
||||
+20
-464
@@ -1,455 +1,31 @@
|
||||
import yaml
|
||||
import oss2
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
# from utils.log_utils import log_execution
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import collections
|
||||
import os
|
||||
import argparse
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from config import oss_config
|
||||
from config import print_data_dir
|
||||
from config import url_get_oss_suffix_by_orderId
|
||||
from config import url_get_info_by_print_batch_id
|
||||
|
||||
from general import is_use_debug_oss
|
||||
from general import transform_save_bpy
|
||||
from general import read_models_from_json
|
||||
from general import is_small_machine
|
||||
|
||||
from compute_print_net import get_oss_client
|
||||
|
||||
class DataTransfer:
|
||||
'''
|
||||
数据传输类
|
||||
'''
|
||||
def __init__(self, local_path: str, oss_path: str, oss_client: oss2.Bucket):
|
||||
'''
|
||||
local_path: 本地输出路径
|
||||
oss_path: oss路径
|
||||
oss_client: oss客户端
|
||||
'''
|
||||
self.local_path = local_path
|
||||
self.oss_path = oss_path.lstrip('/')
|
||||
self.oss_client = oss_client
|
||||
# self.description = description
|
||||
|
||||
# @log_execution(self.description)
|
||||
def download_data(self):
|
||||
"""
|
||||
从 OSS 下载数据到本地,保持原有目录结构
|
||||
"""
|
||||
|
||||
# 列出所有对象
|
||||
objects = []
|
||||
prefix = self.oss_path.lstrip('/') # 移除开头的 '/' 以匹配 OSS 格式
|
||||
|
||||
for obj in oss2.ObjectIterator(self.oss_client, prefix=prefix):
|
||||
if obj.key != prefix: # 跳过目录本身
|
||||
objects.append(obj.key)
|
||||
|
||||
# 下载所有文件,添加进度条
|
||||
for obj_key in tqdm(objects, desc="下载进度"):
|
||||
if obj_key.endswith('/'):
|
||||
continue
|
||||
|
||||
if "printId" in obj_key:
|
||||
continue
|
||||
|
||||
# 计算相对路径
|
||||
rel_path = obj_key[len(prefix):].lstrip('/')
|
||||
# 构建本地完整路径
|
||||
local_path = os.path.join(self.local_path, rel_path)
|
||||
|
||||
# 创建必要的目录
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
# 下载文件
|
||||
self.oss_client.get_object_to_file(obj_key, local_path)
|
||||
|
||||
print("download_data local_path=" + local_path)
|
||||
|
||||
order_id: str
|
||||
pid: str
|
||||
model_height: str
|
||||
|
||||
def download_data_rename_json(self, json_model_info):
|
||||
"""
|
||||
从 OSS 下载数据到本地,保持原有目录结构
|
||||
"""
|
||||
|
||||
# 列出所有对象
|
||||
objects = []
|
||||
prefix = self.oss_path.lstrip('/') # 移除开头的 '/' 以匹配 OSS 格式
|
||||
|
||||
for obj in oss2.ObjectIterator(self.oss_client, prefix=prefix):
|
||||
if obj.key != prefix: # 跳过目录本身
|
||||
objects.append(obj.key)
|
||||
|
||||
# 下载所有文件,添加进度条
|
||||
for obj_key in tqdm(objects, desc="下载进度"):
|
||||
if obj_key.endswith('/'):
|
||||
continue
|
||||
|
||||
if "printId" in obj_key:
|
||||
continue
|
||||
|
||||
# 计算相对路径
|
||||
rel_path = obj_key[len(prefix):].lstrip('/')
|
||||
|
||||
file_dir, file_name = os.path.split(rel_path)
|
||||
file_base, file_ext = os.path.splitext(file_name)
|
||||
|
||||
# 根据文件后缀名进行重命名
|
||||
if file_ext.lower() in ['.mtl', '.jpg', '.jpeg', '.png']:
|
||||
# 对于.mtl和图片文件,在原名前加order_id
|
||||
new_file_name = f"{json_model_info.order_id}_{file_name}"
|
||||
# new_file_name = file_name
|
||||
elif file_ext.lower() == '.obj':
|
||||
# 对于.obj文件,完全重命名
|
||||
new_file_name = f"{json_model_info.obj_name}"
|
||||
else:
|
||||
# 其他文件类型保持原名
|
||||
new_file_name = file_name
|
||||
print("new_file_name=", new_file_name)
|
||||
|
||||
# 构建新的相对路径
|
||||
if file_dir: # 如果有子目录
|
||||
new_rel_path = os.path.join(file_dir, new_file_name)
|
||||
else:
|
||||
new_rel_path = new_file_name
|
||||
|
||||
# 构建本地完整路径
|
||||
local_path = os.path.join(self.local_path, new_rel_path)
|
||||
|
||||
# 创建必要的目录
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
# 下载文件
|
||||
self.oss_client.get_object_to_file(obj_key, local_path)
|
||||
|
||||
if file_ext == '.obj': # 10MB以上
|
||||
try:
|
||||
# 使用临时文件避免内存问题 [8](@ref)
|
||||
temp_path = local_path + '.tmp'
|
||||
with open(local_path, 'r', encoding='utf-8') as f_in, \
|
||||
open(temp_path, 'w', encoding='utf-8') as f_out:
|
||||
|
||||
mtllib_modified = False
|
||||
for line in f_in:
|
||||
if not mtllib_modified and line.strip().startswith('mtllib '):
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_mtl_name = parts[1].strip()
|
||||
new_mtl_name = f"{json_model_info.order_id}_{old_mtl_name}"
|
||||
f_out.write(f"mtllib {new_mtl_name}\n")
|
||||
mtllib_modified = True
|
||||
continue
|
||||
f_out.write(line)
|
||||
|
||||
os.replace(temp_path, local_path) # 原子性替换
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理大文件 {local_path} 时出错: {e}")
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
|
||||
# 优化后的.obj文件处理逻辑
|
||||
if file_ext == '.mtl':
|
||||
try:
|
||||
# 使用更高效的文件读取方式 [6,8](@ref)
|
||||
with open(local_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 使用字符串方法直接查找和替换,避免不必要的循环 [9](@ref)
|
||||
lines = content.split('\n')
|
||||
mtllib_modified = False
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
stripped_line = line.strip()
|
||||
if not mtllib_modified and stripped_line.startswith('map_Kd '):
|
||||
# 更高效的分割方式 [9](@ref)
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_name = parts[1].strip()
|
||||
new_name = f"{json_model_info.order_id}_{old_name}"
|
||||
lines[i] = f"map_Kd {new_name}"
|
||||
mtllib_modified = True
|
||||
print(f"已更新材质库引用: {old_name} -> {new_name}")
|
||||
break # 找到第一个后立即退出
|
||||
|
||||
# 批量写入,减少I/O操作 [6](@ref)
|
||||
with open(local_path, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理文件 {local_path} 时出错: {e}")
|
||||
except UnicodeDecodeError as e:
|
||||
print(f"文件编码错误 {local_path}: {e}")
|
||||
|
||||
print(f"下载文件: {obj_key} -> {local_path}")
|
||||
|
||||
def download_data_rename_batch(self, batch_model_info):
|
||||
"""
|
||||
从 OSS 下载数据到本地,保持原有目录结构
|
||||
"""
|
||||
|
||||
# 列出所有对象
|
||||
objects = []
|
||||
prefix = self.oss_path.lstrip('/') # 移除开头的 '/' 以匹配 OSS 格式
|
||||
|
||||
prefix_exists = False
|
||||
|
||||
for obj in oss2.ObjectIterator(self.oss_client, prefix=prefix):
|
||||
prefix_exists = True
|
||||
if obj.key != prefix: # 跳过目录本身
|
||||
objects.append(obj.key)
|
||||
print(f"obj.key={obj.key}")
|
||||
|
||||
if not prefix_exists:
|
||||
print(f"前缀 '{prefix}' 下没有找到任何文件或目录。")
|
||||
return False
|
||||
else:
|
||||
print(f"前缀 '{prefix}' 存在,共找到 {len(objects)} 个对象。")
|
||||
|
||||
# 下载所有文件,添加进度条
|
||||
for obj_key in tqdm(objects, desc="下载进度"):
|
||||
if obj_key.endswith('/'):
|
||||
print("下载 endswith('/'")
|
||||
continue
|
||||
|
||||
if "printId" in obj_key:
|
||||
print(f"下载 in obj_key")
|
||||
continue
|
||||
|
||||
# 计算相对路径
|
||||
rel_path = obj_key[len(prefix):].lstrip('/')
|
||||
|
||||
file_dir, file_name = os.path.split(rel_path)
|
||||
file_base, file_ext = os.path.splitext(file_name)
|
||||
|
||||
# 根据文件后缀名进行重命名
|
||||
if file_ext.lower() in ['.mtl', '.jpg', '.jpeg', '.png']:
|
||||
# 对于.mtl和图片文件,在原名前加order_id
|
||||
new_file_name = f"{batch_model_info.order_id}_{file_name}"
|
||||
# new_file_name = file_name
|
||||
elif file_ext.lower() == '.obj':
|
||||
# 对于.obj文件,完全重命名
|
||||
new_file_name = f"{batch_model_info.order_id}_{batch_model_info.pid}_P{batch_model_info.print_order_id}_{batch_model_info.model_size}{file_ext}"
|
||||
else:
|
||||
# 其他文件类型保持原名
|
||||
new_file_name = file_name
|
||||
|
||||
# 构建新的相对路径
|
||||
if file_dir: # 如果有子目录
|
||||
new_rel_path = os.path.join(file_dir, new_file_name)
|
||||
else:
|
||||
new_rel_path = new_file_name
|
||||
|
||||
# 构建本地完整路径
|
||||
local_path = os.path.join(self.local_path, new_rel_path)
|
||||
|
||||
# 创建必要的目录
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
# 下载文件
|
||||
self.oss_client.get_object_to_file(obj_key, local_path)
|
||||
|
||||
if file_ext == '.obj': # 10MB以上
|
||||
try:
|
||||
# 使用临时文件避免内存问题 [8](@ref)
|
||||
temp_path = local_path + '.tmp'
|
||||
with open(local_path, 'r', encoding='utf-8') as f_in, \
|
||||
open(temp_path, 'w', encoding='utf-8') as f_out:
|
||||
|
||||
mtllib_modified = False
|
||||
for line in f_in:
|
||||
if not mtllib_modified and line.strip().startswith('mtllib '):
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_mtl_name = parts[1].strip()
|
||||
new_mtl_name = f"{batch_model_info.order_id}_{old_mtl_name}"
|
||||
f_out.write(f"mtllib {new_mtl_name}\n")
|
||||
mtllib_modified = True
|
||||
print("len(parts) > 1")
|
||||
continue
|
||||
f_out.write(line)
|
||||
|
||||
os.replace(temp_path, local_path) # 原子性替换
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理大文件 {local_path} 时出错: {e}")
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
|
||||
# 优化后的.obj文件处理逻辑
|
||||
if file_ext == '.mtl':
|
||||
try:
|
||||
# 使用更高效的文件读取方式 [6,8](@ref)
|
||||
with open(local_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 使用字符串方法直接查找和替换,避免不必要的循环 [9](@ref)
|
||||
lines = content.split('\n')
|
||||
mtllib_modified = False
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
stripped_line = line.strip()
|
||||
if not mtllib_modified and stripped_line.startswith('map_Kd '):
|
||||
# 更高效的分割方式 [9](@ref)
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_name = parts[1].strip()
|
||||
new_name = f"{batch_model_info.order_id}_{old_name}"
|
||||
lines[i] = f"map_Kd {new_name}"
|
||||
mtllib_modified = True
|
||||
print(f"已更新材质库引用: {old_name} -> {new_name}")
|
||||
break # 找到第一个后立即退出
|
||||
|
||||
# 批量写入,减少I/O操作 [6](@ref)
|
||||
with open(local_path, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理文件 {local_path} 时出错: {e}")
|
||||
except UnicodeDecodeError as e:
|
||||
print(f"文件编码错误 {local_path}: {e}")
|
||||
|
||||
print(f"下载文件: {obj_key} -> {local_path}")
|
||||
|
||||
return True
|
||||
|
||||
def upload_data(self):
|
||||
'''
|
||||
上传数据到OSS
|
||||
'''
|
||||
# 检测本地路径是否存在
|
||||
if not os.path.exists(self.local_path):
|
||||
raise FileNotFoundError(f"本地路径不存在: {self.local_path}")
|
||||
|
||||
# 判断本地路径是文件还是目录
|
||||
if os.path.isfile(self.local_path):
|
||||
local_suffix = Path(self.local_path).suffix
|
||||
oss_suffix = Path(self.oss_path).suffix
|
||||
|
||||
if oss_suffix and oss_suffix != local_suffix:
|
||||
# 后缀名不一致,上传到指定文件夹下的同名文件
|
||||
oss_dir = os.path.dirname(self.oss_path)
|
||||
oss_target_path = os.path.join(oss_dir, os.path.basename(self.local_path))
|
||||
else:
|
||||
# 后缀名一致,上传到指定OSS路径
|
||||
oss_target_path = self.oss_path
|
||||
|
||||
# 上传文件
|
||||
self.oss_client.put_object_from_file(oss_target_path, self.local_path)
|
||||
|
||||
print(f"文件已上传到: {oss_target_path}")
|
||||
|
||||
elif os.path.isdir(self.local_path):
|
||||
oss_suffix = Path(self.oss_path).suffix
|
||||
if oss_suffix:
|
||||
raise ValueError("不能将目录上传到具有后缀名的OSS路径。")
|
||||
|
||||
# 遍历本地目录并上传
|
||||
for root, dirs, files in os.walk(self.local_path):
|
||||
for file in files:
|
||||
local_file_path = os.path.join(root, file)
|
||||
relative_path = os.path.relpath(local_file_path, self.local_path)
|
||||
oss_file_path = os.path.join(self.oss_path, relative_path).replace("\\", "/")
|
||||
|
||||
# 创建必要的目录
|
||||
oss_dir = os.path.dirname(oss_file_path)
|
||||
|
||||
# 上传文件
|
||||
self.oss_client.put_object_from_file(oss_file_path, local_file_path)
|
||||
print(f"文件已上传到: {oss_file_path}")
|
||||
else:
|
||||
raise ValueError(f"无效的本地路径类型: {self.local_path}")
|
||||
from download_print_out import DataTransfer
|
||||
from download_print_out import download_data_by_json
|
||||
|
||||
import requests
|
||||
import json
|
||||
import shutil
|
||||
|
||||
from dataclasses import dataclass
|
||||
@dataclass
|
||||
class JSONModelInfo:
|
||||
obj_name: str
|
||||
order_id: str
|
||||
pid: str
|
||||
model_height: str
|
||||
|
||||
def read_pids_from_json(pid_file):
|
||||
"""从文件读取所有PID"""
|
||||
# with open(pid_file, 'r') as f:
|
||||
# # 过滤掉空行并去除每行首尾的空白字符
|
||||
# return [line.strip() for line in f if line.strip()]
|
||||
|
||||
json_path = pid_file
|
||||
|
||||
"""
|
||||
加载JSON文件,读取所有模型信息,应用变换后返回模型列表
|
||||
"""
|
||||
# 检查JSON文件是否存在
|
||||
if not os.path.exists(json_path):
|
||||
print(f"错误: JSON文件不存在 - {json_path}")
|
||||
return []
|
||||
|
||||
# 读取JSON文件
|
||||
try:
|
||||
with open(json_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f"读取JSON文件失败: {e}")
|
||||
return []
|
||||
|
||||
list_model_info = []
|
||||
# 处理每个模型
|
||||
for model in data.get('models', []):
|
||||
obj_name = model.get('file_name', '')
|
||||
|
||||
parts = obj_name.split('_')
|
||||
|
||||
order_id = parts[0]
|
||||
pid = parts[1]
|
||||
model_height = parts[3]
|
||||
|
||||
model_info = JSONModelInfo(
|
||||
obj_name=obj_name,
|
||||
order_id=order_id,
|
||||
pid=pid,
|
||||
model_height=model_height
|
||||
)
|
||||
list_model_info.append(model_info)
|
||||
|
||||
return list_model_info, data
|
||||
|
||||
def download_data_by_json(model_info, workdir, oss_client ):
|
||||
try:
|
||||
pid = model_info.pid
|
||||
model_height = model_info.model_height
|
||||
target_dir = f"{workdir}"
|
||||
|
||||
url = f"{url_get_oss_suffix_by_orderId}{model_info.order_id}"
|
||||
res = requests.get(url)
|
||||
|
||||
data = res.json()["data"]
|
||||
# print("datas=",data)
|
||||
data = data.replace("/init_obj", "")
|
||||
|
||||
print("target_dir=", target_dir)
|
||||
# download_textures = DataTransfer(target_dir, f"objs/download/print/{pid}/base/model/{model_height}/", oss_client)
|
||||
# download_textures = DataTransfer(target_dir, f"objs/download/print/{pid}/base_cartoon/badge/101/3/{model_height}/", oss_client)
|
||||
download_textures = DataTransfer(target_dir, f"objs/download/print/{pid}/{data}/{model_height}/", oss_client)
|
||||
|
||||
download_textures.download_data_rename_json(model_info)
|
||||
# 下载后检查目标文件夹是否为空
|
||||
if os.path.exists(target_dir) and not os.listdir(target_dir):
|
||||
shutil.rmtree(target_dir)
|
||||
print(f"下载后检查发现目标文件夹为空,已删除: {target_dir}")
|
||||
except Exception as e:
|
||||
print(f"卡通图片下载失败: {pid}, 错误: {str(e)}")
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class BatchModelInfo:
|
||||
@@ -461,8 +37,8 @@ class BatchModelInfo:
|
||||
count: str
|
||||
|
||||
def read_paths_from_batch(batch_id):
|
||||
url = f"https://mp.api.suwa3d.com/api/printOrder/getInfoByPrintBatchId?batch_id={batch_id}"
|
||||
res = requests.get(url)
|
||||
|
||||
res = requests.get(f"{url_get_info_by_print_batch_id}{batch_id}")
|
||||
|
||||
datas = res.json()["data"]
|
||||
print("datas=",datas)
|
||||
@@ -528,35 +104,19 @@ def download_datas_by_pre_layout(list_print_model_info, workdir, oss_config):
|
||||
return False
|
||||
return True
|
||||
|
||||
def download_transform_save_by_batch(batch_id, workdir, oss_config):
|
||||
datas, succ = download_datas_by_batch(batch_id, workdir, oss_config)
|
||||
print("datas=", datas)
|
||||
layout_data = datas["layout_data"]
|
||||
|
||||
original_obj_pid_dir = workdir
|
||||
|
||||
transform_save_o3d(layout_data, original_obj_pid_dir)
|
||||
|
||||
def download_datas_by_json(json_name, workdir, oss_config):
|
||||
oss_client = get_oss_client(oss_config)
|
||||
|
||||
#json_path = os.path.join(workdir, "3DPrintLayout.json")
|
||||
json_path = os.path.join(workdir, f"{json_name}.json")
|
||||
|
||||
# 读取所有PID
|
||||
list_model_info, data = read_pids_from_json(json_path)
|
||||
print(f"从文件读取了 {len(list_model_info)} 个PID")
|
||||
list_model_info, json_data = read_models_from_json(json_path)
|
||||
print(f"从文件读取了 {len(list_model_info)} 个model")
|
||||
# 批量下载
|
||||
for model_info in list_model_info:
|
||||
print(f"开始下载PID: {model_info}")
|
||||
download_data_by_json(model_info, workdir, oss_client)
|
||||
|
||||
return data
|
||||
|
||||
def download_transform_save_by_json(json_name, workdir, oss_config):
|
||||
layout_data = download_datas_by_json(json_name, workdir, oss_config)
|
||||
original_obj_pid_dir = workdir
|
||||
transform_save_bpy(layout_data, original_obj_pid_dir)
|
||||
return json_data
|
||||
|
||||
def upload_result(base_original_obj_dir, oss_config, batch_id):
|
||||
|
||||
@@ -580,13 +140,10 @@ def upload_result(base_original_obj_dir, oss_config, batch_id):
|
||||
print(f"失败: {batch_id}, 错误: {str(e)}")
|
||||
pass
|
||||
|
||||
import open3d as o3d
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
is_by_batch = True
|
||||
is_transform_save = False
|
||||
is_by_batch = False
|
||||
batch_id = 10118
|
||||
if is_by_batch:
|
||||
# 通过batch_id下载
|
||||
@@ -599,11 +156,11 @@ if __name__ == "__main__":
|
||||
|
||||
workdir = f"{print_data_dir}{batch_id}"
|
||||
|
||||
is_transform_save = False
|
||||
datas, succ = download_datas_by_batch(batch_id, workdir, oss_config)
|
||||
if is_transform_save:
|
||||
download_transform_save_by_batch(batch_id, workdir, oss_config)
|
||||
else:
|
||||
download_datas_by_batch(batch_id, workdir, oss_config)
|
||||
|
||||
layout_data = datas["layout_data"]
|
||||
transform_save_bpy(layout_data, workdir)
|
||||
else:
|
||||
# 通过Json下载
|
||||
|
||||
@@ -617,7 +174,6 @@ if __name__ == "__main__":
|
||||
|
||||
json_name = batch_id
|
||||
|
||||
if is_transform_save:
|
||||
download_transform_save_by_json(json_name, workdir, oss_config)
|
||||
else:
|
||||
download_datas_by_json(json_name, workdir, oss_config)
|
||||
json_data = download_datas_by_json(json_name, workdir, oss_config)
|
||||
if is_small_machine(json_data):
|
||||
transform_save_bpy(json_data, workdir)
|
||||
+237
-59
@@ -5,10 +5,12 @@ import os
|
||||
import numpy as np
|
||||
import os
|
||||
import argparse
|
||||
import bpy
|
||||
# import bpy
|
||||
import sys
|
||||
import open3d as o3d
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
import json
|
||||
import shutil
|
||||
@@ -16,6 +18,7 @@ import shutil
|
||||
from config import url_get_oss_suffix_by_orderId
|
||||
|
||||
from general import transform_save_bpy
|
||||
from general import read_models_from_json
|
||||
|
||||
from compute_print_net import get_oss_client
|
||||
|
||||
@@ -37,6 +40,46 @@ class DataTransfer:
|
||||
self.local_path = local_path
|
||||
self.oss_path = oss_path.lstrip('/')
|
||||
self.oss_client = oss_client
|
||||
# self.description = description
|
||||
|
||||
# @log_execution(self.description)
|
||||
def download_data(self):
|
||||
"""
|
||||
从 OSS 下载数据到本地,保持原有目录结构
|
||||
"""
|
||||
|
||||
# 列出所有对象
|
||||
objects = []
|
||||
prefix = self.oss_path.lstrip('/') # 移除开头的 '/' 以匹配 OSS 格式
|
||||
|
||||
for obj in oss2.ObjectIterator(self.oss_client, prefix=prefix):
|
||||
if obj.key != prefix: # 跳过目录本身
|
||||
objects.append(obj.key)
|
||||
|
||||
# 下载所有文件,添加进度条
|
||||
for obj_key in tqdm(objects, desc="下载进度"):
|
||||
if obj_key.endswith('/'):
|
||||
continue
|
||||
|
||||
if "printId" in obj_key:
|
||||
continue
|
||||
|
||||
# 计算相对路径
|
||||
rel_path = obj_key[len(prefix):].lstrip('/')
|
||||
# 构建本地完整路径
|
||||
local_path = os.path.join(self.local_path, rel_path)
|
||||
|
||||
# 创建必要的目录
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
# 下载文件
|
||||
self.oss_client.get_object_to_file(obj_key, local_path)
|
||||
|
||||
print("download_data local_path=" + local_path)
|
||||
|
||||
order_id: str
|
||||
pid: str
|
||||
model_height: str
|
||||
|
||||
def download_data_rename_json(self, json_model_info):
|
||||
"""
|
||||
@@ -154,6 +197,197 @@ class DataTransfer:
|
||||
|
||||
print(f"下载文件: {obj_key} -> {local_path}")
|
||||
|
||||
def download_data_rename_batch(self, batch_model_info):
|
||||
"""
|
||||
从 OSS 下载数据到本地,保持原有目录结构
|
||||
"""
|
||||
|
||||
# 列出所有对象
|
||||
objects = []
|
||||
prefix = self.oss_path.lstrip('/') # 移除开头的 '/' 以匹配 OSS 格式
|
||||
|
||||
prefix_exists = False
|
||||
|
||||
for obj in oss2.ObjectIterator(self.oss_client, prefix=prefix):
|
||||
prefix_exists = True
|
||||
if obj.key != prefix: # 跳过目录本身
|
||||
objects.append(obj.key)
|
||||
print(f"obj.key={obj.key}")
|
||||
|
||||
if not prefix_exists:
|
||||
print(f"前缀 '{prefix}' 下没有找到任何文件或目录。")
|
||||
return False
|
||||
else:
|
||||
print(f"前缀 '{prefix}' 存在,共找到 {len(objects)} 个对象。")
|
||||
|
||||
# 下载所有文件,添加进度条
|
||||
for obj_key in tqdm(objects, desc="下载进度"):
|
||||
if obj_key.endswith('/'):
|
||||
print("下载 endswith('/'")
|
||||
continue
|
||||
|
||||
if "printId" in obj_key:
|
||||
print(f"下载 in obj_key")
|
||||
continue
|
||||
|
||||
# 计算相对路径
|
||||
rel_path = obj_key[len(prefix):].lstrip('/')
|
||||
|
||||
file_dir, file_name = os.path.split(rel_path)
|
||||
file_base, file_ext = os.path.splitext(file_name)
|
||||
|
||||
# 根据文件后缀名进行重命名
|
||||
if file_ext.lower() in ['.mtl', '.jpg', '.jpeg', '.png']:
|
||||
# 对于.mtl和图片文件,在原名前加order_id
|
||||
new_file_name = f"{batch_model_info.order_id}_{file_name}"
|
||||
# new_file_name = file_name
|
||||
elif file_ext.lower() == '.obj':
|
||||
# 对于.obj文件,完全重命名
|
||||
new_file_name = f"{batch_model_info.order_id}_{batch_model_info.pid}_P{batch_model_info.print_order_id}_{batch_model_info.model_size}{file_ext}"
|
||||
else:
|
||||
# 其他文件类型保持原名
|
||||
new_file_name = file_name
|
||||
|
||||
# 构建新的相对路径
|
||||
if file_dir: # 如果有子目录
|
||||
new_rel_path = os.path.join(file_dir, new_file_name)
|
||||
else:
|
||||
new_rel_path = new_file_name
|
||||
|
||||
# 构建本地完整路径
|
||||
local_path = os.path.join(self.local_path, new_rel_path)
|
||||
|
||||
# 创建必要的目录
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
# 下载文件
|
||||
self.oss_client.get_object_to_file(obj_key, local_path)
|
||||
|
||||
if file_ext == '.obj': # 10MB以上
|
||||
try:
|
||||
# 使用临时文件避免内存问题 [8](@ref)
|
||||
temp_path = local_path + '.tmp'
|
||||
with open(local_path, 'r', encoding='utf-8') as f_in, \
|
||||
open(temp_path, 'w', encoding='utf-8') as f_out:
|
||||
|
||||
mtllib_modified = False
|
||||
for line in f_in:
|
||||
if not mtllib_modified and line.strip().startswith('mtllib '):
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_mtl_name = parts[1].strip()
|
||||
new_mtl_name = f"{batch_model_info.order_id}_{old_mtl_name}"
|
||||
f_out.write(f"mtllib {new_mtl_name}\n")
|
||||
mtllib_modified = True
|
||||
print("len(parts) > 1")
|
||||
continue
|
||||
f_out.write(line)
|
||||
|
||||
os.replace(temp_path, local_path) # 原子性替换
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理大文件 {local_path} 时出错: {e}")
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
|
||||
# 优化后的.obj文件处理逻辑
|
||||
if file_ext == '.mtl':
|
||||
try:
|
||||
# 使用更高效的文件读取方式 [6,8](@ref)
|
||||
with open(local_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 使用字符串方法直接查找和替换,避免不必要的循环 [9](@ref)
|
||||
lines = content.split('\n')
|
||||
mtllib_modified = False
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
stripped_line = line.strip()
|
||||
if not mtllib_modified and stripped_line.startswith('map_Kd '):
|
||||
# 更高效的分割方式 [9](@ref)
|
||||
parts = line.split(' ', 1)
|
||||
if len(parts) > 1:
|
||||
old_name = parts[1].strip()
|
||||
new_name = f"{batch_model_info.order_id}_{old_name}"
|
||||
lines[i] = f"map_Kd {new_name}"
|
||||
mtllib_modified = True
|
||||
print(f"已更新材质库引用: {old_name} -> {new_name}")
|
||||
break # 找到第一个后立即退出
|
||||
|
||||
# 批量写入,减少I/O操作 [6](@ref)
|
||||
with open(local_path, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
except IOError as e:
|
||||
print(f"处理文件 {local_path} 时出错: {e}")
|
||||
except UnicodeDecodeError as e:
|
||||
print(f"文件编码错误 {local_path}: {e}")
|
||||
|
||||
print(f"下载文件: {obj_key} -> {local_path}")
|
||||
|
||||
return True
|
||||
|
||||
def download_single_file(self):
|
||||
"""
|
||||
下载单个文件从OSS到本地
|
||||
"""
|
||||
# 确保本地目录存在
|
||||
os.makedirs(os.path.dirname(self.local_path), exist_ok=True)
|
||||
|
||||
# 直接下载文件
|
||||
try:
|
||||
self.oss_client.get_object_to_file(self.oss_path, self.local_path)
|
||||
print(f"文件已下载到: {self.local_path}")
|
||||
except oss2.exceptions.NoSuchKey:
|
||||
print(f"OSS文件不存在: {self.oss_path}")
|
||||
|
||||
def upload_data(self):
|
||||
'''
|
||||
上传数据到OSS
|
||||
'''
|
||||
# 检测本地路径是否存在
|
||||
if not os.path.exists(self.local_path):
|
||||
raise FileNotFoundError(f"本地路径不存在: {self.local_path}")
|
||||
|
||||
# 判断本地路径是文件还是目录
|
||||
if os.path.isfile(self.local_path):
|
||||
local_suffix = Path(self.local_path).suffix
|
||||
oss_suffix = Path(self.oss_path).suffix
|
||||
|
||||
if oss_suffix and oss_suffix != local_suffix:
|
||||
# 后缀名不一致,上传到指定文件夹下的同名文件
|
||||
oss_dir = os.path.dirname(self.oss_path)
|
||||
oss_target_path = os.path.join(oss_dir, os.path.basename(self.local_path))
|
||||
else:
|
||||
# 后缀名一致,上传到指定OSS路径
|
||||
oss_target_path = self.oss_path
|
||||
|
||||
# 上传文件
|
||||
self.oss_client.put_object_from_file(oss_target_path, self.local_path)
|
||||
|
||||
print(f"文件已上传到: {oss_target_path}")
|
||||
|
||||
elif os.path.isdir(self.local_path):
|
||||
oss_suffix = Path(self.oss_path).suffix
|
||||
if oss_suffix:
|
||||
raise ValueError("不能将目录上传到具有后缀名的OSS路径。")
|
||||
|
||||
# 遍历本地目录并上传
|
||||
for root, dirs, files in os.walk(self.local_path):
|
||||
for file in files:
|
||||
local_file_path = os.path.join(root, file)
|
||||
relative_path = os.path.relpath(local_file_path, self.local_path)
|
||||
oss_file_path = os.path.join(self.oss_path, relative_path).replace("\\", "/")
|
||||
|
||||
# 创建必要的目录
|
||||
oss_dir = os.path.dirname(oss_file_path)
|
||||
|
||||
# 上传文件
|
||||
self.oss_client.put_object_from_file(oss_file_path, local_file_path)
|
||||
print(f"文件已上传到: {oss_file_path}")
|
||||
else:
|
||||
raise ValueError(f"无效的本地路径类型: {self.local_path}")
|
||||
|
||||
def get_api(url):
|
||||
try:
|
||||
response = requests.get(url)
|
||||
@@ -166,61 +400,6 @@ def get_api(url):
|
||||
except requests.exceptions.RequestException as e:
|
||||
raise Exception(f"Error fetching URL {url}: {e}")
|
||||
|
||||
from dataclasses import dataclass
|
||||
@dataclass
|
||||
class JSONModelInfo:
|
||||
obj_name: str
|
||||
order_id: str
|
||||
pid: str
|
||||
print_order_id: str
|
||||
model_height: str
|
||||
|
||||
def read_pids_from_json(pid_file):
|
||||
"""从文件读取所有PID"""
|
||||
|
||||
json_path = pid_file
|
||||
|
||||
"""
|
||||
加载JSON文件,读取所有模型信息,应用变换后返回模型列表
|
||||
"""
|
||||
# 检查JSON文件是否存在
|
||||
if not os.path.exists(json_path):
|
||||
print(f"错误: JSON文件不存在 - {json_path}")
|
||||
return []
|
||||
|
||||
# 读取JSON文件
|
||||
try:
|
||||
with open(json_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f"读取JSON文件失败: {e}")
|
||||
return []
|
||||
|
||||
list_model_info = []
|
||||
# 处理每个模型
|
||||
for model in data.get('models', []):
|
||||
obj_name = model.get('file_name', '')
|
||||
|
||||
parts = obj_name.split('_')
|
||||
|
||||
order_id = parts[0]
|
||||
pid = parts[1]
|
||||
print_order_id = parts[2]
|
||||
print_order_id = print_order_id.replace("P", "")
|
||||
model_height = parts[3]
|
||||
|
||||
model_info = JSONModelInfo(
|
||||
obj_name=obj_name,
|
||||
order_id=order_id,
|
||||
pid=pid,
|
||||
print_order_id=print_order_id,
|
||||
model_height=model_height
|
||||
)
|
||||
list_model_info.append(model_info)
|
||||
print(f"model_info={model_info}")
|
||||
|
||||
return list_model_info, data
|
||||
|
||||
def download_data_by_json(model_info, workdir, oss_client ):
|
||||
try:
|
||||
pid = model_info.pid
|
||||
@@ -249,18 +428,17 @@ def download_data_by_json(model_info, workdir, oss_client ):
|
||||
def download_datas_by_json(pid_file, workdir, oss_config):
|
||||
oss_client = get_oss_client(oss_config)
|
||||
|
||||
# json_path = os.path.join(workdir, "3DPrintLayout.json")
|
||||
json_path = os.path.join(workdir, f"{pid_file}.json")
|
||||
|
||||
# 读取所有PID
|
||||
list_model_info, data = read_pids_from_json(json_path)
|
||||
list_model_info, json_data = read_models_from_json(json_path)
|
||||
print(f"从文件读取了 {len(list_model_info)} 个PID")
|
||||
# 批量下载
|
||||
for model_info in list_model_info:
|
||||
print(f"开始下载PID: {model_info}")
|
||||
download_data_by_json(model_info, args.workdir, oss_client)
|
||||
|
||||
return data
|
||||
return json_data
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
+66
@@ -218,3 +218,69 @@ def is_cross_border_c(x, y, z, mx, my, mz, max_x, max_y, max_z):
|
||||
return False
|
||||
|
||||
# -------------------------- 结束:碰撞检测和越界 --------------------------
|
||||
|
||||
# -------------------------- 开始:JSON --------------------------
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class JSONModelInfo:
|
||||
obj_name: str
|
||||
order_id: str
|
||||
pid: str
|
||||
print_order_id: str
|
||||
model_height: str
|
||||
|
||||
def read_from_json(json_path):
|
||||
|
||||
if not os.path.exists(json_path):
|
||||
print(f"错误: JSON文件不存在 - {json_path}")
|
||||
return []
|
||||
|
||||
try:
|
||||
with open(json_path, 'r') as f:
|
||||
json_data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f"读取JSON文件失败: {e}")
|
||||
return []
|
||||
|
||||
return json_data
|
||||
|
||||
def read_models_from_json(json_path):
|
||||
|
||||
json_data = read_from_json(json_path)
|
||||
|
||||
list_model_info = []
|
||||
# 处理每个模型
|
||||
for model in json_data.get('models', []):
|
||||
obj_name = model.get('file_name', '')
|
||||
|
||||
parts = obj_name.split('_')
|
||||
|
||||
order_id = parts[0]
|
||||
pid = parts[1]
|
||||
model_height = parts[3]
|
||||
|
||||
model_info = JSONModelInfo(
|
||||
obj_name=obj_name,
|
||||
order_id=order_id,
|
||||
pid=pid,
|
||||
model_height=model_height
|
||||
)
|
||||
list_model_info.append(model_info)
|
||||
|
||||
return list_model_info, json_data
|
||||
|
||||
def get_summary(json_data):
|
||||
return json_data.get('summary')
|
||||
|
||||
def get_selected_machine(json_data):
|
||||
return get_summary(json_data)['selected_machine']
|
||||
|
||||
def is_small_machine(json_data):
|
||||
selected_machine = get_selected_machine(json_data)
|
||||
is_small_machine = True if selected_machine=="小机型" else False
|
||||
return is_small_machine
|
||||
|
||||
# -------------------------- 结束:JSON --------------------------
|
||||
@@ -8,6 +8,7 @@ import gc
|
||||
|
||||
from config import print_data_dir
|
||||
from config import test_print_max
|
||||
from config import version
|
||||
|
||||
from general import mesh_transform_by_matrix
|
||||
from general import get_blank_path
|
||||
@@ -425,6 +426,8 @@ def set_orthographic(meshes, width=1920, height=1080,
|
||||
|
||||
return vis
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
def render_to_texture(meshes, output_image_path):
|
||||
|
||||
vis = set_orthographic(meshes)
|
||||
@@ -432,6 +435,49 @@ def render_to_texture(meshes, output_image_path):
|
||||
# 渲染并保存
|
||||
vis.capture_screen_image(output_image_path, do_render=True)
|
||||
|
||||
text = f"v {version}" # 使用PIL添加文字
|
||||
try:
|
||||
image = Image.open(output_image_path)
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
font = ImageFont.load_default()
|
||||
|
||||
font_families = [
|
||||
'DejaVu Sans', # 许多 Linux 发行版的标准配置[2,5](@ref)
|
||||
'Liberation Sans', # 作为 Arial 等字体的开源替代,预装可能性高[1](@ref)
|
||||
'Ubuntu', # Ubuntu 系统默认字体之一[3,5](@ref)
|
||||
'FreeSans', # 另一个开源无衬线字体
|
||||
'Source Sans Pro' # 一款清晰易读的开源字体
|
||||
]
|
||||
|
||||
for font_family in font_families:
|
||||
try:
|
||||
font = ImageFont.truetype(font_family, 30)
|
||||
break
|
||||
except IOError:
|
||||
continue
|
||||
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
text_width = bbox[2] - bbox[0]
|
||||
text_height = bbox[3] - bbox[1]
|
||||
|
||||
# 设置位置:左下角,左边距50像素,下边距10像素[1,3](@ref)
|
||||
width, height = image.size
|
||||
x = 50 # 左边距
|
||||
y = height - text_height - 50 # 图片高度减去文字高度再减去10像素边距
|
||||
|
||||
fill_color = (255, 0, 0)
|
||||
|
||||
# 添加文字
|
||||
draw.text((x, y), text, fill=fill_color, font=font)
|
||||
|
||||
# 保存带文字的图片
|
||||
image.save(output_image_path)
|
||||
print(f"带文字的渲染图片已保存到: {output_image_path}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"添加文字时出错: {e}")
|
||||
|
||||
print(f"高级渲染图片已保存到: {output_image_path}")
|
||||
|
||||
return vis
|
||||
|
||||
Reference in new issue
Block a user