# Telemetry inspector

Inspect rooftop temperature and wind readings over three time windows.

[View Telemetry inspector on CyberSpec](https://www.cyberspec.dev/sink/telemetry-inspector)

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/telemetry-inspector.json
```

## Usage

```tsx
import { Cyber } from "@/components/ui/cyber"
import Recipe from "@/components/recipes/telemetry-inspector"

export default function App() {
  return (
    <Cyber>
      <Recipe />
    </Cyber>
  )
}
```

## Source

```tsx
"use client"

import { useState } from "react"
import { Readout } from "@/components/ui/readout"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { SignalGraph } from "@/components/ui/signal-graph"
import "./recipe-layout.css"

const channels = {
  Thermal: { unit: "°C", samples: [16, 16, 15, 15, 16, 18, 22, 23, 26, 28, 27, 25, 23, 24, 23, 22, 21, 19, 18, 18, 17, 16, 16, 15] },
  Wind: { unit: "km/h", samples: [4, 7, 8, 6, 4, 5, 7, 11, 10, 6, 5, 7, 14, 18, 11, 13, 8, 6, 5, 8, 6, 5, 4, 3] },
}
type Channel = keyof typeof channels

export default function TelemetryInspector() {
  const [channel, setChannel] = useState<Channel>("Thermal")
  const [period, setPeriod] = useState("24 h")
  const { unit, samples } = channels[channel]
  const window = samples.slice(-parseInt(period, 10))
  const mean = window.reduce((sum, value) => sum + value, 0) / window.length
  return (
    <div className="sink-stack">
      <SegmentedControl<Channel> label="Rooftop sensor" options={["Thermal", "Wind"]} fill value={channel}
        onValueChange={next => next && setChannel(next)} />
      <SignalGraph label={channel === "Thermal" ? "Air temperature" : "Wind speed"} unit={unit} data={window}
        min={0} max={channel === "Thermal" ? 32 : 20} variant={channel === "Wind" ? "bars" : "line"} />
      <div className="sink-row" style={{ gap: "12px 30px" }}>
        <Readout label="Low" size="sm" unit={unit} value={Math.min(...window)} />
        <Readout label="Mean" size="sm" unit={unit} value={mean} precision={1} />
        <Readout label="High" size="sm" unit={unit} value={Math.max(...window)} tone="flag" />
      </div>
      <SegmentedControl label="History" options={["6 h", "12 h", "24 h"]} value={period}
        onValueChange={next => next && setPeriod(next)} />
    </div>
  )
}
```

## Components in this recipe

- [Signal graph](https://www.cyberspec.dev/components/sidebar/signal-graph.md) — A compact live graph, as a trace or a spectrum, with a text summary.
- [Segmented control](https://www.cyberspec.dev/components/sidebar/segmented-control.md) — A row of segments with an indicator that slides to the choice.
- [Readout](https://www.cyberspec.dev/components/sidebar/readout.md) — A large numeral with a unit and a label that counts to its new value when it changes.

## Resources

- [All kitchen sink recipes](https://www.cyberspec.dev/sink.md)
- [Recipe source on GitHub](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/telemetry-inspector.tsx)
- [Recipe layout stylesheet](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/recipe-layout.css)
- [Shadcn registry item](https://www.cyberspec.dev/r/telemetry-inspector.json)
