Personal data and privacy
What personal data is, the Data Protection Act 2018, and anonymising a log.
Do this lesson in the simulatorEvery app you use collects something about you. Some of it you hand over; much of it is gathered while you go about your day. Personal data is protected by law in the UK, and this lesson is about what counts as personal data, what the law demands of anyone who holds it, and how to handle it responsibly in a program.
What counts as personal data?
Personal data is any information that identifies a living person, on its own or joined with something else: name, address, email, photo, location, IP address, or an ID number. Some kinds are special category data and need extra care: health, ethnicity, religion, sexual orientation, biometrics.
Data that identifies nobody is not personal data. "Robot 7 drove 240 cm" is not; "Sam drove 240 cm at 10:15" is.
The Data Protection Act 2018
The Data Protection Act 2018 is the UK's data protection law, and it puts the UK GDPR into force here. Anyone holding personal data must follow its principles. Data must be:
| Principle | What it means |
|---|---|
| Lawful, fair and transparent | you must have a good reason, and tell people what you collect and why |
| Used for a stated purpose | collected for a specific reason, and not quietly used for another |
| Adequate but not excessive | collect the minimum needed for the job, and no more |
| Accurate | kept correct and up to date, and corrected when wrong |
| Kept no longer than needed | deleted once the reason for holding it has gone |
| Kept secure | protected against loss, theft and misuse, for example by encryption |
You also have rights over your own data: to see what is held about you, to have mistakes corrected, to have it erased, and to object to some uses.
Data minimisation in a program
The best protection is not to hold the data at all. A robot logging lesson activity does not need names to work out how far the class drove:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
rows = [("Sam Patel", "sam@school.uk", 240), ("Ava Ng", "ava@school.uk", 180)]
for name, email, cm in rows:
print("full record:", name, email, cm)
# the same answer, with nothing personal kept
print("class total:", sum(cm for _, _, cm in rows), "cm")
Anonymising
Where data must be kept, it can often be anonymised: the identifying parts removed or replaced, so the useful pattern is left but the person is not. Replacing names with student 1, student 2 is enough for a class report, and the report can then be shared safely.
Be careful: data can be re-identified by joining it with something else. A "anonymous" record of one person's exact route home is still that person.
Task: anonymise the log
Each row of log is a name, an email and a distance in centimetres. Print an anonymised line for each, in the form student 1: 240 cm, numbering the students from 1 in the order they appear. Then print records: <n> and total: <n> cm. Nothing in the output may contain a name or an email.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# name, email, distance in cm
log = [
("Sam Patel", "sam@school.uk", 240),
("Ava Ng", "ava@school.uk", 180),
("Jo Reilly", "jo@school.uk", 95),
("Kit Hale", "kit@school.uk", 310),
]
Challenges
- Print the furthest distance without printing who drove it.
- Which principle of the Act does anonymising the log help you follow?
- A school keeps every robot log for ten years. Which principle does that break?