Prepare events for BI

Convert saved JSON pages to CSV, remove exact duplicates and count events by camera.

BOX 3.x event-list format · Runs locally

What you will get

Four unique events from two files, a CSV for BI import and a summary by camera and event type.

Requirements

  • Python 3.9 or later; no third-party libraries.
  • The extracted ZIP includes all input data. BOX access is not required for the local exercise.

Run the example

python3 export_events.py sample-page-1.json sample-page-2.json --config mapping.json --output events.csv
python3 summarize.py events.csv --output summary.csv
python3 check_example.py

Expected output

{"duplicates_skipped": 1, "rows": 4}
CameraEvent typeCount
Camera 1no_helmet2
Camera 2no_helmet1
Camera 2vehicle1

All statuses are included: confirmed, unreviewed and rejected. These are record counts, not counts of confirmed violations.

Checks included

  • The CSV matches the reference file, and the summary contains the expected counts.
  • Exact duplicates are skipped; two different versions of the same event stop processing.
  • Missing fields are detected before CSV output is written. Text that resembles a spreadsheet formula is escaped.
  • The optional API client is tested with mocked HTTPS responses: GET, Bearer authentication, TLS settings, errors, timeout, blocked redirects and no overwrite.

Scope and limitations

  • The events wrapper is documented. The demo_* fields and statuses inside these sample events are synthetic; adapt mapping.json to your installation's schema.
  • The optional fetch_events.py retrieves one explicitly selected page. It does not verify completeness across a period or all pages.
  • Export and API-client tests run locally with mocked transport. A TLS connection to BOX, actual permissions, build compatibility and BI import require separate checks.

Use it with your data

  • Import events.csv into BI: rows = Camera, columns = Type, value = count of ID.
  • Compare the summary with the table here. Then apply Status = confirmed; two records remain.
  • Optionally retrieve one API page: check Swagger, set BOX_ORIGIN and BOX_ACCESS_TOKEN in the environment, then run python3 fetch_events.py --page 1 --page-size 20 --output raw-page-1.json. HTTPS certificate verification is enabled. See the README for complete commands and diagnostics.
  • Adapt a copy of mapping.json to the actual response fields and pass raw-page-1.json to export_events.py. Replace the training demo_* paths using the server schema.

Files and source code

Related documentation