def walsh_percent_effect_remaining(minutes, action_duration):
    """ Give percent of insulin remaining for IOB calculations.
        This curve is only included for the purposes of running glucose
        activity tests

        Arguments:
        minutes -- minutes after insulin delivery
        dia -- duration of insulin action, in hours
    """
    if minutes <= 0:
        return 1
    if minutes >= action_duration * 60:
        return 0
    dia = round(action_duration)
    if dia < 3:
        dia = 3
    elif dia > 6:
        dia = 6
    minutes = minutes * dia / action_duration
    if dia == 3:
        return -3.203e-09 * pow(minutes, 4) + 1.354e-06 * pow(minutes, 3
            ) - 0.0001759 * pow(minutes, 2) + 0.0009255 * minutes + 0.99951
    if dia == 4:
        return -3.31e-10 * pow(minutes, 4) + 2.53e-07 * pow(minutes, 3
            ) - 5.51e-05 * pow(minutes, 2) - 0.0009086 * minutes + 0.9995
    if dia == 5:
        return -2.95e-10 * pow(minutes, 4) + 2.32e-07 * pow(minutes, 3
            ) - 5.55e-05 * pow(minutes, 2) + 0.000449 * minutes + 0.993
    if dia == 6:
        return -1.493e-10 * pow(minutes, 4) + 1.413e-07 * pow(minutes, 3
            ) - 4.095e-05 * pow(minutes, 2) + 0.0006365 * minutes + 0.997
    raise RuntimeError
