3.2 KiB
3.2 KiB
Training Event Simulator
Command line utility for pushing mock training_stream_events data into Supabase. Use it to drive the 体育课训练 dashboard with realistic telemetry while the real gateway is offline.
Features
- Generates ACK + telemetry + summary events aligned with the new
training_stream_eventstable. - Supports JSON/CSV roster files or inline
student_id:device_idlists. - Adjustable intervals, cycle counts, ingest labels, and dry-run mode.
- Works with Supabase service-role or any key that passes RLS inserts.
Prerequisites
-
Node.js 18+
-
An
.envfile containing:SUPABASE_URL=https://your-project.supabase.co SUPABASE_SERVICE_ROLE_KEY=your-service-role-keyThe service-role key is recommended so that inserts bypass RLS issues in test environments.
-
The
training_stream_eventstable and RLS policies provisioned (seecreate_training_stream_events.sql).
Install
cd scripts/training-event-simulator
npm install
This generates a local package-lock.json and installs @supabase/supabase-js plus dotenv.
Roster input formats
JSON array
[
{ "student_id": "d8f0f3b9-...", "device_id": "6f9f64f5-...", "name": "张三" },
{ "student_id": "9da97787-...", "device_id": "350f86fb-...", "name": "李四" }
]
CSV / line-based (student_id,device_id,name)
d8f0f3b9-...,6f9f64f5-...,张三
9da97787-...,350f86fb-...,李四
Inline CLI list (student_id:device_id)
node simulate-training-events.mjs --class-id 9c5d... --students d8f0f3b9-...:6f9f64f5-...,9da97787-...:350f86fb-...
Usage
node simulate-training-events.mjs --class-id 9c5d5e1d-... --roster ./roster.json --interval 5 --cycles 12
Key options:
--class-id <uuid>: required class identifier.--training-id <uuid>: override the generated training session ID.--roster <path>: JSON/CSV roster file (required unless--studentsis used).--students stu:dev,...: inline roster string.--interval <seconds>: seconds between telemetry batches (default 5).--cycles <n>: number of telemetry batches (default 12).--no-ack: skip the initial ACK events.--dry-run: log payloads without inserting.--source <label>/--note <text>: annotateingest_source&ingest_note.--env <path>: custom.envfile.--supabase-url/--supabase-key: override env variables.
To install the utility globally (optional):
npm install --global .
simulate-training-events --class-id ... --roster ...
Typical workflow
- Ensure the Supabase table & policies are deployed.
- Prepare a roster JSON from your test dataset.
- Run the simulator with the class ID & training ID you want to monitor.
- Open the 体育课训练页面 (teacher dashboard) and subscribe to the generated training ID.
Troubleshooting
- RLS failures: verify the key has insert rights. Service-role should always work.
- Foreign key errors: confirm
student_id,device_id, andclass_idexist inak_users,ak_devices, andak_classesrespectively. - ETIMEDOUT / network: check outbound access to
SUPABASE_URLfrom your environment.
Happy simulating! 🎽