> ## Documentation Index
> Fetch the complete documentation index at: https://playbook.smedleygroup.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Charging Export

> How an engineer exports charging data to STL from the track dashboard, and what the export does to the data on the way.

Charging data is the second of the two telemetry streams, and it behaves very differently from DAQ runs. It arrives continuously rather than per run, it is converted on the track machine rather than in AWS, and nothing converts it automatically. An engineer exports it by hand from the dashboard.

Getting the data in is covered by [The Charging Data Receiver](/software/developer/estate/systems/telemetry/receiver). This page is what happens to it afterwards.

> [!WARNING]
>
> InfluxDB is cleared at the end of each day. Charging data must therefore be exported before the day is stopped, or recovered afterwards by restoring that day's backup archive.

## Exporting To STL

Exporting is done from the [Telemetry Dashboard](/software/developer/estate/systems/telemetry/dashboard) on the track machine, which drives the [Exporter API](/software/developer/estate/systems/telemetry/exporter-api#charging-export) a call at a time. There is no scheduled job and no automatic trigger.

**1. Find the karts**

The dashboard asks which karts were charging in a time window, defaulting to a day from the start time.

**2. Resolve the export path**

The dashboard asks the API for the destination folder, passing the region, the event type and the timezone. The event type defaults to `Test` unless the dashboard says otherwise.

**3. List the runs**

For each kart, charging sessions are merged into runs, with any gap of five minutes or less treated as the same run. Runs shorter than a threshold, five minutes by default, are dropped. Each run is then divided into stints, though a stint is a full day, so in practice a run is one stint.

**4. Export each run**

The dashboard posts each run back to the API, which queries InfluxDB and writes the STL files to the local export folder.

**5. Sync to S3**

The dashboard calls the sync endpoint with the local path. That folder is uploaded to the telemetry bucket, and a Teams notification is posted saying whether it succeeded.

Runs are named `Run{NN}`, or `Run{NN}_Stint{NN}` where a run genuinely has more than one stint.

## What The Export Does To The Data

For each run the exporter:

* Queries InfluxDB for that kart over the run window, aggregated into **one second** windows
* Pivots measurements into columns, prefixing the battery name where there is one
* Reindexes onto a continuous one second grid and forward fills the gaps
* Looks up the kart's **battery spec** and applies the matching logging table, renaming each channel to its export name and applying its gain and offset
* Renames node columns to their export names
* Writes `{runName}_Tel.mat` and `{runName}_Info.mat` into `{export path}/{kart}/`

> [!NOTE]
>
> Charging data has no timing and no laps, so the export synthesises them. The run is written as a single lap, the kart takes the place of the driver, and the team is recorded as FKL. This is what lets SimTelLab open a charging run with the same tooling it uses for a racing run.

## How It Differs From DAQ Runs

| | DAQ runs | Charging runs |
| - | - | - |
| Trigger | Automatic, on upload to S3 | Manual, from the track dashboard |
| Converted where | An AWS Lambda | The track machine |
| Source data | The binary recorded by the DAQ unit | InfluxDB |
| Sample interval | 10 ms | 1 second |
| Laps | Split using TalentID timing | None. One synthetic lap per stint |
| Output folder | `RACING/OFFLOADED/EK{kart}/` | `CHARGING/RT/{kart}/` |

Both end up in the same place. See [The STL Database and SimTelLab](/software/developer/estate/systems/telemetry/stl-database).

## Key Files

| File | Role |
| - | - |
| `telemetry/telemetry-api/src/api.py` | The kart, run, export and sync endpoints the dashboard calls |
| `telemetry/telemetry-api/src/services/telemetry_exporter_service.py` | The export itself, including the InfluxDB query and the STL writing |
| `telemetry/telemetry-api/src/services/charging_run_service.py` | Merging charging sessions into runs |
| `telemetry/telemetry-api/src/services/stint_service.py` | Dividing a run into stints |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.