THINK FIRST·CODE LATER

← All labs

Assign channels by type and importance

Problem

Write a tiny encoding recommender for point/line charts. Input lines: name type distinct (type is quantitative, ordinal or categorical), in order of importance.

Channel preference lists (best first): quantitative → x, y, size (area), luminance; ordinal → x, y, luminance, size (area); categorical → x, y, color hue, shape. Each channel is used at most once. Color hue can carry at most 9 categories and shape at most 6: if an attribute has more distinct values, skip that channel with a warning warning: station: 12 categories are too many for color hue (max ~9) (warnings printed after all assignments, in the order they occur). If no channel is left, print name (type) -> facet into small multiples.

Print pm25 (quantitative) -> x per attribute, then the warnings, then channels used: 4.

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.

v5-1-data-1.txt

pm25 quantitative 200
temperature quantitative 30
district categorical 3
level ordinal 3
What your program must print for v5-1-data-1.txt
pm25 (quantitative) -> x
temperature (quantitative) -> y
district (categorical) -> color hue
level (ordinal) -> luminance
channels used: 4

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 < v5-1-data-1.txt

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

Get-Content v5-1-data-1.txt | 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("v5-1-data-1.txt", 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.