Search for '{{search_term}}'

Exercise: parse hours log file and create time report

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

Exercise: Parse hours log file and create time report.

When I was running class-room Perl training courses I've was logging how my course progresses and created log files like this:

examples/data/timelog.log

09:20 Introduction
11:00 Exercises
11:15 Break
11:35 Scalars
12:30 Lunch Break
13:30 Exercises
14:10 Solutions
14:30 Break
14:40 Arrays
15:40 Exercises
17:00 Solutions
17:30 End

09:30 Advanced Arrays
10:30 Break
10:50 Exercises
12:00 Solutions
12:30 Hash fuction introduction
12:45 Lunch Break
14:15 Exercises
16:00 Solutions
16:15 Break
16:30 Subroutines
17:00 Exercises
17:30 End

Every row starts with the timestamp when the specific activity started and then the name of the activity. Empty rows separate the dates.

Some of the activities are the names of the lectures, such as Introduction and Scalars. Others are the names of the names of the activities: Exercises, Solutions, Break, Lunch Break, and End marks the end of the training day.

A course lasts several days. In our sample file we have two days.

Once I had these log file I wanted to generate two reports.

One of them was to display the same data, but showing from-to timestamps and removing the End entry. It would look like this:

09:20-11:00 Introduction
11:00-11:15 Exercises
11:15-11:35 Break
...

The other one would show the accumulated time spent on various activities and the lectures detailed.

Lectures:  210 minutes 22%
Solutions:  95 minutes  9%
Break:      65 minutes  6%
...


Lectures: 
Introduction:  23 minutes 2%
...

This is the exercise, to implement the code that will take the log file and generate the reports.

Tools

Solutions

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus