Skip to content

Commit

Permalink
更新代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingxiangyu committed Jul 6, 2023
1 parent eace2c4 commit 0e6f5b1
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 793 deletions.
19 changes: 19 additions & 0 deletions detection/pandas给csv添加表头.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- codeing = utf-8 -*-
# @Time :2023/7/6 10:54
# @Author :xming
# @Version :1.0
# @Descriptioon :
# @Link :
# @File : pandas给csv添加表头.py

import pandas as pd

# 读取 CSV 文件
layer_path= r"C:\Users\12074\Desktop\Case-11_layer.csv"
df = pd.read_csv(layer_path, header=[0])
# 添加表头 df.columns 赋值一个列表,指定了表头的名称
df.columns = ['start', 'end', 'LayerODin1', 'LayerWtLbFt1', 'LayerODin2', 'LayerWtLbFt2', 'LayerODin3', 'LayerWtLbFt3']

# 将带有表头的 DataFrame 写入 CSV 文件 index=False 参数,避免写入索引列
df.to_csv('data_with_header.csv', index=False)

184 changes: 0 additions & 184 deletions detection/test-计算公式并生成结果.py

This file was deleted.

33 changes: 33 additions & 0 deletions detection/删除文件内容.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- codeing = utf-8 -*-
# @Time :2023/7/5 16:27
# @Author :xming
# @Version :1.0
# @Descriptioon :
# @Link :
# @File : 删除文件内容.py
def remove_lines_with_stop_char(file_path, stop_char):
with open(file_path, 'r') as file:
lines = file.readlines()

output_lines = []
for line in lines:
if stop_char in line:
break
output_lines.append(line)

# 使用列表推导式过滤掉要移除的元素
result = [x for x in lines if x not in output_lines]
result[0] = result[0].replace("~A ", "")
print(result)

result = ''.join(result)

with open(file_path, 'w') as file:
file.write(result)


# 使用示例
file_path = r"C:\Users\12074\Desktop\Case-11_Raw_Data.las"
stop_char = '~A Depth'

remove_lines_with_stop_char(file_path, stop_char)
34 changes: 26 additions & 8 deletions detection/生成Module4结果-6-23.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# 获取label(标签表)数据
label_collection = db['label']
# 获取管道规范数据
PipeSpecifications_collection = db['PipeSpecificationsMaster']
PipeSpecifications_collection = db['pipe_specification']
# 获取公式计算结果
calculate_collection = db['Calculate']

Expand Down Expand Up @@ -409,6 +409,26 @@ def rebuild_data(data):
rebuild_data = rebuild_data(data)


def findByODinAndWt(layerODin, layerWtLbFt):
# 查询管柱规范信息 todo 如果尺寸不对,直接返回异常,不进行计算,如果重量不对,则基于该尺寸找最接近的重量
PipeSpecifications_query = {'OD Ins': {'$eq': layerODin}, "Weight (lb/ft)": {'$eq': layerWtLbFt}}
pipeSpecifications_list = PipeSpecifications_collection.find(PipeSpecifications_query)
pipeSpecifications_list = list(pipeSpecifications_list)
# 如果通过 尺寸 和 重量 查不到,则通过 尺寸 查询
if not pipeSpecifications_list:
PipeSpecifications_query = {'OD Ins': {'$eq': layerODin}}
pipeSpecifications_list = PipeSpecifications_collection.find(PipeSpecifications_query)
pipeSpecifications_list = list(pipeSpecifications_list)
if not pipeSpecifications_list:
# 如果通过 尺寸 无法查询到数据,则抛出异常,输入数据有误
raise ValueError('Input size does not exist.')
# 获取 重量 最接近的数据当做当前管柱
pipeSpecifications_data = min(pipeSpecifications_list,
key=lambda x: abs(x.get("Weight (lb/ft)") - layerODin))
else:
pipeSpecifications_data = pipeSpecifications_list[0]
return pipeSpecifications_data

def write_data(rebuild_data):
# 每一根管柱写一个表
for channel in rebuild_data:
Expand All @@ -417,15 +437,11 @@ def write_data(rebuild_data):
layerWtLbFt = channel.get("LayerWtLbFt")
start_end = channel.get("channel_data")

# 查询管柱规范信息 todo 如果尺寸不对,直接返回异常,不进行计算,如果重量不对,则基于该尺寸找最接近的重量
PipeSpecifications_query = {'OD Ins': {'$eq': layerODin}, "Weight (lb/ft)": {'$eq': layerWtLbFt}}
PipeSpecifications = PipeSpecifications_collection.find(PipeSpecifications_query)
PipeSpecifications = list(PipeSpecifications)
PipeSpecifications = PipeSpecifications[0]
pipeSpecifications_data = findByODinAndWt(layerODin, layerWtLbFt)

# 管柱信息
thickness_ins = PipeSpecifications.get("Wall Thickness ins")
thickness_mm = PipeSpecifications.get("Wall Thickness mm")
thickness_ins = pipeSpecifications_data.get("Wall Thickness ins")
thickness_mm = pipeSpecifications_data.get("Wall Thickness mm")

itemNO = 0
# 准备csv的数据
Expand Down Expand Up @@ -547,4 +563,6 @@ def write_data(rebuild_data):
writer.writerow([row_data for row_data in row[i]])




write_data(rebuild_data)
2 changes: 1 addition & 1 deletion detection/生成Module4结果.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# 获取label(标签表)数据
label_collection = db['label']
# 获取管道规范数据
PipeSpecifications_collection = db['PipeSpecificationsMaster']
PipeSpecifications_collection = db['pipe_specification']
# 获取公式计算结果
calculate_collection = db['Calculate']

Expand Down
27 changes: 26 additions & 1 deletion detection/计算公式并生成结果-6-19.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
label_collection = db['label']
# 获取数据表
collection = db['Calculate']
# 获取管道规范数据
PipeSpecifications_collection = db['pipe_specification']


def flatten_value(dic):
Expand Down Expand Up @@ -183,6 +185,27 @@ def getCalculate(layer_type, label_label, a_jun, b_jun, c_jun, e_jun, n_jun, w,
return calculate


def findByODinAndWt(layerODin, layerWtLbFt):
# 查询管柱规范信息 todo 如果尺寸不对,直接返回异常,不进行计算,如果重量不对,则基于该尺寸找最接近的重量
PipeSpecifications_query = {'OD Ins': {'$eq': layerODin}, "Weight (lb/ft)": {'$eq': layerWtLbFt}}
pipeSpecifications_list = PipeSpecifications_collection.find(PipeSpecifications_query)
pipeSpecifications_list = list(pipeSpecifications_list)
# 如果通过 尺寸 和 重量 查不到,则通过 尺寸 查询
if not pipeSpecifications_list:
PipeSpecifications_query = {'OD Ins': {'$eq': layerODin}}
pipeSpecifications_list = PipeSpecifications_collection.find(PipeSpecifications_query)
pipeSpecifications_list = list(pipeSpecifications_list)
if not pipeSpecifications_list:
# 如果通过 尺寸 无法查询到数据,则抛出异常,输入数据有误
raise ValueError('Input size does not exist.')
# 获取 重量 最接近的数据当做当前管柱
pipeSpecifications_data = min(pipeSpecifications_list,
key=lambda x: abs(x.get("Weight (lb/ft)") - layerODin))
else:
pipeSpecifications_data = pipeSpecifications_list[0]
return pipeSpecifications_data


def clean_data():
print("开始清洗数据")
data = []
Expand Down Expand Up @@ -601,9 +624,11 @@ def clean_data():
# 获取管柱信息
channel_w = curve_item.get("W")
channel_v = curve_item.get("V")
# 管柱信息
LayerODin = curve_item.get("LayerODin")
LayerWtLbFt = curve_item.get("LayerWtLbFt")
LayerNomThkin = curve_item.get("LayerNomThkin")
pipeSpecifications_data = findByODinAndWt(LayerODin, LayerWtLbFt)
LayerNomThkin = pipeSpecifications_data.get("Wall Thickness ins")
break

channel_start_end = {
Expand Down
Loading

0 comments on commit 0e6f5b1

Please sign in to comment.