Capstone — a small campus application

Put the pieces in one picture. A lab utilisation tool: SQLite (or CSV) holds seats and occupancy, pandas (or loops) computes percent, a rule flags Over at 80%, matplotlib saves a bar chart, optional pygame shows a live room colour, tests lock the percent function. That is not a toy — it is the skeleton of every internal school tool you will be asked to build.

Application blueprint

A program is folders, config and a main door.

You will be able to

  • Place each library in a layer of one application
  • Keep the business rule in a tested function
  • Describe a build you could actually ship to a lab technician

One page architecture

config.py — paths, 80% threshold, school name. domain.py — percent(used, seats) and flag(pct). storage.py — sqlite3 or pandas.read_csv. report.py — matplotlib. optional kiosk.py — pygame colour of the room. tests/test_domain.py — percent(8, 10) is 80. main.py — wires them under if __name__.

If you cannot draw those boxes on paper, you are not ready to add another library. More imports will not fix a blob.

The rule stays boring

percent = used * 100 / seats, with seats > 0. Over if percent >= threshold. That function must run in this sandbox, in pytest, and in a FastAPI route later without changing. pygame may paint red; it must not re-implement the 80.

When the principal changes 80 to 75, you change CONFIG. You do not hunt through blit calls.

What “done” looks like

A README that says how to pip install -r requirements.txt and python main.py. A sample data file. A PNG the technician can open. A test you run with pytest. That package is more professional than a 2,000-line Jupyter notebook titled FINAL_FINAL3.

You now have the map: beginner syntax, intermediate data structures and tests, advanced storage and libraries. The next course is not “more syntax” — it is building one real tool and keeping it running.

Words that matter

requirements.txt
Pinned libraries so another machine installs the same stack.
Layer
A file/module with one job: domain, storage, UI, report.
Capstone
A small complete application that uses several skills together.

Common mistakes

Avoid: Re-coding the 80% rule in pandas, in pygame, and in the chart title.

Do this: One function; everyone calls it.

Avoid: Shipping without a sample data file.

Do this: A new technician must run the demo without your laptop.

On a full Python install — Putting it together

This is the shape of a real mini-product. Copy the idea, not every line, into a folder with domain.py and main.py.

pip install pandas matplotlib pygame # pygame optional for a kiosk

Domain stays pure; pandas is storage/report; matplotlib is the human output.

Real library code (not run in this browser sandbox)

import pandas as pd
import matplotlib.pyplot as plt

THRESHOLD = 80

def percent(used, seats):
    if seats <= 0:
        return 0
    return used * 100 / seats

def flag(pct):
    if pct >= THRESHOLD:
        return "Over"
    return "OK"

df = pd.read_csv("data/labs.csv")
df["pct"] = [percent(u, s) for u, s in zip(df["used"], df["seats"])]
df["flag"] = df["pct"].map(flag)
print(df)

plt.bar(df["lab"], df["pct"])
plt.axhline(THRESHOLD)
plt.ylabel("% utilised")
plt.savefig("lab_util.png", dpi=150)

Example program — The domain of a lab board

Same 80% rule the chart and kiosk must call. Change used and seats.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Your turn — Flag a full room

percent(20, 20) is 100. Print Over for that lab so Over appears.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Self-assessment

Check your understanding before you mark the lesson complete.

1. The utilisation threshold should live in…
2. A shippable campus tool includes…

Progress is stored in a browser cookie on this device.