Summarizing Your Data

Overview


By the end of the last part, your study log was persistent. Sessions you logged on Monday were still there on Tuesday. The program had learned to remember.

What it has not yet learned is to make use of what it remembers.

If you have been using the log between parts, you now have a real file with real sessions in it. At the end of each run, the program prints a short summary — total minutes, number of sessions, and longest single session. But the summary has not kept up with the data. It does not break time down by subject. It does not say which day was heaviest. It does not know whether you have studied two days in a row or twenty. The data is sitting in the file, and most of it is being ignored.

In this part, you will learn to compute small, useful facts from large piles of records — the operations that turn a list of sessions into “you have studied 14 hours of math this month” or “you are on a five-day streak”.

The structure of this part is as follows:

Finally, the recap and feedback chapter summarizes what was covered and asks for feedback.

Summaries and Empty-Data Results

In this part, you’ll write plenty of summary functions. Each one you write will have a small contract — a specification of what it returns on normal data, and what it returns on empty data. The summary-contract table below makes these commitments explicit:

QuestionNormal resultEmpty-data result
How many items match?Integer count0
How many minutes match?Integer total0
What is the average?NumberNone
What is the longest session?Number or rowNone
What are the totals by subject?List of summary rows[]
What is the heaviest day?[date_string, minutes]None
What is the current or longest streak?Integer number of days0

The pattern is small: counts and totals return zero on empty input; averages and “best of” answers return None; collections of summaries return empty collections. Writing a summary function starts with deciding which question it answers, and then committing to the right empty-data result for that question.

  1. read the regular chapters in order, completing exercises as you go,
  2. complete the project checkpoint in Adding an Opening Dashboard to Your Study Log,
  3. and finish with the recap and feedback.

The new mechanical material in this part is bounded — dates, sorting, and the small list-comprehension form. The harder work is in the compositions you write on top of them: per-category summaries, time-window filters, daily totals, streaks.