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.pyExpected output
{"duplicates_skipped": 1, "rows": 4}| Camera | Event type | Count |
|---|---|---|
| Camera 1 | no_helmet | 2 |
| Camera 2 | no_helmet | 1 |
| Camera 2 | vehicle | 1 |
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
README.md— View fileCommands, BI import, field mapping and scopefetch_events.py— View sourceOptional HTTPS GET of one API pageexport_events.py— View sourceJSON-to-CSV conversion and deduplicationsummarize.py— View sourceCSV grouping by camera and event typemapping.json— View fileConfigurable field mappingsample-page-1.json— View fileFirst synthetic data pagesample-page-2.json— View fileSecond page with one duplicateexpected.csv— View fileReference output: four eventsexpected-summary.csv— View fileReference grouped countscheck_example.py— View sourceResult and error checkscheck_fetch.py— View sourceAPI-client checks with mocked responses and no network access
