|
| 1 | +# @klicker-uzh/export |
| 2 | + |
| 3 | +Standalone, **read-only** CLI that exports a single course's (or several courses') live-quiz data to CSV + XLSX for offline analysis. |
| 4 | + |
| 5 | +It is **not** imported by any app and **not** part of any deployment — it is run manually by an operator, on demand. The only production contact is pointing it at a read-only production `DATABASE_URL`. |
| 6 | + |
| 7 | +## Scope |
| 8 | + |
| 9 | +Exports **live-quiz data only**: |
| 10 | + |
| 11 | +- `LiveQuizResponse` — one row per response |
| 12 | +- `Participation` — enrolled participants |
| 13 | +- `ParticipantInvitation` — invitations |
| 14 | +- `AppliedPointCorrection` — lecturer point corrections (audit) |
| 15 | +- plus two dimension sheets: live quizzes and element instances |
| 16 | + |
| 17 | +It does **not** include practice-quiz / microlearning `QuestionResponse`, `QuestionResponseDetail`, or `GroupActivityInstance`. The scope (included/excluded models) is recorded in every export's `manifest.json` so a course with those activity types is not mistaken for "fully exported". |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +```bash |
| 22 | +# build the compiled binary (no tsx at runtime) |
| 23 | +pnpm --filter @klicker-uzh/export build |
| 24 | + |
| 25 | +# single course |
| 26 | +pnpm --filter @klicker-uzh/export export -- --courseId <uuid> [--outputDir <path>] [--pseudonymize] |
| 27 | + |
| 28 | +# multiple courses (also writes a combined workbook) |
| 29 | +pnpm --filter @klicker-uzh/export export -- --courseId <uuid1> --courseId <uuid2> |
| 30 | + |
| 31 | +# development (runs via tsx, no build step) |
| 32 | +pnpm --filter @klicker-uzh/export export:dev -- --courseId <uuid> |
| 33 | + |
| 34 | +# against production secrets (read-only URL) |
| 35 | +infisical run --env prd -- \ |
| 36 | + node packages/export/dist/scripts/export-course.js --courseId <uuid> --outputDir <path> |
| 37 | +``` |
| 38 | + |
| 39 | +Flags: |
| 40 | + |
| 41 | +- `--courseId <uuid>` — required, repeatable for multi-course export |
| 42 | +- `--outputDir <path>` — default `./export-output` |
| 43 | +- `--pseudonymize` — de-identify direct identifiers (see below) |
| 44 | + |
| 45 | +## Output |
| 46 | + |
| 47 | +``` |
| 48 | +<outputDir>/ |
| 49 | + <courseName>_<courseId>/ |
| 50 | + export.xlsx # 6 sheets, frozen header + per-column filters |
| 51 | + responses.csv |
| 52 | + participants.csv |
| 53 | + invitations.csv |
| 54 | + corrections.csv |
| 55 | + live_quizzes.csv |
| 56 | + element_instances.csv |
| 57 | + manifest.json # schema version, counts, scope, per-file SHA-256, data dictionary |
| 58 | + combined-export.xlsx # only when >1 course is exported |
| 59 | +``` |
| 60 | + |
| 61 | +Files are written `0600`, directories `0700`. |
| 62 | + |
| 63 | +### Sheets and join keys |
| 64 | + |
| 65 | +| Sheet | Join key | |
| 66 | +| ------------------- | -------------------------------------------------------------------- | |
| 67 | +| `RESPONSES` | `liveQuizResponseId` (PK); `elementInstanceId` → `ELEMENT_INSTANCES` | |
| 68 | +| `PARTICIPANTS` | `participantId` (PK) | |
| 69 | +| `INVITATIONS` | `participantId` | |
| 70 | +| `CORRECTIONS` | `liveQuizResponseId` + `elementBlockExecution` → `RESPONSES` | |
| 71 | +| `LIVE_QUIZZES` | `liveQuizId` (includes zero-response quizzes) | |
| 72 | +| `ELEMENT_INSTANCES` | `elementInstanceId` (full untruncated content + point config) | |
| 73 | + |
| 74 | +`RESPONSES` carries both the raw `response` JSON and flattened `response_choices` / `response_value` / `response_selection` / `response_assessment` columns so analysts can avoid parsing JSON. |
| 75 | + |
| 76 | +## Safety |
| 77 | + |
| 78 | +- **Read-only DB access** — `createReadonlyClient` narrows the Prisma client to read operations at compile time, and a runtime `$allOperations` guard blocks every non-read operation, including raw queries (`$queryRaw` / `$executeRaw` / `…Unsafe`). |
| 79 | +- **PII modes** — default `full` writes identifiers verbatim (with a loud stderr warning); `--pseudonymize` hashes email / SSO id+email / matriculation number (per-run HMAC-SHA256 salt, never persisted) and redacts free-text answers and raw response JSON. |
| 80 | +- **CSV** — UTF-8 BOM, one physical line per row (embedded newlines normalized), formula-injection escaping (`= + - @`). |
| 81 | +- **Integrity** — `manifest.json` records per-file SHA-256, counts, package version, PII mode, scope, and a data dictionary for the cryptic + flattened columns. |
| 82 | + |
| 83 | +Output directories contain PII and are gitignored. |
| 84 | + |
| 85 | +## Development |
| 86 | + |
| 87 | +```bash |
| 88 | +pnpm --filter @klicker-uzh/export check # tsc --noEmit |
| 89 | +pnpm --filter @klicker-uzh/export test # vitest |
| 90 | +pnpm --filter @klicker-uzh/export build # rollup -> dist/ + dist/scripts/export-course.js |
| 91 | +``` |
0 commit comments