function GetCurveValue ( curve_register, x_to_find_y ) --[[ --Curve handler INPUT: Put curve register as first argument and X coordinate as second. OUTPUT: Get as result status if it is inside curve range of outside(false) and the Y value as second output argument EXAMPLE: curve_status, value = GetCurveValue( "curve_for_current_hour", current_hour ) --]] table = cjson.decode( R ( curve_register ) ) -- inRangeCurve( table, x_to_find_y ) for _, value in ipairs( table ) do --piecewise handler inside range of the curve if ( value.range[1] <= x_to_find_y and x_to_find_y < value.range[2] ) then -- in_range_status, index_curve_piece, y = true, index, curveLinearCalc( x_to_find_y, value.k, value.b ) in_range_status, y = true, ( x_to_find_y * value.k + value.b ) return in_range_status, y end end if x_to_find_y < table[1].range[1] then -- behaivior for outside left-sided -- in_range_status, index_curve_piece, y = false, 1, curveLinearCalc( table[1].range[1], table[1].k*0, table[1].b ) --table[1].b in_range_status, index_curve_piece, y = false, 1, ( table[1].range[1] * table[1].k + table[1].b ) --table[1].b return in_range_status, y elseif x_to_find_y > table[#table].range[2] then -- behaivior for outside right-sided -- in_range_status, index_curve_piece, y = false,#table,curveLinearCalc( table[#table].range[2], table[#table].k, table[#table].b ) --table[#table].b in_range_status, y = false,#table,( table[#table].range[2] * table[#table].k + table[#table].b) return in_range_status, y end return in_range_status, y end