You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
4 weeks ago
|
from utils.mysql import get_all_standard_diameters
|
||
|
import math
|
||
|
from decimal import Decimal
|
||
|
|
||
|
def group_pipes(pipes):
|
||
|
result = {}
|
||
|
for pipe in pipes:
|
||
|
if pipe['parent_id'] not in result:
|
||
|
result[pipe['parent_id']] = []
|
||
|
result[pipe['parent_id']].append(pipe)
|
||
|
return result
|
||
|
|
||
|
def get_pipes_diameter(pipes,design_plan_id):
|
||
|
pipeFlow= 0
|
||
|
standard_diamters = get_all_standard_diameters(design_plan_id)
|
||
|
res = []
|
||
|
for pipe in pipes:
|
||
|
pipeFlow += pipe['flow'] * pipe['valve_opening'] / 100
|
||
|
res.append(get_pipe_diameter(pipe,pipeFlow,standard_diamters))
|
||
|
return res
|
||
|
def get_pipe_diameter(pipe,pipeFlow,standard_diamters):
|
||
|
cal_diameter =Decimal(2000 * math.sqrt(pipeFlow / 19 / 3600 / Decimal(math.pi)))
|
||
|
diameter = find_closest_greater_diameter(cal_diameter, standard_diamters)
|
||
|
|
||
|
return {
|
||
|
'id':pipe['id'],
|
||
|
'flow':pipe['flow'],
|
||
|
'valve_opening':pipe['valve_opening'],
|
||
|
'is_normally_open':pipe['is_normally_open'],
|
||
|
'pipe_flow':pipeFlow,
|
||
|
'diameter':diameter,
|
||
|
'cal_diameter':cal_diameter,
|
||
|
}
|
||
|
|
||
|
def find_closest_greater_diameter(cal_diameter, standard_diameters):
|
||
|
greater_diameters = [d for d in standard_diameters if d > cal_diameter]
|
||
|
if not greater_diameters:
|
||
|
return max(standard_diameters)
|
||
|
closest_diameter = min(greater_diameters, key=lambda d: d - cal_diameter)
|
||
|
return closest_diameter
|