From a2d4f72133da46079ee2c24f6fb803c1008216d6 Mon Sep 17 00:00:00 2001 From: mingxiangyu Date: Mon, 19 Jun 2023 10:10:47 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...37\346\210\220\347\273\223\346\236\234.py" | 3 + ...210\220Module4\347\273\223\346\236\234.py" | 140 +++++++++++++++++- ...37\346\210\220\347\273\223\346\236\234.py" | 30 ++-- ...255\230\345\202\250\345\210\260MongoDB.py" | 8 + 4 files changed, 164 insertions(+), 17 deletions(-) diff --git "a/detection/test-\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" "b/detection/test-\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" index 6f42cc1..5440ca3 100644 --- "a/detection/test-\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" +++ "b/detection/test-\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" @@ -160,6 +160,7 @@ def clean_data(): curve_list = layer_value.get("curve") # 将起始深度当做查询参数进行 label 查询 + # toDo 需要修改,是大于等于还是大于 query = {'StartDepth': {'$gte': l1_start}, "EndDepth": {'$lte': l1_end}} Depth = label_collection.find(query) label_depth_list = list(Depth[:]) @@ -192,6 +193,7 @@ def clean_data(): if label_start > layer_old_endDepth: n_label_label = "N" # 获取las文件中起始深度为 layer_old_endDepth ,label_start 的所有行数据 + # toDo 需要修改,是大于等于还是大于 n_query = {'Depth': {'$gte': layer_old_endDepth, '$lte': label_start}} n_Depth = lascurve_collection.find(n_query) n_Depth_list = [doc for doc in n_Depth] @@ -238,6 +240,7 @@ def clean_data(): label_item_start_end[label_label].append(label_start_end) # 获取las文件中起始深度为 StartDepth ,EndDepth 的所有行数据 + # toDo 需要修改,是大于等于还是大于 query = {'Depth': {'$gte': label_start, '$lte': label_end}} Depth = lascurve_collection.find(query) diff --git "a/detection/\347\224\237\346\210\220Module4\347\273\223\346\236\234.py" "b/detection/\347\224\237\346\210\220Module4\347\273\223\346\236\234.py" index 9356038..6117d01 100644 --- "a/detection/\347\224\237\346\210\220Module4\347\273\223\346\236\234.py" +++ "b/detection/\347\224\237\346\210\220Module4\347\273\223\346\236\234.py" @@ -7,6 +7,8 @@ # @File : test.py # 上一条label的截止深度 +import csv + from pymongo import MongoClient # 连接 MongoDB 数据库 @@ -26,6 +28,10 @@ db = client["mydatabase"] # 获取label(标签表)数据 label_collection = db['label'] +# 获取管道规范数据 +PipeSpecifications_collection = db['PipeSpecificationsMaster'] +# 获取公式计算结果 +calculate_collection = db['Calculate'] # toDo 井构表数据,待放入库中,从库中查询 l = {"type": 3, "start": 4.0667, "end": 897, @@ -43,7 +49,7 @@ layer = [l, l1, l2] -def test(): +def clean_data(): data = [] # 定义一个全局的结束参数,用来获取 N(管节) 的起始值 old_EndDepth = 0 @@ -64,7 +70,8 @@ def test(): # 定义一个字典,存储当前 layer 下所有 curve(Channel) 的数据 channel_itme = {} - label_item_start_end = {} + # 定义一个字典,存储当前 layer 下所有 curve(Channel) 的起始数据 + label_start_end_item = {} # 循环曲线参数 for curve_item in curve_list: @@ -80,6 +87,8 @@ def test(): if curve_type == 1: # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的数据<标签:数据集合> label_item = {} + # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的起始数据 + label_item_start_end = {} # 循环 label 结果 for lable_depth in label_depth_list: label_label = lable_depth.get("Label") @@ -111,11 +120,15 @@ def test(): # 更新上一条Label的截止深度 layer_old_endDepth = label_end channel_itme[curve_name] = label_item + label_start_end_item[curve_name] = label_item_start_end # 根据不同类型曲线,获取不同的N if curve_type == 2: # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的数据<标签:数据集合> label_item = {} + # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的起始数据 + label_item_start_end = {} + # 循环 label 结果 for lable_depth in label_depth_list: label_label = lable_depth.get("Label") @@ -148,11 +161,15 @@ def test(): layer_old_endDepth = label_end channel_itme[curve_name] = label_item + label_start_end_item[curve_name] = label_item_start_end # 根据不同类型曲线,获取不同的N if curve_type == 3: # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的数据<标签:数据集合> label_item = {} + # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的起始数据 + label_item_start_end = {} + # 循环 label 结果 for lable_depth in label_depth_list: label_label = lable_depth.get("Label") @@ -185,11 +202,122 @@ def test(): layer_old_endDepth = label_end channel_itme[curve_name] = label_item + label_start_end_item[curve_name] = label_item_start_end - print(label_item_start_end) + print(label_start_end_item) print("\n") old_EndDepth = layer_old_endDepth - - -test() + # 当前井构(L1)下所有标签的集合 + layer_item = [] + # 重新组装数据结构 + for channel, channel_value in channel_itme.items(): + channel_w = None + channel_v = None + curve_type = None + for curve_item in curve_list: + if channel == curve_item.get('Channel'): + channel_w = curve_item.get("W") + channel_v = curve_item.get("V") + curve_type = curve_item.get("curve_type") + break + + channel_start_end = { + "layer": l1_type, + "channel_name": channel, + "curve_type": curve_type, + "W": channel_w, + "V": channel_v + } + # 如果该 channel(曲线) 是空的,则直接对data复制为空 + if channel: + label_item_start_end = label_start_end_item.get(channel) + start_end_get = label_item_start_end.get("N") + channel_start_end["channel_data"] = start_end_get + layer_item.append(channel_start_end) + + layer_data = { + "layer_start": l1_start, + "layer_end": l1_end, + "layer_type": l1_type, + "layer_item": layer_item + } + data.append(layer_data) + return data + + +data = clean_data() + + +def rebuild_data(data): + # 重新组装数据,key为 channelType,value为对应的起始值集合 + channel_start_end = {} + for layer in data: + layer_item = layer.get("layer_item") + for layer_item_data in layer_item: + layer_item_start_end_list = layer_item_data.get("channel_data") + + # 如果起始数据集合为空,则直接跳过 + if not layer_item_start_end_list: + continue + + curve_type = layer_item_data.get("curve_type") + # 将当前 n_label 的起始值记录下 + start_end = channel_start_end.get(curve_type) + if start_end: + channel_start_end[curve_type].extend(layer_item_start_end_list) + else: + channel_start_end[curve_type] = [] + channel_start_end[curve_type].extend(layer_item_start_end_list) + return channel_start_end + + +rebuild_data = rebuild_data(data) + + +def write_data(rebuild_data): + for channel_start_end_key in rebuild_data: + print(channel_start_end_key) + start_end = rebuild_data.get(channel_start_end_key) + + row = [] + for start_end_item in start_end: + top = start_end_item.get("label_start") + bottom = start_end_item.get("label_end") + length = bottom - top + # toDo 后续传输进来 + nom_od = 9.625 + weight = 40 + + PipeSpecifications_query = {'OD Ins': {'$eq': nom_od}, "Weight (lb/ft)": {'$eq': weight}} + PipeSpecifications = PipeSpecifications_collection.find(PipeSpecifications_query) + PipeSpecifications = list(PipeSpecifications) + PipeSpecifications = PipeSpecifications[0] + + thickness = PipeSpecifications.get("Wall Thickness") + + # toDo 需要修改,是大于等于还是大于 + calculate_query = {'Depth': {'$gte': top, '$lte': bottom}} + calculate_list = calculate_collection.find(calculate_query) + collection_list = list(calculate_list) + + if channel_start_end_key == 1: + collection_list.sort(key=lambda p: p.Curve1) + if channel_start_end_key == 2: + collection_list.sort(key=lambda p: p.Curve2) + if channel_start_end_key == 3: + collection_list.sort(key=lambda p: p.Curve3) + + print(collection_list) + + with open('Joint Analysis.csv', 'w', newline='') as f: + writer = csv.writer(f) + csv_h0eader = ["Depth", "Layer", "Lable", "Curve1", "Curve2", "Curve3"] + writer.writerow(csv_h0eader) + for i in range(len(row)): + writer.writerow([row_data for row_data in row[i]] ) + + # for layer_item_start_end in layer_item_start_end_list: + + +write_data(rebuild_data) diff --git "a/detection/\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" "b/detection/\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" index 3e1a008..b486150 100644 --- "a/detection/\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" +++ "b/detection/\350\256\241\347\256\227\345\205\254\345\274\217\345\271\266\347\224\237\346\210\220\347\273\223\346\236\234.py" @@ -19,15 +19,21 @@ # toDo 井构表数据,待放入库中,从库中查询 l = {"type": 3, "start": 4.0667, "end": 897, - "curve": [{"curve_type": 1, "Channel": "AD[15]", "W": 0.25, "V": -0.009}, - {"curve_type": 2, "Channel": "AD[38]", "W": 0.25, "V": -0.006}, - {"curve_type": 3, "Channel": "AD[54]", "W": 0.25, "V": -0.009}]} + "curve": [{"curve_type": 1, "Channel": "AD[15]", "W": 0.25, "V": -0.009, "LayerODin": 9.625, "LayerWtLbFt": 40, + "LayerNomThkin": 0.395}, + {"curve_type": 2, "Channel": "AD[38]", "W": 0.25, "V": -0.006, "LayerODin": 9.625, "LayerWtLbFt": 40, + "LayerNomThkin": 0.395}, + {"curve_type": 3, "Channel": "AD[54]", "W": 0.25, "V": -0.009, "LayerODin": 9.625, "LayerWtLbFt": 40, + "LayerNomThkin": 0.395}]} l1 = {"type": 2, "start": 897, "end": 4652.4, - "curve": [{"curve_type": 1, "Channel": "AD[15]", "W": 0.25, "V": -0.009}, - {"curve_type": 2, "Channel": "AD[38]", "W": 0.42, "V": -0.001}, + "curve": [{"curve_type": 1, "Channel": "AD[15]", "W": 0.25, "V": -0.009, "LayerODin": 13.375, "LayerWtLbFt": 72, + "LayerNomThkin": 0.514}, + {"curve_type": 2, "Channel": "AD[38]", "W": 0.42, "V": -0.001, "LayerODin": 13.375, "LayerWtLbFt": 72, + "LayerNomThkin": 0.514}, {"curve_type": 3, "Channel": None, "W": 1, "V": 0}]} l2 = {"type": 1, "start": 4652.4, "end": 5149.667, - "curve": [{"curve_type": 1, "Channel": "AD[25]", "W": 0.25, "V": -0.007}, + "curve": [{"curve_type": 1, "Channel": "AD[25]", "W": 0.25, "V": -0.007, "LayerODin": 18.625, "LayerWtLbFt": 115, + "LayerNomThkin": 0.594}, {"curve_type": 2, "Channel": None, "W": 1, "V": 0}, {"curve_type": 3, "Channel": None, "W": 1, "V": 0}]} layer = [l, l1, l2] @@ -156,6 +162,8 @@ def clean_data(): l1_type = layer_value.get("type") # 获取当前layer的曲线参数 curve_list = layer_value.get("curve") + # 获取管柱信息 + curve_list = layer_value.get("LayerODin") # 将起始深度当做查询参数进行 label 查询 query = {'StartDepth': {'$gte': l1_start}, "EndDepth": {'$lte': l1_end}} @@ -185,7 +193,7 @@ def clean_data(): # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的数据<标签:数据集合> label_item = {} # 定义一个字典,存储当前 layer 下当前 curve(Channel) 下所有标签和对应的起始数据 - label_item_start_end={} + label_item_start_end = {} # 循环 label 结果 for lable_depth in label_depth_list: label_label = lable_depth.get("Label") @@ -489,10 +497,10 @@ def curve_value_calculate(data, curve_depth, las_curve): # 获取当前 layer 中所有 label 标签集合 layer_item = layer_data.get("layer_item") - for layer_data in layer_item: - channel_data = layer_data.get('channel_data') - channel_w = layer_data.get('W') - channel_v = layer_data.get('V') + for layer_item_data in layer_item: + channel_data = layer_item_data.get('channel_data') + channel_w = layer_item_data.get('W') + channel_v = layer_item_data.get('V') # 因为下面计算可能用上所有均值,所以提前获取所有均值 n_jun, a_jun, b_jun, c_jun, e_jun = [0 for i in range(5)] diff --git "a/\345\260\206csv\345\255\230\345\202\250\345\210\260MongoDB.py" "b/\345\260\206csv\345\255\230\345\202\250\345\210\260MongoDB.py" index c8e572c..c00fee5 100644 --- "a/\345\260\206csv\345\255\230\345\202\250\345\210\260MongoDB.py" +++ "b/\345\260\206csv\345\255\230\345\202\250\345\210\260MongoDB.py" @@ -47,6 +47,14 @@ db = client["mydatabase"] # 标签表 collection = db['Calculate'] +# collection.insert_many(data_json) + + +df = pd.read_csv("G:\软件备份\Project\测井\项目所需\Case-3文件及说明\API_PipeSpecificationsMaster.csv", encoding='utf-8') +data_json = df.to_dict(orient='records') +db = client["mydatabase"] +# 标签表 +collection = db['PipeSpecificationsMaster'] collection.insert_many(data_json)