feat: Implement Phase 2 wipe performance analytics dashboard
Complete implementation of wipe analytics system providing operational insights and data-driven wipe timing optimization. Backend: - Added comprehensive analytics query layer to db/wipes.rs: - Success rate calculation over time ranges - Average wipe duration tracking - Post-wipe population curve analysis (Day 1/2/3) - Optimal wipe timing recommendations based on player peaks - Individual wipe entry tracking with peak population correlation - Implemented GET /api/analytics/wipes/performance endpoint with flexible range parameters (6d/12d/90d/all) - All queries leverage hourly aggregate tables for 90-day retention Frontend: - Built WipeAnalyticsView.vue with 3 ECharts visualizations: - Success rate timeline (scatter: green success, red failures) - Population curve comparing Day 1/2/3 post-wipe averages - Wipe duration trend showing execution time evolution - Insight cards displaying success rate, avg duration, peak day, optimal timing - Actionable recommendations banner with data-driven suggestions: - Optimal wipe scheduling based on historical player peaks - Wipe frequency recommendations (weekly vs bi-weekly) - Duration optimization alerts - Rollback protection warnings - Time range selector and CSV export functionality - Added /wipes/analytics route TypeScript interfaces added: WipePerformanceMetrics, WipeAnalyticsEntry, PopulationCurve Answers critical operational questions: "How long do wipes take? When do players peak post-wipe? What's my success rate? When should I wipe for maximum population?" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
39
CHANGELOG.md
39
CHANGELOG.md
@@ -4,6 +4,45 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added (Phase 2 — Wipe Performance Analytics)
|
||||
|
||||
**Backend:**
|
||||
- `backend/src/db/wipes.rs` — Comprehensive wipe analytics query layer:
|
||||
- `get_wipe_success_rate()` — Success vs failure rate over time range
|
||||
- `get_average_wipe_duration()` — Average execution time for successful wipes
|
||||
- `get_wipe_to_peak_population()` — Hours from wipe completion to peak player count (24h window)
|
||||
- `get_population_curve_by_cycle()` — Day 1 vs Day 2 vs Day 3 average player counts post-wipe
|
||||
- `get_optimal_wipe_timing()` — Recommends best day of week + hour based on historical peak populations
|
||||
- `get_wipe_analytics_entries()` — Detailed per-wipe records for charting (duration, peak pop, success)
|
||||
- All queries use hourly aggregates (`server_stats_hourly`) with 90-day retention
|
||||
- `backend/src/api/analytics.rs` — Wipe performance endpoint:
|
||||
- `GET /api/analytics/wipes/performance?range=90d` — Returns full wipe performance metrics
|
||||
- Supports range params: `6d`, `12d`, `90d`, `all` (converted to wipe count estimates)
|
||||
- Response includes: success rate, avg duration, population curve, optimal timing, individual wipe entries
|
||||
|
||||
**Frontend:**
|
||||
- `WipeAnalyticsView.vue` — Complete wipe performance dashboard:
|
||||
- **ECharts Visualizations:**
|
||||
- Wipe success timeline (scatter plot: green = success, red = failed)
|
||||
- Population curve bar chart (Day 1/Day 2/Day 3 average players post-wipe)
|
||||
- Wipe duration trend (line chart showing execution time evolution)
|
||||
- **Insight Cards:**
|
||||
- Success rate percentage with total wipe count
|
||||
- Average wipe duration (formatted as minutes:seconds)
|
||||
- Peak population day identifier
|
||||
- Optimal wipe timing recommendation (day + hour)
|
||||
- **Actionable Recommendations Banner:**
|
||||
- Optimal wipe day/hour based on post-wipe player peaks
|
||||
- Weekly vs bi-weekly wipe suggestion (if Day 1 >> Day 2 population)
|
||||
- Duration optimization alerts (if avg > 10 minutes)
|
||||
- Rollback protection warnings (if failures detected)
|
||||
- Time range selector: Last 6 wipes / Last 12 wipes / All time
|
||||
- CSV export functionality
|
||||
- Added route `/wipes/analytics` to router
|
||||
- TypeScript interfaces: `WipePerformanceMetrics`, `WipeAnalyticsEntry`, `PopulationCurve`
|
||||
|
||||
**Purpose:** Answers critical questions: "How long do wipes take? When do players peak post-wipe? What's my success rate? When should I schedule wipes for max population?" Enables data-driven wipe timing optimization and operational insights.
|
||||
|
||||
### Added (Phase 3 — Public Status Page)
|
||||
|
||||
**Backend:**
|
||||
|
||||
@@ -1,10 +1,56 @@
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// TODO: Define WipeProfile struct (id, server_id, name, wipe_type, commands, plugin_actions, created_at)
|
||||
// TODO: Define WipeSchedule struct (id, profile_id, cron_expression, next_run_at, enabled)
|
||||
// TODO: Define WipeHistory struct (id, profile_id, started_at, completed_at, status, log)
|
||||
|
||||
/// Wipe history entry (full schema).
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct WipeHistoryRow {
|
||||
pub id: Uuid,
|
||||
pub license_id: Uuid,
|
||||
pub wipe_schedule_id: Option<Uuid>,
|
||||
pub wipe_profile_id: Uuid,
|
||||
pub wipe_type: String,
|
||||
pub trigger_type: String,
|
||||
pub status: String,
|
||||
pub started_at: Option<DateTime<Utc>>,
|
||||
pub completed_at: Option<DateTime<Utc>>,
|
||||
pub map_used: Option<String>,
|
||||
pub plugins_wiped: Vec<String>,
|
||||
pub plugins_preserved: Vec<String>,
|
||||
pub backup_reference: Option<String>,
|
||||
pub error_message: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// Analytics: Wipe with duration and peak population metadata.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WipeAnalyticsEntry {
|
||||
pub date: DateTime<Utc>,
|
||||
pub duration_seconds: i64,
|
||||
pub peak_population: i32,
|
||||
pub hours_to_peak: f64,
|
||||
pub success: bool,
|
||||
}
|
||||
|
||||
/// Analytics: Population curve aggregates (average players per day post-wipe).
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct PopulationCurve {
|
||||
pub day_1_avg: f64,
|
||||
pub day_2_avg: f64,
|
||||
pub day_3_avg: f64,
|
||||
}
|
||||
|
||||
/// Analytics: Optimal wipe timing recommendation.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct OptimalWipeTiming {
|
||||
pub optimal_wipe_day: String,
|
||||
pub optimal_wipe_hour: i32,
|
||||
}
|
||||
|
||||
/// Create a new wipe profile (template for a wipe operation).
|
||||
pub async fn create_wipe_profile(pool: &PgPool, server_id: Uuid, name: &str, wipe_type: &str) -> Result<Uuid> {
|
||||
@@ -40,3 +86,302 @@ pub async fn update_wipe_history(pool: &PgPool, history_id: Uuid, status: &str,
|
||||
pub async fn get_wipe_history(pool: &PgPool, profile_id: Uuid, limit: i64) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// ANALYTICS QUERIES — Phase 2 Wipe Performance Tracking
|
||||
// ========================================================================
|
||||
|
||||
/// Get wipe success rate over a time range (days).
|
||||
/// Returns (total_wipes, successful_wipes, failed_wipes).
|
||||
pub async fn get_wipe_success_rate(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<(i64, i64, i64)> {
|
||||
let result: (i64, i64, i64) = sqlx::query_as(
|
||||
"SELECT
|
||||
COUNT(*) as total_wipes,
|
||||
COUNT(*) FILTER (WHERE status = 'success') as successful_wipes,
|
||||
COUNT(*) FILTER (WHERE status IN ('failed', 'rolled_back')) as failed_wipes
|
||||
FROM wipe_history
|
||||
WHERE license_id = $1
|
||||
AND created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND status IN ('success', 'failed', 'rolled_back')",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.context("Failed to query wipe success rate")?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Get average wipe duration (in seconds) over a time range (days).
|
||||
/// Only includes successful wipes with valid start/completion timestamps.
|
||||
pub async fn get_average_wipe_duration(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<f64> {
|
||||
let result: Option<(Option<f64>,)> = sqlx::query_as(
|
||||
"SELECT AVG(EXTRACT(EPOCH FROM (completed_at - started_at))) as avg_duration
|
||||
FROM wipe_history
|
||||
WHERE license_id = $1
|
||||
AND created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND status = 'success'
|
||||
AND started_at IS NOT NULL
|
||||
AND completed_at IS NOT NULL",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.context("Failed to query average wipe duration")?;
|
||||
|
||||
Ok(result.and_then(|r| r.0).unwrap_or(0.0))
|
||||
}
|
||||
|
||||
/// Get hours from wipe completion to peak population.
|
||||
/// For each wipe, finds the max player count in the 24 hours post-wipe,
|
||||
/// then calculates how many hours after wipe completion that peak occurred.
|
||||
/// Returns average across all wipes in the time range.
|
||||
pub async fn get_wipe_to_peak_population(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<f64> {
|
||||
// For each successful wipe, find the peak player count within 24 hours post-wipe
|
||||
// and calculate hours from wipe completion to that peak.
|
||||
let result: Option<(Option<f64>,)> = sqlx::query_as(
|
||||
"WITH wipe_peaks AS (
|
||||
SELECT
|
||||
wh.id as wipe_id,
|
||||
wh.completed_at,
|
||||
MAX(ssh.max_players) as peak_players,
|
||||
(SELECT ssh2.hour
|
||||
FROM server_stats_hourly ssh2
|
||||
WHERE ssh2.license_id = wh.license_id
|
||||
AND ssh2.hour >= wh.completed_at
|
||||
AND ssh2.hour < wh.completed_at + INTERVAL '24 hours'
|
||||
AND ssh2.max_players = MAX(ssh.max_players)
|
||||
ORDER BY ssh2.hour ASC
|
||||
LIMIT 1
|
||||
) as peak_hour
|
||||
FROM wipe_history wh
|
||||
LEFT JOIN server_stats_hourly ssh
|
||||
ON ssh.license_id = wh.license_id
|
||||
AND ssh.hour >= wh.completed_at
|
||||
AND ssh.hour < wh.completed_at + INTERVAL '24 hours'
|
||||
WHERE wh.license_id = $1
|
||||
AND wh.created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND wh.status = 'success'
|
||||
AND wh.completed_at IS NOT NULL
|
||||
GROUP BY wh.id, wh.completed_at
|
||||
)
|
||||
SELECT AVG(EXTRACT(EPOCH FROM (peak_hour - completed_at)) / 3600.0) as avg_hours_to_peak
|
||||
FROM wipe_peaks
|
||||
WHERE peak_hour IS NOT NULL",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.context("Failed to query wipe-to-peak population")?;
|
||||
|
||||
Ok(result.and_then(|r| r.0).unwrap_or(0.0))
|
||||
}
|
||||
|
||||
/// Get population curve: average player count on day 1, day 2, day 3 post-wipe.
|
||||
/// Aggregates all successful wipes in the time range.
|
||||
pub async fn get_population_curve_by_cycle(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<PopulationCurve> {
|
||||
// For each successful wipe, calculate avg players on day 1 (0-24h), day 2 (24-48h), day 3 (48-72h)
|
||||
let result: Vec<(i32, f64)> = sqlx::query_as(
|
||||
"WITH wipe_days AS (
|
||||
SELECT
|
||||
wh.id as wipe_id,
|
||||
wh.completed_at,
|
||||
CASE
|
||||
WHEN ssh.hour >= wh.completed_at AND ssh.hour < wh.completed_at + INTERVAL '24 hours' THEN 1
|
||||
WHEN ssh.hour >= wh.completed_at + INTERVAL '24 hours' AND ssh.hour < wh.completed_at + INTERVAL '48 hours' THEN 2
|
||||
WHEN ssh.hour >= wh.completed_at + INTERVAL '48 hours' AND ssh.hour < wh.completed_at + INTERVAL '72 hours' THEN 3
|
||||
END as day_num,
|
||||
ssh.avg_players
|
||||
FROM wipe_history wh
|
||||
LEFT JOIN server_stats_hourly ssh
|
||||
ON ssh.license_id = wh.license_id
|
||||
AND ssh.hour >= wh.completed_at
|
||||
AND ssh.hour < wh.completed_at + INTERVAL '72 hours'
|
||||
WHERE wh.license_id = $1
|
||||
AND wh.created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND wh.status = 'success'
|
||||
AND wh.completed_at IS NOT NULL
|
||||
)
|
||||
SELECT day_num, AVG(avg_players) as avg_players_per_day
|
||||
FROM wipe_days
|
||||
WHERE day_num IS NOT NULL
|
||||
GROUP BY day_num
|
||||
ORDER BY day_num",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.context("Failed to query population curve")?;
|
||||
|
||||
let mut curve = PopulationCurve {
|
||||
day_1_avg: 0.0,
|
||||
day_2_avg: 0.0,
|
||||
day_3_avg: 0.0,
|
||||
};
|
||||
|
||||
for (day_num, avg_players) in result {
|
||||
match day_num {
|
||||
1 => curve.day_1_avg = avg_players,
|
||||
2 => curve.day_2_avg = avg_players,
|
||||
3 => curve.day_3_avg = avg_players,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(curve)
|
||||
}
|
||||
|
||||
/// Get optimal wipe timing: best day of week and hour based on historical peak populations.
|
||||
/// Analyzes successful wipes and their subsequent player peaks.
|
||||
pub async fn get_optimal_wipe_timing(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<OptimalWipeTiming> {
|
||||
// Find the day of week and hour with highest average peak population within 24h post-wipe
|
||||
let result: Option<(String, f64, f64)> = sqlx::query_as(
|
||||
"WITH wipe_performance AS (
|
||||
SELECT
|
||||
wh.id as wipe_id,
|
||||
wh.completed_at,
|
||||
EXTRACT(DOW FROM wh.completed_at) as day_of_week,
|
||||
EXTRACT(HOUR FROM wh.completed_at) as hour_of_day,
|
||||
MAX(ssh.max_players) as peak_players
|
||||
FROM wipe_history wh
|
||||
LEFT JOIN server_stats_hourly ssh
|
||||
ON ssh.license_id = wh.license_id
|
||||
AND ssh.hour >= wh.completed_at
|
||||
AND ssh.hour < wh.completed_at + INTERVAL '24 hours'
|
||||
WHERE wh.license_id = $1
|
||||
AND wh.created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND wh.status = 'success'
|
||||
AND wh.completed_at IS NOT NULL
|
||||
GROUP BY wh.id, wh.completed_at
|
||||
),
|
||||
best_timing AS (
|
||||
SELECT
|
||||
day_of_week,
|
||||
hour_of_day,
|
||||
AVG(peak_players) as avg_peak_players
|
||||
FROM wipe_performance
|
||||
GROUP BY day_of_week, hour_of_day
|
||||
ORDER BY avg_peak_players DESC
|
||||
LIMIT 1
|
||||
)
|
||||
SELECT
|
||||
CASE day_of_week::INTEGER
|
||||
WHEN 0 THEN 'Sunday'
|
||||
WHEN 1 THEN 'Monday'
|
||||
WHEN 2 THEN 'Tuesday'
|
||||
WHEN 3 THEN 'Wednesday'
|
||||
WHEN 4 THEN 'Thursday'
|
||||
WHEN 5 THEN 'Friday'
|
||||
WHEN 6 THEN 'Saturday'
|
||||
END as day_name,
|
||||
hour_of_day,
|
||||
avg_peak_players
|
||||
FROM best_timing",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.context("Failed to query optimal wipe timing")?;
|
||||
|
||||
let (day_name, hour_of_day, _) = result.unwrap_or(("Thursday".to_string(), 18.0, 0.0));
|
||||
|
||||
Ok(OptimalWipeTiming {
|
||||
optimal_wipe_day: day_name,
|
||||
optimal_wipe_hour: hour_of_day as i32,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get detailed wipe analytics entries (for charting).
|
||||
/// Returns individual wipe records with duration, peak population, hours to peak.
|
||||
pub async fn get_wipe_analytics_entries(
|
||||
pool: &PgPool,
|
||||
license_id: Uuid,
|
||||
days: i64,
|
||||
) -> Result<Vec<WipeAnalyticsEntry>> {
|
||||
let rows: Vec<(Uuid, DateTime<Utc>, Option<DateTime<Utc>>, Option<DateTime<Utc>>, String)> = sqlx::query_as(
|
||||
"SELECT id, created_at, started_at, completed_at, status
|
||||
FROM wipe_history
|
||||
WHERE license_id = $1
|
||||
AND created_at >= NOW() - ($2 || ' days')::INTERVAL
|
||||
AND status IN ('success', 'failed', 'rolled_back')
|
||||
ORDER BY created_at ASC",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(days)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.context("Failed to query wipe analytics entries")?;
|
||||
|
||||
let mut entries = Vec::new();
|
||||
|
||||
for (wipe_id, created_at, started_at, completed_at, status) in rows {
|
||||
let success = status == "success";
|
||||
let duration_seconds = if let (Some(start), Some(end)) = (started_at, completed_at) {
|
||||
(end - start).num_seconds()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// Find peak population and hours to peak for successful wipes
|
||||
let (peak_population, hours_to_peak) = if success && completed_at.is_some() {
|
||||
let peak_result: Option<(i32, DateTime<Utc>)> = sqlx::query_as(
|
||||
"SELECT max_players, hour
|
||||
FROM server_stats_hourly
|
||||
WHERE license_id = $1
|
||||
AND hour >= $2
|
||||
AND hour < $2 + INTERVAL '24 hours'
|
||||
ORDER BY max_players DESC, hour ASC
|
||||
LIMIT 1",
|
||||
)
|
||||
.bind(license_id)
|
||||
.bind(completed_at.unwrap())
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
.context("Failed to query peak population for wipe")?;
|
||||
|
||||
if let Some((peak, peak_hour)) = peak_result {
|
||||
let hours = (peak_hour - completed_at.unwrap()).num_seconds() as f64 / 3600.0;
|
||||
(peak, hours)
|
||||
} else {
|
||||
(0, 0.0)
|
||||
}
|
||||
} else {
|
||||
(0, 0.0)
|
||||
};
|
||||
|
||||
entries.push(WipeAnalyticsEntry {
|
||||
date: created_at,
|
||||
duration_seconds,
|
||||
peak_population,
|
||||
hours_to_peak,
|
||||
success,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
390
frontend/src/views/admin/WipeAnalyticsView.vue
Normal file
390
frontend/src/views/admin/WipeAnalyticsView.vue
Normal file
@@ -0,0 +1,390 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch, nextTick } from 'vue'
|
||||
import { BarChart3, TrendingUp, Clock, Target, Download, Zap } from 'lucide-vue-next'
|
||||
import * as echarts from 'echarts'
|
||||
import type { ECharts } from 'echarts'
|
||||
import { useApi } from '@/composables/useApi'
|
||||
import type { WipePerformanceMetrics } from '@/types'
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const timeRange = ref<'6' | '12' | 'all'>('12')
|
||||
const loading = ref(true)
|
||||
const metrics = ref<WipePerformanceMetrics | null>(null)
|
||||
|
||||
const successRateChart = ref<HTMLElement | null>(null)
|
||||
const populationCurveChart = ref<HTMLElement | null>(null)
|
||||
const durationTrendChart = ref<HTMLElement | null>(null)
|
||||
|
||||
let successRateChartInstance: ECharts | null = null
|
||||
let populationCurveChartInstance: ECharts | null = null
|
||||
let durationTrendChartInstance: ECharts | null = null
|
||||
|
||||
const rangeToParam = (range: string): string => {
|
||||
if (range === 'all') return 'all'
|
||||
return `${parseInt(range) * 30}d` // 6 wipes = ~180d, 12 wipes = ~360d (monthly wipes)
|
||||
}
|
||||
|
||||
const loadAnalytics = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const range = rangeToParam(timeRange.value)
|
||||
const response = await api.get<WipePerformanceMetrics>(`/api/analytics/wipes/performance?range=${range}`)
|
||||
metrics.value = response
|
||||
|
||||
await nextTick()
|
||||
renderCharts()
|
||||
} catch (error) {
|
||||
console.error('Failed to load wipe analytics:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const renderCharts = () => {
|
||||
if (!metrics.value) return
|
||||
|
||||
// Success Rate Timeline
|
||||
if (successRateChart.value) {
|
||||
if (successRateChartInstance) {
|
||||
successRateChartInstance.dispose()
|
||||
}
|
||||
successRateChartInstance = echarts.init(successRateChart.value)
|
||||
|
||||
const successData = metrics.value.wipes.map(w => w.success ? 1 : 0)
|
||||
const dates = metrics.value.wipes.map(w => new Date(w.date).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
}))
|
||||
|
||||
successRateChartInstance.setOption({
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: '#1a1a1a',
|
||||
borderColor: '#2a2a2a',
|
||||
textStyle: { color: '#e5e5e5' },
|
||||
formatter: (params: any) => {
|
||||
const status = params[0].data === 1 ? 'Success' : 'Failed'
|
||||
const color = params[0].data === 1 ? '#10b981' : '#ef4444'
|
||||
return `<span style="color:${color}">●</span> ${params[0].axisValue}: ${status}`
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '10%',
|
||||
top: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
axisLabel: { color: '#808080', rotate: 45 }
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
min: 0,
|
||||
max: 1,
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
splitLine: { lineStyle: { color: '#2a2a2a' } },
|
||||
axisLabel: {
|
||||
color: '#808080',
|
||||
formatter: (value: number) => value === 1 ? 'Success' : 'Failed'
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Wipe Status',
|
||||
type: 'scatter',
|
||||
data: successData,
|
||||
symbolSize: 10,
|
||||
itemStyle: {
|
||||
color: (params: any) => params.data === 1 ? '#10b981' : '#ef4444'
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
// Population Curve (Day 1 vs Day 2 vs Day 3)
|
||||
if (populationCurveChart.value) {
|
||||
if (populationCurveChartInstance) {
|
||||
populationCurveChartInstance.dispose()
|
||||
}
|
||||
populationCurveChartInstance = echarts.init(populationCurveChart.value)
|
||||
|
||||
const { population_curve } = metrics.value
|
||||
|
||||
populationCurveChartInstance.setOption({
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: '#1a1a1a',
|
||||
borderColor: '#2a2a2a',
|
||||
textStyle: { color: '#e5e5e5' }
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '10%',
|
||||
top: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['Day 1', 'Day 2', 'Day 3'],
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
axisLabel: { color: '#808080' }
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
name: 'Avg Players',
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
splitLine: { lineStyle: { color: '#2a2a2a' } },
|
||||
axisLabel: { color: '#808080' }
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Average Players',
|
||||
type: 'bar',
|
||||
data: [
|
||||
population_curve.day_1_avg,
|
||||
population_curve.day_2_avg,
|
||||
population_curve.day_3_avg
|
||||
],
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: '#CE422B' },
|
||||
{ offset: 1, color: '#8B2E1F' }
|
||||
])
|
||||
},
|
||||
barWidth: '50%'
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
// Wipe Duration Trend
|
||||
if (durationTrendChart.value) {
|
||||
if (durationTrendChartInstance) {
|
||||
durationTrendChartInstance.dispose()
|
||||
}
|
||||
durationTrendChartInstance = echarts.init(durationTrendChart.value)
|
||||
|
||||
const durations = metrics.value.wipes.map(w => (w.duration_seconds / 60).toFixed(1))
|
||||
const dates = metrics.value.wipes.map(w => new Date(w.date).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
}))
|
||||
|
||||
durationTrendChartInstance.setOption({
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: '#1a1a1a',
|
||||
borderColor: '#2a2a2a',
|
||||
textStyle: { color: '#e5e5e5' },
|
||||
formatter: (params: any) => {
|
||||
return `${params[0].axisValue}<br/>Duration: ${params[0].data} minutes`
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '10%',
|
||||
top: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
axisLabel: { color: '#808080', rotate: 45 }
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
name: 'Minutes',
|
||||
axisLine: { lineStyle: { color: '#404040' } },
|
||||
splitLine: { lineStyle: { color: '#2a2a2a' } },
|
||||
axisLabel: { color: '#808080' }
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Duration',
|
||||
type: 'line',
|
||||
data: durations,
|
||||
smooth: true,
|
||||
lineStyle: { color: '#6366f1', width: 2 },
|
||||
areaStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: 'rgba(99, 102, 241, 0.3)' },
|
||||
{ offset: 1, color: 'rgba(99, 102, 241, 0)' }
|
||||
])
|
||||
},
|
||||
itemStyle: { color: '#6366f1' }
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const formatDuration = (seconds: number): string => {
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const secs = Math.floor(seconds % 60)
|
||||
return `${minutes}m ${secs}s`
|
||||
}
|
||||
|
||||
const downloadCSV = async () => {
|
||||
if (!metrics.value) return
|
||||
|
||||
let csv = 'Date,Duration (seconds),Peak Population,Hours to Peak,Success\n'
|
||||
metrics.value.wipes.forEach(wipe => {
|
||||
csv += `${new Date(wipe.date).toISOString()},${wipe.duration_seconds},${wipe.peak_population},${wipe.hours_to_peak.toFixed(2)},${wipe.success}\n`
|
||||
})
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv' })
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `wipe_analytics_${timeRange.value}.csv`
|
||||
a.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
watch(timeRange, () => {
|
||||
loadAnalytics()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
loadAnalytics()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-6 space-y-6">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<Zap class="w-5 h-5 text-oxide-500" />
|
||||
<h1 class="text-2xl font-bold text-neutral-100">Wipe Analytics</h1>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
@click="downloadCSV"
|
||||
class="flex items-center gap-2 px-3 py-2 bg-neutral-800 border border-neutral-700 rounded-lg hover:bg-neutral-700 transition-colors text-sm text-neutral-300"
|
||||
>
|
||||
<Download class="w-4 h-4" />
|
||||
Export CSV
|
||||
</button>
|
||||
<div class="flex bg-neutral-800 rounded-lg border border-neutral-700 overflow-hidden">
|
||||
<button
|
||||
v-for="opt in (['6', '12', 'all'] as const)"
|
||||
:key="opt"
|
||||
@click="timeRange = opt"
|
||||
class="px-3 py-2 text-sm font-medium transition-colors"
|
||||
:class="timeRange === opt ? 'bg-oxide-500/15 text-oxide-400' : 'text-neutral-400 hover:text-neutral-200'"
|
||||
>
|
||||
{{ opt === 'all' ? 'All Time' : `Last ${opt} Wipes` }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading state -->
|
||||
<div v-if="loading" class="flex items-center justify-center py-12">
|
||||
<div class="text-neutral-500">Loading wipe analytics...</div>
|
||||
</div>
|
||||
|
||||
<template v-else-if="metrics">
|
||||
<!-- Insight Cards -->
|
||||
<div class="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<Target class="w-4 h-4 text-neutral-500" />
|
||||
<p class="text-sm text-neutral-400">Success Rate</p>
|
||||
</div>
|
||||
<p class="text-2xl font-bold text-neutral-100">{{ metrics.success_rate_percent.toFixed(1) }}%</p>
|
||||
<p class="text-xs text-neutral-600 mt-1">{{ metrics.successful_wipes }}/{{ metrics.total_wipes }} wipes</p>
|
||||
</div>
|
||||
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<Clock class="w-4 h-4 text-neutral-500" />
|
||||
<p class="text-sm text-neutral-400">Avg Duration</p>
|
||||
</div>
|
||||
<p class="text-2xl font-bold text-neutral-100">{{ formatDuration(metrics.avg_duration_seconds) }}</p>
|
||||
<p class="text-xs text-neutral-600 mt-1">Per wipe</p>
|
||||
</div>
|
||||
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<TrendingUp class="w-4 h-4 text-neutral-500" />
|
||||
<p class="text-sm text-neutral-400">Peak Population</p>
|
||||
</div>
|
||||
<p class="text-2xl font-bold text-neutral-100">Day 1</p>
|
||||
<p class="text-xs text-neutral-600 mt-1">{{ metrics.population_curve.day_1_avg.toFixed(1) }} avg players</p>
|
||||
</div>
|
||||
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<BarChart3 class="w-4 h-4 text-neutral-500" />
|
||||
<p class="text-sm text-neutral-400">Optimal Timing</p>
|
||||
</div>
|
||||
<p class="text-2xl font-bold text-neutral-100">{{ metrics.optimal_wipe_day }}</p>
|
||||
<p class="text-xs text-neutral-600 mt-1">{{ metrics.optimal_wipe_hour }}:00</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actionable Insight Banner -->
|
||||
<div v-if="metrics.total_wipes > 3" class="bg-oxide-500/10 border border-oxide-500/30 rounded-lg p-4">
|
||||
<div class="flex items-start gap-3">
|
||||
<Target class="w-5 h-5 text-oxide-400 mt-0.5" />
|
||||
<div>
|
||||
<p class="text-sm font-medium text-neutral-100 mb-1">Recommendations</p>
|
||||
<ul class="text-sm text-neutral-300 space-y-1">
|
||||
<li>• Your best wipe day is <span class="font-semibold text-oxide-400">{{ metrics.optimal_wipe_day }} at {{ metrics.optimal_wipe_hour }}:00</span> based on post-wipe population peaks.</li>
|
||||
<li v-if="metrics.population_curve.day_1_avg > metrics.population_curve.day_2_avg * 1.2">
|
||||
• Players peak on Day 1 ({{ metrics.population_curve.day_1_avg.toFixed(0) }} avg). Consider <span class="font-semibold text-oxide-400">weekly wipes</span> to maintain engagement.
|
||||
</li>
|
||||
<li v-if="metrics.avg_duration_seconds > 600">
|
||||
• Average wipe duration is {{ formatDuration(metrics.avg_duration_seconds) }}. Review pre-wipe commands for optimization opportunities.
|
||||
</li>
|
||||
<li v-if="metrics.success_rate_percent < 95 && metrics.failed_wipes > 0">
|
||||
• {{ metrics.failed_wipes }} wipe(s) failed. Enable rollback protection in wipe profiles.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Charts -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<h2 class="text-sm font-medium text-neutral-400 uppercase tracking-wider mb-4">Wipe Success Timeline</h2>
|
||||
<div ref="successRateChart" class="h-64"></div>
|
||||
</div>
|
||||
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<h2 class="text-sm font-medium text-neutral-400 uppercase tracking-wider mb-4">Population Curve Post-Wipe</h2>
|
||||
<div ref="populationCurveChart" class="h-64"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-neutral-900 border border-neutral-800 rounded-lg p-5">
|
||||
<h2 class="text-sm font-medium text-neutral-400 uppercase tracking-wider mb-4">Wipe Duration Trend</h2>
|
||||
<div ref="durationTrendChart" class="h-64"></div>
|
||||
</div>
|
||||
|
||||
<!-- No Data State -->
|
||||
<div v-if="metrics.total_wipes === 0" class="bg-neutral-900 border border-neutral-800 rounded-lg p-8">
|
||||
<div class="text-center">
|
||||
<Zap class="w-12 h-12 text-neutral-700 mx-auto mb-3" />
|
||||
<p class="text-neutral-400 mb-1">No wipe data yet</p>
|
||||
<p class="text-sm text-neutral-600">Wipe analytics will appear after your first scheduled or manual wipe.</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user