# step2_river.py — two signals, and a score for each one.
# A score is a number from 0 to 1. 0 means calm. 1 means danger.
# The file is growing, so it gets a shape: functions, and main().

RAIN = [4, 0, 12, 31, 88, 64, 9]              # mm per day
RIVER = [2.4, 2.4, 2.5, 2.9, 3.6, 4.1, 3.9]    # metres at gauge P.1, Nawarat Bridge
CRITICAL = 3.70                                # at 3.70 m the Irrigation Office warns


def ramp(value, low, high):
    """0 below low, 1 above high, a straight line between them."""
    if value <= low:
        return 0.0
    if value >= high:
        return 1.0
    return (value - low) / (high - low)


def rain_score(mm):
    """20 mm is nothing. 80 mm in one day is full danger."""
    return ramp(mm, 20, 80)


def river_score(metres):
    """3.0 m is calm. At the critical level the score is 1."""
    return ramp(metres, 3.0, CRITICAL)


def main():
    for day in range(len(RAIN)):
        rain = rain_score(RAIN[day])
        river = river_score(RIVER[day])
        print(f"day {day + 1}: rain {rain:.2f}   river {river:.2f}")


if __name__ == "__main__":
    main()
