~mrp/time_computer

36b4edd5ae34b657ce269c14d6c513d615855e6d — Mark Penner 3 years ago 727d4d1
add reg_overtime_hours function to calculate regular hours and overtime hours from weekly hours
2 files changed, 24 insertions(+), 0 deletions(-)

M tc.py
M test_tc.py
M tc.py => tc.py +17 -0
@@ 61,6 61,23 @@ def weekly_hours(data):
    return output


def reg_overtime_hours(weekly, standard_week):
    """
    calculate how much regular time and how much overtime worked
    take a dictionary from weekly_hours of ISO week numbers as keys and hours as values
    and standard_week an integer of hours when overtime begins
    return a dictionary like {"regular": 40, "overtime": 4.5}
    """
    output = {"regular": 0, "overtime": 0}
    for week in weekly:
        if weekly[week] <= standard_week:
            output["regular"] += weekly[week]
        else:
            output["regular"] += standard_week
            output["overtime"] += weekly[week] - standard_week
    return output


def job_hours(data):
    """
    calculate how many hours worked each job

M test_tc.py => test_tc.py +7 -0
@@ 38,6 38,13 @@ def test_weekly_hours():
    ) == {13: 16.380000000000003}


def test_reg_overtime_hours():
    assert tc.reg_overtime_hours({1: 39, 2: 40, 3: 44.5, 4: 82}, 40) == {
        "regular": 159,
        "overtime": 46.5,
    }


def test_job_hours():
    assert tc.job_hours(
        [