Esempio n. 1
0
 def wrapper(req, *args, **kwargs):
     roughness = req.get('roughness', 1.5)
     internal_dimension = get_internal_diameter(req['nominal_diameter'],
                                                req['material'])
     if not internal_dimension:
         return error_response(400, 'Wrong pipe diameter value.')
     if 2 * roughness >= internal_dimension:
         return error_response(400, 'Wrong roughness value.')
     return func(*args,
                 req=req,
                 roughness=roughness,
                 internal_dimension=internal_dimension,
                 **kwargs)
Esempio n. 2
0
def gravity_flow(req):
    """Calculate gravity flow and velocity.

    :param req: request.get_json() flask's method to get json from user
    """
    height = req['height']
    if 'diameter' in req:
        diameter = req['diameter']
        if height > diameter:
            return error_response(400, 'Height couldn\'t be higher than diameter.')
        angle = angle_in_partial_filled_pipe(diameter, height)
        area = circular_water_cross_sectional_area(angle, diameter, height)
        perimeter = circular_wetted_perimeter(angle, diameter)
    else:
        width = req['width']
        area = rectangular_dict(width, height, 'm')
        perimeter = rectangular_wetted_perimeter(width, height)
    hydraulic_radius_value = hydraulic_radius(area, perimeter)
    velocity = manning_equation(hydraulic_radius_value, req['manning_coefficient'], req['slope'])
    return api_response(
        {
            'velocity': round(velocity, 2),
            'velocity_unit': 'm/s',
            'flow': round(velocity * area * 3600, 2),
            'flow_unit': 'm3/h',
        }
    )
Esempio n. 3
0
 def wrapper(*args, **kwargs):
     try:
         req = request.get_json()
         jsonschema.validate(req, schema)
         return func(*args, req=req, **kwargs)
     except jsonschema.exceptions.ValidationError as exc:
         return error_response(400, exc.message)
Esempio n. 4
0
 def wrapper(req, *args, **kwargs):
     if 'power' in req:
         power = unit_convertion(req['power'], req['power_unit'], 'W',
                                 'power')
         temperature_delta = abs(req['temperature_supply'] -
                                 req['temperature_return'])
         if not temperature_delta:
             return error_response(
                 400,
                 'Temperature supply and return can not have the same value.'
             )
         flow = power / (temperature_delta * req['density'] *
                         req['specific_heat'])
         req.update({'flow': flow, 'flow_unit': 'm3/s'})
     return func(*args, req=req, **kwargs)
Esempio n. 5
0
def wrong_method(e):
    return error_response(405, 'wrong method')
Esempio n. 6
0
def not_found(e):
    return error_response(404, 'not found')