def get_int_default_or_max(val, default_val, max_val=None):
    """Given a string try to turn it into an int and enforce a max and default if the string is not a int value"""
    try:
        i = int(val)
        if max_val and i > max_val:
            i = max_val
    except:
        i = default_val
    return i