~mrp/time_computer

371588274e59756989fd7ef468d614c89cfe5ac8 — Mark Penner 3 years ago 35d18a6
fix bug in parse_line and change test_parse_line to catch it
2 files changed, 19 insertions(+), 5 deletions(-)

M tc.py
M test_tc.py
M tc.py => tc.py +17 -3
@@ 9,9 9,17 @@
import sys
import datetime


def total_hours(data):
    total = 0.0
    for item in data:
        total += item["hours"]
    return total


if __name__ == "__main__":
    print("time computer")
    print("version 2020-03")
    print("version 2020-04")
    print("        ____")
    print("       /    \\")
    print("      /  |   \\")


@@ 35,7 43,14 @@ if __name__ == "__main__":
    dates = []
    totalminutes = 0
    linenum = 1
    # data = []
    # for line in infile:
    # data.append(parse_line(line))

    # print("Total hours:", total_hours(data))

    try:

        while True:
            linebuffer = []
            try:


@@ 155,7 170,6 @@ 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])


@@ 169,7 183,7 @@ def parse_line(line):

    hours = 0
    i = 1
    for item in range(1, len(times), 2):
    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_tc.py => test_tc.py +2 -2
@@ 13,8 13,8 @@ tc = __import__("tc")


def test_parse_line():
    assert tc.parse_line("20210331 jobname 08:00 12:00 13:00 17:00") == {
    assert tc.parse_line("20210331 jobname 06:47 11:59 12:52 17:03") == {
        "date": datetime.date(2021, 3, 31),
        "job": "jobname",
        "hours": 8,
        "hours": 9.383333333333333,
    }