views/dashboard.pyA view layer that can be tested; lineage from the catalogueInstruction session · Thursday, December 10, 2026 · one hour of demonstration, one hour of application in the groups
The DataApp of the TCGplayer prices already runs by itself. In this session it gains the layer that people look at: a Streamlit app, inside the views layer of the package, that explains how the DataApp works and lets its users explore the gold layer with charts chosen for each question.
Project ritual
Each group reports the progress of its deliverables, the work planned for this session and the blockers that require a decision.
In the first hour the professor builds the app live with a coding agent, in four steps, over a copy of the package of Lesson 7, and compares each step with the reference package 0.5.0. In the second hour each group adds the same kind of app to the DataApp of the partner.
views/dashboard.pyA view layer that can be tested; lineage from the catalogueviews/app.py, themeThe execution model of Streamlit; the DAG and the lineagepip install -e '.[dev,app]', tcg-dataapp run, tcg-dataapp app and pytest. The reference package is in lab/lesson-11/tcg_dataapp/ of the module.A chart is chosen by the question it must answer, not by the variety of the library. Each question of the DataApp has one job, and each job has a form that the eye reads with the least effort.
| Job of the data | Question in the DataApp | Form | Avoid |
|---|---|---|---|
| compare magnitudes | which sets hold the most expensive cards? | horizontal bars ranked, from zero | pie with seven slices; bars that start above zero |
| change over time | how did the value of a set evolve between captures? | line, one series highlighted | seven coloured lines with a legend |
| part of a whole | what share of the market is one set? | one sentence or a single stacked bar | donut with labels outside it |
| hierarchy | inside a set, which rarity, and inside it which card? | bars with drill-down and roll-up | a treemap read by colour |
| one headline number | how many prices does the fact hold? | a number with its label, no chart | a gauge |
| how the system works | what runs, in which order, from where to where? | a graph of tasks and a graph of lineage | a diagram drawn by hand that drifts from the code |
Position on a common scale is read more precisely than length, length more than angle and area, and all of them more than colour. A chart therefore places the message in position or length and uses colour only to point at it.
The series that carries the message is drawn in the accent; every other series stays grey, as context. Seven sets do not need seven colours, which no reader with colour blindness separates.
The value at the end of the bar and the name at the end of the line replace the legend, which forces the eye to travel and back. The grid and the axes stay pale.
Each view opens with the sentence that states the conclusion, with the number that matters, and the chart supports that sentence. A chart without a sentence leaves the conclusion to chance.
Step 01 · 0:20 · Queries
Before any chart, the queries of the app live in one module without Streamlit, over a read-only connection. Two small changes below the views give the infographic its metadata.
views/dashboard.py, pipeline.py (ops.pipeline_tasks), processors/gold.py (comment of the frozen tables), tests/test_dashboard.py.
DROP VIEW?ValueError, and a typed value stay a parameter?[C] Character
You are a data engineer who maintains tcg-dataapp, the Python package of
Lesson 7, with its three layers (views, processors, etls), its pipeline of
twelve tasks and its DuckDB warehouse. You know that a chart is only as
honest as the query behind it.
[R] Request
Prepare the view layer for a Streamlit app, without Streamlit yet.
1. views/dashboard.py, a module of pure functions over a read-only
connection (connect(db_path) opens it with read_only=True):
- overview(con): sets, cards, prices of the fact, captures, cells of the
cube, first and last capture, and the last run of ops.pipeline_runs
(tasks ok, tasks, failed attempts, start and end).
- headline(con): the most valuable card of report.v_card_price_latest
and the share of the largest set in report.v_set_value_latest.
- task_graph(con): the tasks of the last run with their dependencies,
final status, attempts and seconds.
- lineage(con): every object of db_ingestion, gold, mart_collectors and
report, its rows, its kind (table or view) and its layer, and the
edges source -> target found in the SQL of each view (duckdb_views()).
- explore(con, source, dims, measure, filters, suffix): ranked groups
of the frozen report report.mv_card_price_<suffix> or of the live view
report.v_card_price_latest, returning the rows and the SQL.
- cube_check(con, result, dims, measure, filters): the same groups read
from gold.agg_price_cube at the right grouping_id, and whether they
agree; None when the card is used, because the cube has no card.
- price_history(con, level, highlight): market value of each set on
every capture, or the five most valuable cards of one set.
2. Two small changes below the views, so the app can draw from metadata:
- pipeline.py keeps the graph of each run in ops.pipeline_tasks
(run_id, task, depends_on VARCHAR[]);
- freeze_month writes COMMENT ON TABLE report.mv_... IS 'frozen from
<source>, last capture of <month>', because a table does not remember
the query that created it.
3. tests/test_dashboard.py over the FakeClient of conftest.py.
Facts measured on 08/11/2026 (confirm before use):
- tcg-dataapp run: 12 tasks ok in about 25 s; 7 sets, 1,273 cards,
5,951 prices, 5 captures, 524 cells of the cube.
- The lineage has 13 objects and 20 edges; the frozen report of September
has 1,226 rows.
[E] Example
cube_check for dims = ["set_name"]: grouping_id = 2 + 1 = 3 (rarity and
variant rolled up), 7 cells on the last capture, agree = True.
[A] Adjustments
- dims and measure come from fixed lists (DIMENSIONS, MEASURES); anything
else raises ValueError. Filter values are parameters (?), never SQL.
- Dates stay in Unix time in this module; nothing is converted here.
- The views never read db_ingestion, except to count it in the lineage.
[T] Type of output
The files, the output of pytest and, on the real warehouse, the result of
overview, lineage (number of nodes and edges) and one cube_check.
[E] Extras
Show the plan before editing. Stop at the end.
A diagram drawn by hand describes the system on the day it was drawn. A diagram generated from the catalogue and the run log describes the system that ran, and changes when the code changes.
duckdb_views()The SQL of every view is in the catalogue. Searching it for the names of the other objects gives the edges of the lineage: gold.fact_price reads db_ingestion, gold.dim_set and gold.dim_product.
A table made by CREATE TABLE AS keeps only its columns. freeze_month writes its source in the comment, and the lineage reads it from duckdb_tables().
ops.pipeline_tasksThe runner records the graph of each run next to ops.pipeline_runs, so the app draws the DAG without importing the pipeline, which would break the direction of the layers.
x' OR '1'='1 returns no rows, and a test proves it.Step 02 · 0:30 · Infographic
The second step creates the app, its command and its theme, and the first tab: the size of the model, the last run, the DAG of the run and the lineage of the warehouse, each with a table view.
views/app.py, cli.py (tcg-dataapp app), .streamlit/config.toml, pyproject.toml (extra app).
tcg-dataapp app open on port 8501, read-only?[C] Character
You are the same engineer, now also responsible for how the DataApp
explains itself. The audience is technical: the group, the professor and
the partner who will maintain the pipeline.
[R] Request
Create the Streamlit app and its first tab, the technical infographic.
1. views/app.py, started by a new command tcg-dataapp app [--port]
[--headless], which runs `python -m streamlit run` on the file of the
package. Streamlit and Altair go in an optional extra
(pip install -e '.[app]').
2. .streamlit/config.toml with the theme of the Inteli design system:
primaryColor #2f8f78, textColor #2e2640, secondaryBackgroundColor
#e6eaeb, borderColor #caced6, Inter and JetBrains Mono, radius
0.25rem, gatherUsageStats false.
3. At the top, a title, the version, the warehouse, the period of the
captures in UTC and one sentence built from headline(con).
4. Tab "Technical infographic":
- five st.metric: sets, cards, prices of the fact, captures, cells;
- one line on the last run (tasks ok, failed attempts, seconds);
- the DAG of the last run with st.graphviz_chart, the status and the
seconds written inside each box;
- the lineage grouped in three clusters (ETLs, Processors, Views), each
node with its rows and kind, tables drawn as cylinders;
- a "Table view" expander under each figure, and an alt text on each.
Facts measured on 08/11/2026 (confirm before use):
- Streamlit 1.67.0, Altair 6.3.0, DuckDB 2.0.0, Python 3.12.
- On the warehouse of the rehearsal the infographic shows 7 sets, 1,273
cards, 5,951 prices, 5 captures, 524 cells and 12 of 12 tasks ok.
[E] Example
"extract_products\nok · 7 s" inside the box of the task, with the border
in #2f8f78 when ok and in #2e2640 otherwise, so the status never depends
on the colour alone.
[A] Adjustments
- The app opens the warehouse read-only and only through views/dashboard.py.
- No KPI in colour, no gauge, no 3D: numbers in text, figures in the ink
and the greys of the palette, one accent.
- When the warehouse does not exist, the app says to run tcg-dataapp run
and stops.
[T] Type of output
The files and a screenshot of the first tab, with the command used.
[E] Extras
Show the plan before editing. Stop at the end.
A Streamlit app is a Python script that runs from top to bottom each time the user changes a widget. What must survive between runs is kept in st.session_state, and what is expensive is cached.
| Piece | In tcg-dataapp | Why |
|---|---|---|
st.cache_resource | the read-only connection to DuckDB | one connection for every run and every user |
st.session_state | the path of the drill-down | the click survives the rerun that it causes |
st.tabs | infographic, ranking, prices over time | one question per tab |
st.metric | sets, cards, prices, captures, cells | a headline number needs no chart |
st.graphviz_chart | the DAG and the lineage, from DOT text | the graph is generated, drawn in the browser |
.streamlit/config.toml | the palette and the fonts of the design system | the theme is configuration, not code |
[theme] base = "light" primaryColor = "#2f8f78" backgroundColor = "#ffffff" secondaryBackgroundColor = "#e6eaeb" textColor = "#2e2640" borderColor = "#caced6" baseRadius = "0.25rem" font = "Inter:https://fonts..." codeFont = "'JetBrains Mono':..." [browser] gatherUsageStats = false
The tab answers the questions of whoever maintains the DataApp: how large the model is, whether the last run worked, what runs in which order and which object reads which. Every number comes from the warehouse of the rehearsal, on 08/11/2026.
Twelve boxes, from extract_sets to write_report, each one with its status and its seconds written inside, for instance extract_products · ok · 7 s. The run took 25 seconds, and 12 of 12 tasks ended ok.
Thirteen objects in three clusters (ETLs, Processors, Views) and twenty edges. The landing table holds 7,448 records, the fact 5,951 rows and the frozen report of September 1,226; tables are cylinders, views are boxes.
Step 03 · 0:40 · Drill-down
The second tab ranks the groups of the frozen report or of the live view, lets a click on a bar descend the hierarchy set › rarity › card, and checks every view against the cube.
views/app.py (tab "Ranking and drill-down").
gold.agg_price_cube?[C] Character
You are the same engineer. The second tab repeats, in Streamlit, the
explorer of the lab of Lesson 6: ranked bars over the frozen report or the
live view, with drill-down and roll-up on the hierarchy set › rarity ›
card.
[R] Request
Tab "Ranking and drill-down" in views/app.py:
1. Controls in one row: source (frozen report of the last frozen month or
live view), measure (highest price, average price, market value,
number of prices) and four checkboxes to group by set, rarity, card and
variant.
2. Horizontal bars ranked from the largest value, in #2f8f78, with the
value written at the end of each bar and a tooltip; height of the
chart proportional to the number of groups.
3. Drill-down: a click on a bar (st.altair_chart with on_select="rerun"
and a point selection) keeps the values of the clicked bar as filters
and moves the grouping one level down the hierarchy. A row of buttons
(All sets, Set: ..., Rarity: ...) rolls up.
4. Under the chart: the number of groups, the source and its capture in
UTC, the result of cube_check in one sentence, a "Table view" expander
and an expander with the SQL and its parameters.
Facts measured on 08/11/2026 (confirm before use):
- Frozen report 2026-09, highest price by set: ME: Ascended Heroes
1,049.08, ME: 30th Celebration 1,000.00, ME05: Pitch Black 198.62;
5 groups, grouping_id 3, agrees with the cube.
- Drill into ME: Ascended Heroes: 9 rarities, the first Special
Illustration Rare at 1,049.08, grouping_id 1, 9 cells, agrees.
[E] Example
Click on "ME: Ascended Heroes" with dims = [set_name]:
path = [("set_name", "ME: Ascended Heroes")], dims = [rarity].
[A] Adjustments
- A widget state cannot change after the widget exists: store the click
as a pending change, call st.rerun() and apply it at the top of the tab.
- The key of the chart includes the depth of the path, so the selection of
the previous level does not fire again.
- One axis, one colour, no legend for a single series.
[T] Type of output
The changes and two screenshots: the top level and one drill-down.
[E] Extras
Show the plan before editing. Stop at the end.
The selection of a bar arrives after the checkboxes were drawn, and a widget cannot change once it exists in the run. The click is therefore stored as a pending change, the script runs again, and the change is applied at the top, before the widgets.
if "pending" in state: # applied before the widgets
state.path, dims_next = state.pop("pending")
for d in DIMENSIONS:
state[f"dim_{d}"] = d in dims_next
...
event = st.altair_chart(chart, on_select="rerun",
key=f"bars_..._{len(state.path)}")
picked = event.selection.get("pick")
if picked: # one level down
state.pending = (state.path + [("set_name", ...)], ["rarity"])
st.rerun()The depth of the path is part of the key, so the chart of the new level starts without the selection of the previous one, which would otherwise fire again.
Grouping by set rolls up rarity and variant, so the cube answers at grouping_id 2 + 1 = 3. The cube has no card, and a view by card has no check.
The frozen report of September, highest market price. The first level ranks the five sets that had prices on that capture; a click on ME: Ascended Heroes groups its cards by rarity, and both levels agree with the cube.
Step 04 · 0:50 · Time and accessibility
The last tab draws the prices over the captures with one series highlighted, converts the Unix time to a calendar day in UTC, and the step ends with an accessibility pass on the three tabs and a test of the whole app.
views/app.py (tab "Prices over time"), tests/test_app.py.
[C] Character
You are the same engineer, reviewing the app for the person who cannot
see a colour, reads with a screen reader or opens it on a Brazilian
laptop where the clock is three hours behind UTC.
[R] Request
1. Tab "Prices over time": a line chart of price_history, either the
market value of each set or the five most valuable cards of one set.
One series is highlighted in #2f8f78 (selectbox, the largest by
default) with points, a tooltip and its name written at the end of the
line; the others stay as thin lines in #caced6, as context. Below the
chart, one sentence with the first and the last value of the
highlighted series.
2. Dates: the warehouse keeps Unix time; the app converts it only when
drawing, with pd.to_datetime(unit="s", utc=True), an Altair scale of
type "utc" and the format %d/%m/%Y. The tooltip shows the Unix time too.
3. An accessibility pass on the three tabs: alt text on every chart and
graph, a table view under every figure, the status written in text,
no meaning carried by colour alone, contrast of the text against the
background, and no chart with two y axes.
4. tests/test_app.py with streamlit.testing.v1.AppTest over the fake
warehouse (skipped when Streamlit is not installed): the app renders
without exception, the metrics show 2 sets, 3 cards, 6 prices and
2 captures, and checking "Rarity" reruns without error.
Facts measured on 08/11/2026 (confirm before use):
- ME: 30th Celebration went from US$ 1,349.93 to US$ 12,403.41 of market
value between 01/09/2026 and 07/11/2026; on 07/11/2026 it holds 65.3%
of the value of the seven sets, and its Mew - R/RGB (Holofoil) is the
most valuable card at US$ 4,492.45.
- pytest: 22 tests pass in about 10 s, without network.
[E] Example
A capture at 1788220800 is 01/09/2026 00:00 UTC; drawn in local time in
São Paulo it would read 31/08/2026 21:00 and fall on the wrong day.
[A] Adjustments
- No rainbow of seven colours for seven sets: highlight and context.
- Write the sentence before choosing the chart: the chart supports it.
[T] Type of output
The changes, a screenshot of the tab and the output of pytest.
[E] Extras
Show the plan before editing. Stop at the end.
The warehouse keeps every date as Unix time in UTC. A browser in São Paulo formats a date in local time unless told otherwise, and 00:00 UTC becomes 21:00 of the previous day, so the September capture would be drawn in August.
hist["day"] = pd.to_datetime(hist["captured_at"],
unit="s", utc=True)
x = alt.X("day:T", title="Capture (UTC)",
scale=alt.Scale(type="utc"),
axis=alt.Axis(format="%d/%m/%Y"))| Unix time | UTC | São Paulo (UTC−3) |
|---|---|---|
1772323200 | 01/03/2026 00:00 | 28/02/2026 21:00 |
1788220800 | 01/09/2026 00:00 | 31/08/2026 21:00 |
1794009600 | 07/11/2026 00:00 | 06/11/2026 21:00 |
Accessibility asks whether a person who cannot see a colour, uses a screen reader or reads on a small screen gets the same conclusion. Ethics asks whether the conclusion is the one the data supports.
| Accessibility | In the app |
|---|---|
| meaning never in colour alone | status written in the box; names at the end of the line |
| alternative text | alt= on every Altair and Graphviz chart |
| the data behind the chart | a "Table view" under every figure |
| contrast | text in #2e2640 on white, 14.6:1 |
| one conclusion per view | a sentence with the number above the chart |
| Ethics | In the app |
|---|---|
| the scale starts at zero | every bar chart |
| source and date declared | table and capture in UTC under each chart |
| the period is not chosen to persuade | every capture is drawn |
| a set released on 16/09/2026 | its jump is the launch, not appreciation |
| the check is visible | the agreement with the cube and the SQL |
The queries are tested alone, over the fake warehouse of Lesson 7, and the whole app runs inside AppTest, which executes the script as Streamlit would and exposes its widgets. The 22 tests take about ten seconds.
| Test | What it proves |
|---|---|
test_the_connection_of_the_app_cannot_write | the view layer is read-only |
test_lineage_reads_the_catalogue_and_the_comment_of_the_frozen_table | the infographic comes from metadata |
test_explorer_drills_down_and_agrees_with_the_cube | the bars and the cube give the same numbers |
test_explorer_refuses_anything_outside_its_lists (4 cases) | no dimension or measure outside the lists |
test_a_filter_value_is_a_parameter_not_sql | a typed value never becomes SQL |
test_price_history_by_set_and_by_card | the series keep Unix time |
test_the_app_renders_every_tab_without_errors | the app runs, shows the metrics and reruns on a click |
| the 9 tests of Lesson 7 | the pipeline still works |
Each group adds a Streamlit app to the DataApp of the partner, in the views layer and in the same pattern, with prompt 05: the queries tested alone, a tab that explains the DataApp and two analytical views that answer questions of the partner.
AppTestReadings and videos assigned on Adalove for this week, on chart types and on building data apps in Streamlit, with the reading material of the session.
Twelve chart types in Streamlit, with customisation options and good practices.
Video introduction to building interactive data apps with Streamlit.
Layout, chart integration and user experience when building dashboards in Streamlit.
Chart selection, the execution model of Streamlit, the technical infographic, drill-down, time zones, accessibility and ethics, with the numbers of the rehearsal.
DataApp Technical Infographics · 10/12/2026 · Prof. Afonso
By the end of the session, students should be able to choose the chart that fits each question of the DataApp, build a Streamlit app in its views layer with a technical infographic generated from metadata and analytical views with drill-down over the gold layer, and review the app for accessibility, time zones and the ethics of the chart, first with the TCGplayer prices and then with the partner data.
Demonstration followed by application. In the first hour the professor builds the app live with a coding agent in four CREATE prompts (queries and metadata, technical infographic, ranking with drill-down, time and accessibility) over the package of Lesson 7, comparing each step with the reference package 0.5.0. In the second hour each group adds a Streamlit app to the DataApp of the partner with prompt 05.