Files
NODEDC_MISSION_CORE/packages/router-ui/src/RouterRadioHistory.tsx
T
DCCONSTRUCTIONS a49fb00b8e feat(routers): integrate Banana Pi Client API and onboard LibreSpeed measurements
Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
2026-11-11 23:53:46 +03:00

22 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {useEffect,useState} from 'react';
import {Description,Select,SettingsCard} from '@nodedc/ui-react';
import {metric,simChannels,type RouterDevice,type RouterSnapshot} from './contracts';
import {collectRadio,radioChanges,radioMetrics,radioPath,radioSegments,type RadioHistory} from './radioHistory';
export function useRadioHistory(device:RouterDevice,value:RouterSnapshot,ready:boolean){
const [history,setHistory]=useState<RadioHistory>({key:'',day:0,samples:[]});
const key=`${value.runtime_id}:${device.id}:${device.client_api?.boot_id}:${JSON.stringify(device.slot_map)}`;
useEffect(()=>{setHistory(previous=>collectRadio(previous,key,device,ready,Date.now()/1000));},[key,device,ready]);
return history.key===key?history.samples:[];
}
export function RouterRadioHistory({device,samples}:{device:RouterDevice;samples:RadioHistory['samples']}){
const [field,setField]=useState<keyof typeof radioMetrics>('rsrp'),m=radioMetrics[field];
return <div className="router-form">
<Select label="История радиоканала" value={field} options={Object.entries(radioMetrics).map(([value,m])=>({value,label:m.label}))} onChange={s=>setField(s as keyof typeof radioMetrics)}/>
<Description>Последние пять минут, пока открыто окно роутера. Разрывы — пропуски измерений или смена диапазона/соты.</Description>
{simChannels(device).map(channel=>{const points=samples.filter(s=>s.slot===channel.slot),end=points.at(-1)?.at??0,last=points.at(-1),changes=radioChanges(points),valid=points.filter(p=>p[field]!=null).length;return <SettingsCard key={channel.slot} title={`${channel.label} · ${m.label}`} description={last?`${metric(last[field],m.unit)}${last.band?` · ${last.band}`:''}`:'Свежих измерений пока нет'}>
{valid>=2?<figure className="router-traffic-chart"><div className="router-scale-labels"><span>{m.max} {m.unit}</span><span>{m.min} {m.unit}</span></div><svg viewBox="0 0 320 82" preserveAspectRatio="none" role="img" aria-label={`${channel.label}: ${m.label} за пять минут`}><line x1="2" x2="318" y1="78" y2="78" className="router-chart-baseline"/><path d={radioPath(points,field,end)} className="router-chart-line router-chart-down"/>{radioSegments(points,field,end).filter(p=>p.length===1).map((p,i)=><circle key={i} cx={p[0].x} cy={p[0].y} r="1.5" className="router-chart-point-down"/>)}</svg><figcaption className="router-scale-labels"><span>−5 мин</span><span>{new Date(end*1000).toLocaleTimeString('ru-RU')}</span></figcaption></figure>:<Description>{valid===1?'Ожидание следующего измерения.':'Радиопоказателей для этой SIM пока нет.'}</Description>}
{changes.length?<ol className="router-events">{changes.map((c,i)=><li key={i}><time>{new Date(c.at*1000).toLocaleTimeString('ru-RU')}</time><span>{c.text}</span></li>)}</ol>:<Description>Смен диапазона или соты в непрерывных наблюдениях пока нет.</Description>}
</SettingsCard>;})}
</div>;
}