def get_LOS(headway = None, frequency = None, veh_per_hr = None):
You have no docstring. That would helpful in explaining what the parameters are doing.
if frequency != None and headway = veh_per_hr == None:
When checking wheter something is none it is best to use
is None or
is not None
headway = 1 / frequency
The problem is that if someone passes frequency along with one of the other parameters, this function will go merrily onwards and probably not even produce an error. I recommend having a get_LOS_from_frequency function which takes the frequency and then calls this function.
if headway!= None or veh_per_hr != None:
if headway 10 < or veh_per_hr > 6:
I'm pretty sure that won't compile
elif 10 <= headway < 15 or 5 < veh_per_hr <= 6:
elif 15 <= headway < 20 or 3 < veh_per_hr <= 5:
elif 20 <= headway < 31 or 2 < veh_per_hr <= 3:
elif 31 <= headway < 60 or 1 <= veh_per_hr < 2:
elif headway >= 60 or veh_per_hr < 1:
I'd store these values in a list which makes it easy to pull them from configuration at a later date if neccesary.
Don't report error by returning strings. Throw an exception, or at least assert False.
How I'd do this:
return get_los(1 / frequency)
HEADWAY_LIMITS = [10, 15, 20, 31, 60]
VEH_PER_HR_LIMITS = [1,2,3,5,6]
GRADES = "ABCDEF"
def get_los(headway = None, veh_per_hr = None):
if headway is None:
headway_score = len(GRADES)
headway_score = bisect.bisect_left(HEADWAY_LIMITS, headway)
if veh_pr_hr is None:
veh_pr_hr_score = len(GRADES)
veh_pr_hr_score = len(GRADES) - bisect.bisect_left(VEH_PR_HR_LIMITS, veh_pr_hr)
return GRADES[min(headway_score, veh_pr_hr_score)]