Build a one-page static report from the data

applied · 60 min · Objective 4.2

Task

Generate a one-page HTML report from the practice data with a script: three headline figures, a table by region, and a line saying when the data was taken and from where. Then check that the table adds up to the headline.

Steps

  1. Calculate the number of valid orders, their net revenue and the median order's net value, and each region's valid orders and net revenue.
  2. Write lab/report/build.py to generate lab/report/report.html with an <h1>; three elements <div class="kpi" data-name="NAME">VALUE</div> named orders, net_revenue and median_order, money to two decimal places; and a <table> with one row per region, written as <tr class="region"><td>REGION</td><td>ORDERS</td><td>REVENUE</td></tr>.
  3. End the page with <p class="as-of">Data as of TIMESTAMP from data/orders.csv</p>.
  4. Run the script twice, and confirm the figures do not change.

Verify

These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.

grep -o 'data-name="[a-z_]*">[0-9.]*' lab/report/report.html
grep -c '<tr class="region"' lab/report/report.html
grep -o 'class="as-of">[^<]*' lab/report/report.html
python3 -c "import re; t = open('lab/report/report.html').read(); print('regions sum to', round(sum(float(x) for x in re.findall('<tr class=.region.><td>[A-Za-z]+</td><td>[0-9]+</td><td>([0-9.]+)', t)), 2))"

1997 orders, 354627.14 of net revenue and a median order of 99.21, four region rows, and an as-of line. The regions sum to 354627.13 -- a cent short, because each region was rounded before it was added. Anyone who totals the table will find that cent, so a report either says its figures are rounded or rounds only once.

This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.