# Track QC, Statistics & HTML5 Reports

Tracking is only half the story — before trusting downstream statistics, you need to know *whether* every frame tracked cleanly, catch hidden 5-frame occlusion gaps, calibrate pixels to real physical units (`cm`, `cm/s`), and export reproducible reports your collaborators can open in any web browser.

Annolid unifies all of this in **Analysis & Reporting Studio** (`Ctrl+Shift+R`), the **`annolid-run`** CLI, and **Annolid Bot** (`/qc`, `/stats`, `/report`).

## The Six Integrated Tabs of Analysis & Reporting Studio

Open **`Analysis → Analysis & Reporting Studio…`** (`Ctrl+Shift+R`) in the Annolid desktop app (or click **`Studio…`** from the Behavior Log dock). All computations run on background worker threads so your video canvas never freezes:

| Tab | What It Computes | Interactive Workflow |
| --- | --- | --- |
| **1. Unified Report** | Self-contained `analysis_report.html` (inline SVG trajectories, ethograms, zone bars, freezing), `.md`, and `.json` | One-click publication-ready summary |
| **2. Track QC & Gaps** | Audits CSVs or JSON folders for velocity spikes, missing-frame gaps, area jumps, pose bone stretch & ID swaps | **Double-click any alert** to jump the main video canvas directly to that frame |
| **3. Kinematics & Freezing** | Distance, speed (`px/s` or calibrated `cm/s`), straightness, freezing & high-activity bouts, pairwise social distance | Supports scalar `px_per_cm` or $3\times 3$ perspective homography |
| **4. Behavior & Ethogram QC** | Interval-union time budgets, binned trajectories, unpaired start/stop & mutually-exclusive ethogram checks | Catches logging mistakes before stats |
| **5. Inter-Rater Reliability (IRR)** | Cohen's $\kappa$ (bootstrap 95% CI), Fleiss' $\kappa$, Krippendorff's $\alpha$, PABAK, bout F1 & disagreement windows | Jump straight to disagreement bouts for adjudication |
| **6. Cohort & Transitions** | Welch $t$, Mann-Whitney $U$, ANOVA/Kruskal-Wallis, Hedges' $g$, Cliff's $\delta$, Kaplan-Meier survival, BH-FDR $q$, Markov transitions | Recording-level or subject-level experimental units |

## Visual Tour: What `annolid-run report` Produces

Running a single command on the 4,881-frame `mouse083` resident-intruder session generates a complete interactive HTML5 + inline SVG report with zero external web dependencies:

```{figure} ../images/showcase/mouse083_report_preview.png
---
name: reporting-html-preview
alt: Preview of Annolid's live self-contained HTML5 and inline SVG report showing quality gate, coverage table, and prioritized Track QC review queue
width: 96%
---
Self-contained HTML5 report generated by `annolid-run report`, highlighting the prioritized manual review queue and frame-level coverage ([open live interactive example](https://annolid.com/portal/assets/reports/mouse083_report.html)).
```

```{figure} ../images/showcase/mouse083_behavior_storyboard.png
---
name: reporting-qc-storyboard
alt: Four-panel storyboard highlighting how Track QC detects a 5-frame intruder occlusion dropout during a mounting bout
width: 96%
---
Panel D illustrates why automated Track QC matters: a brief 5-frame occlusion (`frames 3361–3366`) is immediately surfaced and ranked instead of silently biasing distance or interaction metrics.
```

## Essential CLI Commands (`annolid-run`)

### 1. Unified HTML5 + SVG + Markdown + JSON Report

```bash
annolid-run report session_tracked.csv \
  --events-csv session_events.csv \
  --zone-file session_zones.json \
  --schema project.annolid.json \
  --fps 30 \
  --px-per-cm 12.5 \
  --title "Resident-Intruder Assay — Cohort A" \
  --output-dir ./session_report
```

### 2. Track QC & Prioritized Review Queue

```bash
annolid-run track-qc session_tracked.csv \
  --expected-instances 2 \
  --fps 30 \
  --review-csv review_queue.csv \
  --out track_qc.json
```

### 3. Calibrated Kinematics (Scalar Scale or Perspective Homography)

Use `--px-per-cm` for top-down cameras, or `--calibration arena_cal.json` for angled cameras using full $3 \times 3$ planar perspective homography:

```bash
annolid-run kinematics session_tracking.csv \
  --fps 30 \
  --calibration arena_calibration.json \
  --output-dir ./kinematics_out \
  --events-csv kinematics_bouts.csv
```

### 4. Inter-Rater Reliability (IRR) & Cohort Statistics

```bash
# Compare two or more human/AI raters with bootstrap 95% CIs
annolid-run behavior-irr rater1.csv rater2.csv \
  --bin-seconds 0.1 \
  --disagreements-csv disagreements.csv \
  --out irr_report.json

# Run multi-recording cohort comparisons with FDR correction and transition diagrams
annolid-run behavior-cohort ./cohort_manifest.json \
  --unit recording \
  --session-duration 600 \
  --summary-csv cohort_summary.csv \
  --comparisons-csv cohort_comparisons.csv \
  --transitions-svg cohort_transitions.svg \
  --out cohort_report.json
```

## Quick Chat Shortcuts in Annolid Bot

Prefer typing a one-liner inside the Annolid GUI? Open **Annolid Bot** and run:

```text
/qc /path/to/session_tracked.csv
/stats /path/to/session_tracked.csv px_per_cm=12.5
/report /path/to/session_tracked.csv px_per_cm=12.5
```

```{tip}
**Experimental unit reminder:** In dyadic or group-housed cages (`resident` + `intruder`), animals in the same cage share variance. Use `--unit recording` in `annolid-run behavior-cohort` so each recording acts as an independent statistical unit. See the full [Reporting & Statistics Reference](https://annolid.com/portal/reporting_and_statistics/) on the Docs Portal.
```
