# Converting long-format InfluxDB exports to FEDS

This note is a **draft recipe** for researchers who store fungal electrophysiology streams in InfluxDB (or similar time-series databases) and want a FEDS-shaped export. It is not normative; adjust for your lab workflow.

## Goals

- One FEDS recording → one `sub-*/signal/` folder with matching `*_signal.json`, `*_electrodes.tsv`, and `*_signal.tsv` or `*_signal.tsv.gz`.
- Voltages in the TSV are in **`VoltageUnit`**, not raw ADC counts.
- Timestamps in the TSV are **relative seconds** with monotonic non-decreasing values.

## 1. Select and sanitize tags

Influx exports often include tags such as `host`, `mac`, `ssid`, or device IDs. **Remove or hash identifying tags** before publishing a dataset. Keep only tags needed to map channels (e.g. `channel`, `electrode_pair`).

## 2. Pivot long → wide

Typical Influx long format:

| time | channel | value | …tags… |
|------|---------|-------|--------|

Pivot so each channel becomes a column:

| timestamp | ch_a | ch_b |
|-----------|------|------|

Convert `time` to **seconds relative to the first sample** (float). If the database stores nanoseconds, divide appropriately and document `TimestampSource` / `TimestampPrecisionSeconds` in `signal.json`.

## 3. Convert counts to volts

If `value` is still in ADC counts, multiply by your calibrated scale and write **`VoltageUnit`** in `signal.json`. Optionally record per-channel `counts_to_volts_scale` in `electrodes.tsv` for traceability.

## 4. Document gaps

If points are missing, leave the corresponding TSV cell **empty** (do not write `NaN` or `n/a`). Summarize dropouts in `GapSummary` on `signal.json` when you can compute it.

## 5. Write FEDS files

1. Root `dataset_description.json` with `FEDSVersion: "0.1"` and appropriate `DatasetType`.
2. `samples.tsv` listing each `sub-*` folder.
3. For each recording:
   - `*_signal.json` — nominal `SamplingFrequency`, units, channel count, transport, ADC metadata.
   - `*_electrodes.tsv` — one row per channel column.
   - `*_signal.tsv.gz` — pivoted wide table (UTF-8).

## 6. Validate

Run the Python CLI or the browser validator on the folder or a `.zip` archive before sharing.

## Open questions

- Standard tag names for multi-upstream Influx buckets.
- Whether to preserve original Influx line protocol as an optional extension file.
