Databases and big data · A level · OCR H446 1.3.2, AQA 7517 4.9.4.10, Eduqas A500QS 2.4 · about 55 min
How data gets in, how it is selected and managed, and how systems swap it as CSV, JSON and XML. The robot exports its own readings.
[1 mark]Exam answer sheets are scanned and the positions of shaded boxes are read. Which capture method is this?
[1 mark]A run time of 7.2 s is typed as 2.7 s. Which check could catch this?
[1 mark]What does a data dictionary hold?
[1 mark]Which are true of JSON compared with XML?
Tick every answer that is true.
[1 mark]What does this print?
import json
text = '{"robot": "Ada", "readings": [61, 51, 41], "ok": true}'
data = json.loads(text)
print(data["robot"], len(data["readings"]), data["readings"][-1] + 1, data["ok"])[1 mark]What does this print?
import csv, io
rows = list(csv.reader(io.StringIO("name,cm\nAda,42\nBolt,38\n")))
print(rows[1])
print(rows[1][1] + rows[2][1])The robot starts facing a wall. Take four readings, numbered step 0 to 3. For each: record step (a whole number), y (the second value of position(), rounded to 1 decimal place) and cm (the value of distance()), then drive forward 10 cm at speed 40 before the next reading (no drive after step 3).
Then, from that one list of readings:
1. Write readings.csv: the header line step,y,cm, then one line per reading, such as 1,10.0,51.0.
2. Write readings.json with json.dump: a list of four objects, each with the keys step, y and cm.
3. Read readings.json back with json.load and print json readings: <n>, the number of objects in it.
4. Print the readings as XML: a line <readings>, then one line per reading exactly in the form <reading step="1" y="10.0" cm="51.0"/> (indenting is allowed), then </readings>.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() import json readings = []
Plan your program here, then type it in and press Run.
seconds field, the time of each reading from clock(). Which of your three outputs needed changing, and how?Ada, the second. What goes wrong in a CSV file written by hand, and how does the csv module deal with it?