Files
OpenVPN-Monitoring-Simple/deploy/ui-dist/assets/useTrafficChart-69f2EcZB.js
T
ayurishchevandClaude Sonnet 5.5 b3466f9c61 History and Analytics: average speed from bytes for periods over 24 hours
The aggregate tables (stats_*) keep only bytes, and the queries returned 0 as speed, so the Speed
mode was empty for 7d and 30d. Speed is now the bucket average: bytes * 8 / 1e6 / bucket seconds;
for the current incomplete bucket the duration is min(bucket length, time since its start), at least
1 s. Series are labelled "RX Mbps (avg)" / "TX Mbps (avg)" for ranges over 24h. One test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KC7BXv32Jwj8mY5sKX8u2F
2026-10-07 14:28:02 +03:00

2 lines
2.1 KiB
JavaScript

import{C as p,r as v}from"./vendor-charts-Bcjh2pZL.js";import{u as T}from"./useFormatters-CKGG-YVI.js";import{c as k}from"./index-BfAhXdi6.js";p.register(...v);const L="#1652B8",M="#EC7C31",_=1024*1024,S=()=>{const e=document.documentElement.getAttribute("data-theme")==="dark";return{isDark:e,gridColor:e?"rgba(240, 246, 252, 0.1)":"rgba(0,0,0,0.05)",textColor:e?"#8b949e":"#6c757d"}},A=(e,o)=>{if(!e||e.length===0)return[];if(e.length<=o)return e;const u=Math.ceil(e.length/o),n=[];for(let a=0;a<e.length;a+=u){const l=e.slice(a,a+u);if(l.length===0)continue;let m=0,c=0,s=0,t=0;l.forEach(r=>{m+=r.bytes_received||0,c+=r.bytes_sent||0,s=Math.max(s,r.rx_rate_mbps||0),t=Math.max(t,r.tx_rate_mbps||0)}),n.push({timestamp:l[0].timestamp,bytes_received:m,bytes_sent:c,rx_rate_mbps:s,tx_rate_mbps:t})}return n},B=e=>{const o=/^(\d+)([hd])$/.exec(e||"");return o?Number(o[1])*(o[2]==="d"?24:1)>24:!1};function D(e,{maxPoints:o}){const{parseServerDate:u}=T();let n=null;const a=()=>{n&&(n.destroy(),n=null)},l=(c,s)=>{const t=u(c),r=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return s.includes("h")||s==="1d"?r:t.toLocaleDateString([],{month:"short",day:"numeric"})+" "+r},m=(c,{range:s,speedMode:t})=>{if(!e.value)return;a();const r=[],d=[],b=[];A(c,o).forEach(i=>{r.push(l(i.timestamp,s)),t?(d.push(i.rx_rate_mbps||0),b.push(i.tx_rate_mbps||0)):(d.push(i.bytes_received/_),b.push(i.bytes_sent/_))});const{gridColor:h,textColor:g}=S(),x=B(s)?" (avg)":"",f=(i,C,R,y)=>({label:i,data:C,borderColor:R,backgroundColor:y,borderWidth:2,fill:!0,tension:.3,pointRadius:3,pointHoverRadius:4});n=new p(e.value.getContext("2d"),{type:"line",data:{labels:r,datasets:[f(t?`RX Mbps${x}`:"Received (MB)",d,L,"rgba(22, 82, 184, 0.15)"),f(t?`TX Mbps${x}`:"Sent (MB)",b,M,"rgba(236, 124, 49, 0.15)")]},options:{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{labels:{color:g}}},scales:{x:{ticks:{color:g,maxTicksLimit:8},grid:{color:h}},y:{beginAtZero:!0,ticks:{color:g},grid:{color:h}}}}})};return k(a),{render:m,destroy:a}}export{L as C,M as a,S as g,D as u};