THINK FIRST·CODE LATER

← All labs

Audit an AI-generated chart

Problem

A chatbot produced Vega-Lite specifications for CityPulse. Write an automatic auditor: read one JSON specification from standard input and apply these rules, in this order:

  • R1 — on a bar or area mark, a quantitative x or y encoding with scale.zero set to false: R1 truncated y axis on a bar chart (scale.zero is false).
  • R2 — an arc (pie) mark whose colour field (or, if none, theta field) has more than 5 distinct values in data.values: R2 pie chart with 6 slices (more than 5).
  • R3 — no title: R3 no chart title.
  • R4 — colour scheme rainbow or jet (the cyclic sinebow is fine for cyclic data such as hour of day): R4 rainbow colour scheme 'rainbow'.
  • R5 — a field whose name contains date, time, month or day (case-insensitive) encoded with a type other than temporal or ordinal: R5 time field 'month' on x encoded as nominal.
  • R6 — resolve.scale.y is independent (dual axes): R6 dual y axes (independent scales).

The mark may be a string ("bar") or an object ({"type": "bar"}). First print mark: bar, channels: x, y (channels sorted), then the issues, then 2 issue(s) found or No issues found.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v1-3-data-1.jsonl

{"mark":"bar","data":{"values":[{"district":"A","pm25":40},{"district":"B","pm25":44}]},
 "encoding":{"x":{"field":"district","type":"nominal"},"y":{"field":"pm25","type":"quantitative","scale":{"zero":false}}}}
What your program must print for v1-3-data-1.jsonl
mark: bar, channels: x, y
R1 truncated y axis on a bar chart (scale.zero is false)
R3 no chart title
2 issue(s) found

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v1-3-data-1.jsonl

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v1-3-data-1.jsonl | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v1-3-data-1.jsonl", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.