Project: an impact report
Read the trial log, anonymise it, cost its energy and carbon, and publish a report.
Do this lesson in the simulatorA school is deciding whether to buy a class set of robots, and has asked for a report. This project writes it: a program that reads the trial's log, keeps the useful facts, throws away the personal ones, works out the energy and carbon cost, and prints a report anyone could publish. It puts together privacy (F12.2), the environment (F12.5) and weighing up impacts (F12.1).
The log
The trial recorded one line per session. It is on this page, so you can see exactly what the program reads:
name,email,minutes,distance_cm
Sam Patel,sam@school.uk,45,240
Ava Ng,ava@school.uk,30,180
Jo Reilly,jo@school.uk,20,95
Kit Hale,kit@school.uk,50,310
Sam Patel,sam@school.uk,25,140
It holds names and email addresses. The report must not.
What the report needs
- How much it was used: the number of sessions, the number of students, and the total minutes.
- Nothing personal: students appear as
student 1,student 2and so on, in the order they first appear. No names, no email addresses. - The cost to the environment: the energy for those minutes, its price, and its carbon.
- A verdict you could defend.
For the energy, take a robot and its laptop together as 60 W, electricity at 28p a unit, and 190 g of CO2 a unit.
Reading the file
The file is on the page, so a program here can open it like any other:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
rows = open("trial.csv").read().strip().split("\n")
print("header:", rows[0])
for line in rows[1:3]:
name, email, minutes, cm = line.split(",")
print("session:", name, minutes, "min")
Plan it first
- read the file and split off the header;
- give each new name the next
student <n>label, remembering the ones you have seen; - add up the minutes and the distances;
- energy in kWh is
60 * total_minutes / 60 / 1000; - print the lines the report needs, and never print a name or an email.
Task: write the report
Read trial.csv and print the report, in this order and these exact forms:
sessions: <n>students: <n>total minutes: <n>- one line per student,
student <n>: <minutes> min, <cm> cm, numbered in the order they first appear energy: <kwh> kWhrounded to 2 decimal placescost: £<n>rounded to 2 decimal placescarbon: <n> g CO2rounded to the nearest whole numberpersonal data in this report: none
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
WATTS = 60
PENCE_PER_KWH = 28
GRAMS_PER_KWH = 190
Challenges
- Add the average minutes per session, without naming anyone.
- Add a line comparing the carbon with something familiar, such as a car journey.
- Write three sentences of verdict for the school: two impacts and a recommendation.