minor UI fix, minot data processing improvements

This commit is contained in:
Антон
2026-01-09 21:05:02 +03:00
parent facde3b80e
commit de09326c38
5 changed files with 47 additions and 19 deletions

View File

@@ -193,7 +193,7 @@ class OpenVPNAPI:
# 1. Установка временных рамок
if not end_date:
end_date = datetime.now()
end_date = datetime.utcnow()
if not start_date:
start_date = end_date - timedelta(hours=24) # Дефолт - сутки
@@ -341,17 +341,24 @@ class OpenVPNAPI:
for _ in range(points_count):
current += timedelta(seconds=interval)
ts_str = current.strftime('%Y-%m-%d %H:%M:%S')
ts_iso = ts_str.replace(' ', 'T') + 'Z'
if ts_str in db_data_map:
final_data.append(db_data_map[ts_str])
item = db_data_map[ts_str].copy()
item['timestamp'] = ts_iso
final_data.append(item)
else:
final_data.append({
'timestamp': ts_str,
'timestamp': ts_iso,
'bytes_received': 0,
'bytes_sent': 0,
'bytes_received_rate_mbps': 0,
'bytes_sent_rate_mbps': 0
})
else:
for item in final_data:
if 'timestamp' in item and isinstance(item['timestamp'], str):
item['timestamp'] = item['timestamp'].replace(' ', 'T') + 'Z'
return {
'data': final_data,
@@ -475,7 +482,7 @@ class OpenVPNAPI:
# Post-processing: Zero Fill
analytics['global_history_24h'] = []
now = datetime.utcnow()
now = datetime.now(timezone.utc)
# Round down to nearest interval
ts_now = now.timestamp()
ts_aligned = ts_now - (ts_now % interval_seconds)
@@ -490,12 +497,15 @@ class OpenVPNAPI:
for _ in range(96):
current += timedelta(seconds=interval_seconds)
ts_str = current.strftime('%Y-%m-%d %H:%M:%S')
ts_iso = ts_str.replace(' ', 'T') + 'Z'
if ts_str in db_data:
analytics['global_history_24h'].append(db_data[ts_str])
item = db_data[ts_str].copy()
item['timestamp'] = ts_iso
analytics['global_history_24h'].append(item)
else:
analytics['global_history_24h'].append({
'timestamp': ts_str,
'timestamp': ts_iso,
'total_rx': 0,
'total_tx': 0,
'total_rx_rate': 0,

View File

@@ -35,7 +35,7 @@ class TimeSeriesAggregator:
conn = self.db_provider()
cursor = conn.cursor()
now = datetime.now()
now = datetime.utcnow()
# --- РАСЧЕТ ВРЕМЕННЫХ КВАНТОВ ---
# 1. Сутки (00:00:00)