1.快速订单新增特征识别路径字段
2.修复销售经理和销售总监看不到快速订单菜单 3.优化系统设置页面,新增特征识别路径展示,去掉重复的业务平台参数配置展示 4.快速订单去掉老版本的特征识别的代码及包,新增最新的特征识别方法
This commit is contained in:
201
sf_sale/models/preload_datas_functions.py
Normal file
201
sf_sale/models/preload_datas_functions.py
Normal file
@@ -0,0 +1,201 @@
|
||||
import psycopg2
|
||||
# import pandas as pd
|
||||
|
||||
|
||||
def load_and_convert_data(table_name, column_names):
|
||||
connection = None
|
||||
data = []
|
||||
|
||||
try:
|
||||
# connection = psycopg2.connect(user="odoo",
|
||||
# password="odoo",
|
||||
# host="localhost",
|
||||
# port="5432",
|
||||
# database="www1")
|
||||
connection = psycopg2.connect(user="odoo",
|
||||
password="odoo",
|
||||
host="120.76.195.146",
|
||||
port="15432",
|
||||
database="bfm_dev1")
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
# Construct the query string using the table name passed in
|
||||
query = f"SELECT {', '.join(column_names)} FROM {table_name};"
|
||||
cursor.execute(query)
|
||||
|
||||
# Fetch all rows from cursor
|
||||
data = cursor.fetchall()
|
||||
|
||||
except (Exception, psycopg2.Error) as error:
|
||||
print("Error fetching data from PostgreSQL table", error)
|
||||
|
||||
finally:
|
||||
# Always close database connection after work done
|
||||
if (connection):
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
# Convert the list of tuples to DataFrame
|
||||
# df = pd.DataFrame(data, columns=column_names)
|
||||
#
|
||||
# # Convert all string columns to float
|
||||
# for col in df.columns:
|
||||
# if df[col].dtype == 'object':
|
||||
# df[col] = df[col].astype(float)
|
||||
|
||||
return 'df'
|
||||
|
||||
|
||||
def get_suitable_hole_working_hours(df, target_diameter, target_depth):
|
||||
"""
|
||||
从钻孔、铰孔数据中获取符合要求的最小工时
|
||||
"""
|
||||
# df为输入的数据,target_diameter为目标孔径,target_depth为目标孔深
|
||||
|
||||
df_diameter_filtered = df.loc[df['hole_diameter'] >= target_diameter]
|
||||
|
||||
if not df_diameter_filtered.empty:
|
||||
min_diameter = df_diameter_filtered['hole_diameter'].min()
|
||||
df_depth_filtered = df_diameter_filtered.loc[
|
||||
(df_diameter_filtered['hole_diameter'] == min_diameter) & (
|
||||
df_diameter_filtered['hole_depth'] >= target_depth)]
|
||||
|
||||
if not df_depth_filtered.empty:
|
||||
min_depth_row = df_depth_filtered.loc[df_depth_filtered['hole_depth'].idxmin()]
|
||||
min_working_hours = min_depth_row['working_hours']
|
||||
return min_working_hours
|
||||
else:
|
||||
print("No records found where hole_depth is bigger than the target depth")
|
||||
return None
|
||||
else:
|
||||
print("No records found where hole_diameter is bigger than the target diameter")
|
||||
return None
|
||||
|
||||
|
||||
def get_suitable_blank_working_hours(df, blank_height, blank_length, blank_width):
|
||||
"""
|
||||
从毛坯数据中获取符合要求的最小工时
|
||||
"""
|
||||
# df为输入的数据,blank_height为目标毛坯高度,blank_length为目标毛坯长度,blank_width为目标毛坯宽度
|
||||
|
||||
df_height_filtered = df.loc[df['blank_height'] >= blank_height]
|
||||
|
||||
if not df_height_filtered.empty:
|
||||
min_height = df_height_filtered['blank_height'].min()
|
||||
df_length_filtered = df_height_filtered.loc[
|
||||
(df_height_filtered['blank_height'] == min_height) & (
|
||||
df_height_filtered['blank_length'] >= blank_length)]
|
||||
|
||||
if not df_length_filtered.empty:
|
||||
min_length_row = df_length_filtered.loc[df_length_filtered['blank_length'].idxmin()]
|
||||
min_working_hours = min_length_row['working_hours']
|
||||
return min_working_hours
|
||||
else:
|
||||
print("No records found where blank_length is bigger than the target length")
|
||||
return None
|
||||
else:
|
||||
print("No records found where blank_height is bigger than the target height")
|
||||
return None
|
||||
|
||||
|
||||
def get_suitable_rough_working_hours(df, rough_depth):
|
||||
"""
|
||||
从粗加工数据中获取符合要求的最小工时
|
||||
"""
|
||||
# df为输入的数据,rough_depth为目标粗加工深度
|
||||
|
||||
df_depth_filtered = df.loc[df['rough_depth'] >= rough_depth]
|
||||
|
||||
if not df_depth_filtered.empty:
|
||||
min_depth_row = df_depth_filtered.loc[df_depth_filtered['rough_depth'].idxmin()]
|
||||
min_working_hours = min_depth_row['working_hours']
|
||||
return min_working_hours
|
||||
else:
|
||||
print("No records found where rough_depth is bigger than the target depth")
|
||||
return None
|
||||
|
||||
|
||||
def get_suitable_finish_working_hours(df, finish_depth, finish_tool_diameter):
|
||||
"""
|
||||
从精加工数据中获取符合要求的最小工时
|
||||
"""
|
||||
# df为输入的数据,finish_depth为目标精加工深度,finish_tool_diameter为目标精加工刀具直径
|
||||
|
||||
df_depth_filtered = df.loc[df['finish_depth'] >= finish_depth]
|
||||
|
||||
if not df_depth_filtered.empty:
|
||||
min_depth = df_depth_filtered['finish_depth'].min()
|
||||
df_tool_diameter_filtered = df_depth_filtered.loc[
|
||||
(df_depth_filtered['finish_depth'] == min_depth) & (
|
||||
df_depth_filtered['finish_tool_diameter'] >= finish_tool_diameter)]
|
||||
|
||||
if not df_tool_diameter_filtered.empty:
|
||||
min_tool_diameter_row = df_tool_diameter_filtered.loc[
|
||||
df_tool_diameter_filtered['finish_tool_diameter'].idxmin()]
|
||||
min_working_hours = min_tool_diameter_row['working_hours']
|
||||
return min_working_hours
|
||||
else:
|
||||
print("No records found where finish_tool_diameter is bigger than the target tool diameter")
|
||||
return None
|
||||
else:
|
||||
print("No records found where finish_depth is bigger than the target depth")
|
||||
return None
|
||||
|
||||
|
||||
def get_suitable_chamfer_working_hours(df, chamfer_length, chamfer_size):
|
||||
"""
|
||||
根据倒角长度获得倒角工时,装夹平面耗时clamping_type_plane和装夹斜面耗时clamping_type_slope
|
||||
"""
|
||||
# df为输入的数据,chamfer_length为目标倒角长度,clamping_type_plane为目标装夹平面耗时,clamping_type_slope为目标装夹斜面耗时
|
||||
|
||||
df_length_filtered = df.loc[df['chamfer_length'] >= chamfer_length]
|
||||
df_chamfer_size_filtered = df.loc[df['chamfer_size'] >= chamfer_size]
|
||||
|
||||
if not df_length_filtered.empty and not df_chamfer_size_filtered.empty:
|
||||
min_length_row = df_length_filtered.loc[df_length_filtered['chamfer_length'].idxmin()]
|
||||
min_chamfer_size_row = df_chamfer_size_filtered.loc[df_chamfer_size_filtered['chamfer_size'].idxmin()]
|
||||
clamping_time = min_length_row['clamping_time']
|
||||
clamping_type_plane = min_length_row['clamping_type_plane']
|
||||
clamping_type_slope = min_length_row['clamping_type_slope']
|
||||
coefficient = min_chamfer_size_row['coefficient']
|
||||
return clamping_time, clamping_type_plane, clamping_type_slope, coefficient
|
||||
else:
|
||||
print("No records found where chamfer_length is bigger than the target length")
|
||||
return None
|
||||
|
||||
|
||||
df_hole_duration = load_and_convert_data('hole_duration', ['hole_diameter', 'hole_depth', 'working_hours'])
|
||||
|
||||
df_j_hole_duration = load_and_convert_data('j_hole_duration', ['hole_diameter', 'hole_depth', 'working_hours'])
|
||||
|
||||
df_chamfer_duration = load_and_convert_data('chamfer_duration',
|
||||
['chamfer_length', 'clamping_time', 'chamfer_size', 'coefficient',
|
||||
'clamping_type_plane', 'clamping_type_slope'])
|
||||
|
||||
df_blank_duration = load_and_convert_data('blank_duration',
|
||||
['blank_length', 'blank_width', 'blank_height', 'working_hours'])
|
||||
|
||||
df_rough_duration = load_and_convert_data('rough_duration', ['rough_depth', 'working_hours'])
|
||||
|
||||
df_finish_duration = load_and_convert_data('finish_duration',
|
||||
['finish_depth', 'finish_tool_diameter', 'working_hours'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
min_working_hours = get_suitable_hole_working_hours(df_hole_duration, 24, 150)
|
||||
print('min_working_hours', min_working_hours)
|
||||
min_j_working_hours = get_suitable_hole_working_hours(df_j_hole_duration, 10, 15)
|
||||
print('min_j_working_hours', min_j_working_hours)
|
||||
min_blank_working_hours = get_suitable_blank_working_hours(df_blank_duration, 150, 300, 300)
|
||||
print('min_blank_working_hours', min_blank_working_hours)
|
||||
min_rough_working_hours = get_suitable_rough_working_hours(df_rough_duration, 49)
|
||||
print('min_rough_working_hours', min_rough_working_hours)
|
||||
min_finish_working_hours = get_suitable_finish_working_hours(df_finish_duration, 0.5, 10)
|
||||
print('min_finish_working_hours', min_finish_working_hours)
|
||||
clamping_time, clamping_type_plane, clamping_type_slope, coefficient = get_suitable_chamfer_working_hours(
|
||||
df_chamfer_duration, 10, 1.5)
|
||||
print('clamping_time', clamping_time)
|
||||
print('clamping_type_plane', clamping_type_plane)
|
||||
print('clamping_type_slope', clamping_type_slope)
|
||||
print('coefficient', coefficient)
|
||||
Reference in New Issue
Block a user