/ concept-collection / timeseries-compressibility
Sign in
concept-collection / timeseries-compressibility
timeseries-compressibility / src / components / TrueRateCommand.tsx
74 lines · 2.0 KBBlameHistoryRaw
1import { useState } from 'react'
2import type { FilterSpec } from '../model/filters'
4/** The scripts/true_rate.py invocation matching the current parameters. */
5export function trueRateCommand(
6 sigma: number,
7 spec: FilterSpec,
8 sampleRateHz: number,
9 dither: boolean,
10): string {
11 const parts = ['python scripts/true_rate.py', `--sigma ${sigma}`]
12 switch (spec.family) {
13 case 'none':
14 parts.push('--filter none')
15 break
16 case 'firstDifference':
17 parts.push('--filter first-difference')
18 break
19 case 'movingAverage':
20 parts.push('--filter moving-average', `--width ${spec.width}`)
21 break
22 case 'lowpass':
23 parts.push(
24 '--filter lowpass',
25 `--cutoff-hz ${spec.highHz}`,
26 `--taps ${spec.taps}`,
27 `--sample-rate ${sampleRateHz}`,
28 )
29 break
30 case 'bandpass':
31 parts.push(
32 '--filter bandpass',
33 `--low-hz ${spec.lowHz}`,
34 `--high-hz ${spec.highHz}`,
35 `--taps ${spec.taps}`,
36 `--sample-rate ${sampleRateHz}`,
37 )
38 break
39 }
40 if (dither) parts.push('--dither')
41 return parts.join(' ')
44/**
45 * The Monte Carlo cross-check, as a copy-pasteable command. The script
46 * estimates the true entropy rate (docs/mc-true-rate.md) so the dashed R can
47 * be compared against ground truth for the current parameters.
48 */
49export default function TrueRateCommand(props: {
50 sigma: number
51 spec: FilterSpec
52 sampleRateHz: number
53 dither: boolean
54}) {
55 const [copied, setCopied] = useState(false)
56 const command = trueRateCommand(props.sigma, props.spec, props.sampleRateHz, props.dither)
57 return (
58 <div className="cli-row">
59 <span className="cli-label">check R by Monte Carlo:</span>
60 <code>{command}</code>
61 <button
62 className="copy-btn"
63 onClick={() => {
64 navigator.clipboard.writeText(command).then(() => {
65 setCopied(true)
66 setTimeout(() => setCopied(false), 1500)
67 })
68 }}
69 >
70 {copied ? 'copied ✓' : 'copy'}
71 </button>
72 </div>
73 )
moveopenescclose