~mrp/time_computer

3bd12d6af9459420dc9bf1c2d79d6d6c40100dd9 — Mark Penner 3 years ago 3715882
add .gitignore, add test_total_hours, restructuring
4 files changed, 36 insertions(+), 27 deletions(-)

A .gitignore
M tc.py
M test-file
M test_tc.py
A .gitignore => .gitignore +2 -0
@@ 0,0 1,2 @@
*.pyc
__pycache__

M tc.py => tc.py +22 -24
@@ 10,6 10,28 @@ import sys
import datetime


def parse_line(line):
    """ parse a line in the input file """
    items = line.split()
    year = int(items[0][0:4])
    month = int(items[0][4:6])
    day = int(items[0][6:8])
    name = items[1]

    times = []
    for i in range(2, len(items)):
        timehm = items[i].split(":")
        time = float(timehm[0]) + (float(timehm[1]) / 60)
        times.append(time)

    hours = 0
    i = 1
    for i in range(1, len(times), 2):
        hours += times[i] - times[i - 1]

    return {"date": datetime.date(year, month, day), "job": name, "hours": hours}


def total_hours(data):
    total = 0.0
    for item in data:


@@ 163,27 185,3 @@ if __name__ == "__main__":
    print("overtime:", round(overtime, 2))

    print("\ntotal hours:", round(totalminutes / 60, 2), "\n")


def parse_line(line):
    """
    parse a line in the input file
    """
    items = line.split()
    year = int(items[0][0:4])
    month = int(items[0][4:6])
    day = int(items[0][6:8])
    name = items[1]

    times = []
    for i in range(2, len(items)):
        timehm = items[i].split(":")
        time = float(timehm[0]) + (float(timehm[1]) / 60)
        times.append(time)

    hours = 0
    i = 1
    for i in range(1, len(times), 2):
        hours += times[i] - times[i - 1]

    return {"date": datetime.date(year, month, day), "job": name, "hours": hours}

M test-file => test-file +0 -3
@@ 8,8 8,5 @@
20181205 byler 07:03 11:58 12:35 18:25
20181206 byler 09:17 11:57 12:46 20:40
20181207 byler 07:32 11:58 11:59 12:52 17:03 20:40
20181210 byler 07:32 11:58
20181211 byler 07:32 11:58
20181212 byler 07:32 11:58
20181213 byler 07:32 11:58
20181213 watson 12:32 16:58

M test_tc.py => test_tc.py +12 -0
@@ 18,3 18,15 @@ def test_parse_line():
        "job": "jobname",
        "hours": 9.383333333333333,
    }


def test_total_hours():
    assert (
        tc.total_hours(
            [
                {"date": datetime.date(2021, 3, 31), "job": "jobname", "hours": 9.38},
                {"date": datetime.date(2021, 3, 31), "job": "jobname", "hours": 7},
            ]
        )
        == 16.380000000000003
    )