──────────────────────────────────────

56. Work with Spreadsheets, PDFs and Images · Build a Club File Pack

Combine what you learn about worksheet counts, PDF text and image sizes into one handover report.

Lesson files · lessons/documents-and-images/build-a-club-file-pack

Before you start
- Keep zero counts separate from missing counts.
- Flag pages with no extracted text after trimming.
- Measure a poster against a size limit.

By the end
- Use one report function for counts, pages and posters.
- Test report totals for an empty packet and for items exactly at the size limit.
- Use the local lab to create and reopen a worksheet, PDF and image copies.

Where you can use it
Prepare files for a new club organiser. Give them a count summary, a combined print pack and poster copies ready for a small screen.

A handover report can show what a club has and what a person still needs to check. Keep the calculations in a function that receives the kit counts, extracted page texts and poster dimensions. Studio supplies these facts in one JSON object so you can test the rules with small examples.

The local workbook lab reads the same kinds of facts from actual files. It applies the report function, writes an XLSX inventory, combines the PDFs and saves PNG copies that fit within 320 by 320 pixels. Opening the saved files checks that the pack is usable by the next person.

Predict
Which result should change when a blank count is filled with 0?
- Kits recorded goes up by one.
- Rows with a count goes up by one.

Worked example (example.py)

quantities = [4, 0, None]
known = [count for count in quantities if count is not None]
print(f"Rows with a count: {len(known)}")
print(f"Kits recorded: {sum(known)}")


Example result
Rows with a count: 2
Kits recorded: 4

Read one JSON object with the lists kits, pages and posters. Kits contains whole-number counts or null. Pages contains strings from PDF extraction. Posters contains width and height pairs.

Complete file_pack_summary() to return five labelled counts in this order. Report Rows with a count, Kits recorded, Rows missing a count, PDF pages to review and Posters to resize. Count a page for review when its text is empty after trimming. Count a poster for resizing when either side exceeds 320 pixels. The supplied print loop displays each label and its count.

After Studio, download the Intermediate Python ZIP workbook. Open this lesson's folder and follow README.txt to build and verify your own pack from the five real practice files.

Starter program (starter.py)

import json


def file_pack_summary(quantities, page_texts, image_sizes):
    return [("Rows with a count", len(quantities))]


data = json.loads(input())
for label, count in file_pack_summary(data["kits"], data["pages"], data["posters"]):
    print(f"{label}: {count}")


Starter input
{"kits":[4,0,null],"pages":["Club Kit Schedule","Meet outside the lab",""],"posters":[[800,400],[160,160]]}

Hint
Keep the three kinds of calculation separate. Count every known number, then use individual checks for stripped page text and the longer image dimension.

Case 1. Try the sample
Input
{"kits":[4,0,null],"pages":["Club Kit Schedule","Meet outside the lab",""],"posters":[[800,400],[160,160]]}
Expected output
Rows with a count: 2
Kits recorded: 4
Rows missing a count: 1
PDF pages to review: 1
Posters to resize: 1

Case 2. Empty pack
Input
{"kits":[],"pages":[],"posters":[]}
Expected output
Rows with a count: 0
Kits recorded: 0
Rows missing a count: 0
PDF pages to review: 0
Posters to resize: 0

Case 3. At the size limit
Input
{"kits":[0],"pages":["  "],"posters":[[320,160],[160,320]]}
Expected output
Rows with a count: 1
Kits recorded: 0
Rows missing a count: 0
PDF pages to review: 1
Posters to resize: 0

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Build a new pack from a second fixture folder with a changed kit count. Compare the two reports and explain the difference to a reader.

The ZIP includes added practice files for this lesson. Open its lesson folder and read the included instructions.

Reflect
Which report number asks a person to inspect a file, and what should they look for?

Check your prediction
Rows with a count goes up by one. A zero provides a count. It adds zero to the total number of kits.
