Spaces:
Sleeping
Sleeping
Update frontend/dashboard.html
Browse files- frontend/dashboard.html +62 -118
frontend/dashboard.html
CHANGED
|
@@ -4,164 +4,108 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>PINE AI - VNPT Smart Dashboard</title>
|
| 7 |
-
|
| 8 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 10 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
| 11 |
-
|
| 12 |
<style>
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
.
|
| 17 |
-
|
| 18 |
-
.mascot-container:hover { transform: scale(1.1) rotate(5deg); }
|
| 19 |
-
.mascot-container img { width: 75%; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2)); }
|
| 20 |
-
.glass-card { background: #ffffff; border: 1px solid #e2e8f0; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03); border-radius: 1rem; transition: all 0.3s ease; height: 100%; }
|
| 21 |
-
.glass-card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.025); }
|
| 22 |
-
.tab-btn { padding: 0.5rem 1.5rem; border-radius: 0.75rem; font-size: 0.875rem; font-weight: 700; color: rgba(255,255,255,0.8); transition: all 0.2s; }
|
| 23 |
-
.tab-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
|
| 24 |
-
.tab-active { background: #ffffff !important; color: var(--vnpt-dark) !important; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
|
| 25 |
-
::-webkit-scrollbar { width: 6px; }
|
| 26 |
-
::-webkit-scrollbar-track { background: #f1f5f9; }
|
| 27 |
-
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
|
| 28 |
-
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
|
| 29 |
</style>
|
| 30 |
</head>
|
| 31 |
-
<body
|
| 32 |
|
| 33 |
-
<header
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
<div class="mascot-container">
|
| 37 |
-
<img src="https://github.com/chydua/PINE/blob/main/Screenshot_2025-12-18_at_19.19.29-removebg-preview.png?raw=true" alt="PINE">
|
| 38 |
-
</div>
|
| 39 |
-
<div>
|
| 40 |
-
<h1 class="text-2xl font-extrabold text-white tracking-tight">PINE AI <span class="opacity-70 font-normal text-lg">| Dashboard</span></h1>
|
| 41 |
-
<p class="text-xs text-white/80 font-medium uppercase tracking-wider flex items-center gap-2">
|
| 42 |
-
<span class="w-2 h-2 bg-green-400 rounded-full animate-pulse"></span>
|
| 43 |
-
Last updated: <span id="last-update">...</span>
|
| 44 |
-
<span id="connection-status" class="text-red-300 font-bold ml-2"></span>
|
| 45 |
-
</p>
|
| 46 |
-
</div>
|
| 47 |
-
</div>
|
| 48 |
-
|
| 49 |
-
<div class="flex bg-white/20 p-1 rounded-2xl backdrop-blur-md">
|
| 50 |
-
<button onclick="switchPeriod(event,'today')" class="tab-btn tab-active filter-btn">HÔM NAY</button>
|
| 51 |
-
<button onclick="switchPeriod(event,'week')" class="tab-btn filter-btn">TUẦN NÀY</button>
|
| 52 |
-
<button onclick="switchPeriod(event,'month')" class="tab-btn filter-btn">THÁNG NAY</button>
|
| 53 |
-
</div>
|
| 54 |
-
</div>
|
| 55 |
</header>
|
| 56 |
|
| 57 |
-
<main
|
| 58 |
-
<!--
|
| 59 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</main>
|
| 61 |
|
| 62 |
-
<footer
|
| 63 |
-
© 2025 PINE AI - GIẢI PHÁP CSKH THÔNG MINH
|
| 64 |
-
</footer>
|
| 65 |
|
| 66 |
<script>
|
|
|
|
| 67 |
let rawData = [];
|
| 68 |
-
let currentPeriod = 'today';
|
| 69 |
-
let busChart, intChart, sentChart;
|
| 70 |
-
|
| 71 |
async function fetchDashboardData() {
|
| 72 |
try {
|
| 73 |
-
const res = await fetch(
|
| 74 |
const json = await res.json();
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
loadDashboard(
|
| 80 |
-
document.getElementById('last-update')
|
|
|
|
| 81 |
}
|
| 82 |
} catch (e) {
|
| 83 |
console.error("Lỗi kết nối Dashboard:", e);
|
| 84 |
-
document.getElementById('connection-status')
|
|
|
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
function formatAHT(seconds) {
|
| 89 |
if (!seconds || isNaN(seconds)) return "00:00";
|
| 90 |
-
const m = Math.floor(seconds
|
| 91 |
-
const s = (seconds
|
| 92 |
return `${m}:${s}`;
|
| 93 |
}
|
| 94 |
|
| 95 |
-
function filterData(period) {
|
| 96 |
-
if (!rawData || rawData.length === 0) return [];
|
| 97 |
-
const now = new Date();
|
| 98 |
-
const startOfDay = new Date(now.setHours(0,0,0,0));
|
| 99 |
-
const startOfWeek = new Date(new Date().setDate(now.getDate() - 7));
|
| 100 |
-
const startOfMonth = new Date(new Date().setDate(now.getDate() - 30));
|
| 101 |
-
|
| 102 |
-
return rawData.filter(item => {
|
| 103 |
-
const itemTime = new Date(item.time);
|
| 104 |
-
if (period === 'today') return itemTime >= startOfDay;
|
| 105 |
-
if (period === 'week') return itemTime >= startOfWeek;
|
| 106 |
-
return true;
|
| 107 |
-
});
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
function calculateMetrics(data) {
|
| 111 |
-
const total = data.length;
|
| 112 |
-
if
|
| 113 |
-
const totalCost = data.reduce((
|
| 114 |
-
const totalDur = data.reduce((
|
| 115 |
-
const totalCSAT = data.reduce((
|
| 116 |
const fcrCount = data.filter(c=>c.ai).length;
|
| 117 |
-
const intents = { network: 0, cancel: 0, competitor: 0, low_data: 0 };
|
| 118 |
-
const sents = { pos:0, neu:0, neg:0 };
|
| 119 |
-
data.forEach(c=>{
|
| 120 |
-
const i=(c.intent||"").toLowerCase();
|
| 121 |
-
if(i.includes('network')) intents.network++;
|
| 122 |
-
else if(i.includes('low_data') || i.includes('data')) intents.low_data++;
|
| 123 |
-
else if(i.includes('cancel')) intents.cancel++;
|
| 124 |
-
else intents.competitor++;
|
| 125 |
-
if(c.sent==='positive') sents.pos++;
|
| 126 |
-
else if(c.sent==='negative') sents.neg++;
|
| 127 |
-
else sents.neu++;
|
| 128 |
-
});
|
| 129 |
return {
|
| 130 |
totalCalls: total,
|
| 131 |
avgCost: Math.round(totalCost/total),
|
| 132 |
aht: Math.round(totalDur/total),
|
| 133 |
fcr: ((fcrCount/total)*100).toFixed(1),
|
| 134 |
-
avgCSAT: (totalCSAT/total).toFixed(1)
|
| 135 |
-
intents: intents,
|
| 136 |
-
sentiments: sents
|
| 137 |
};
|
| 138 |
}
|
| 139 |
|
| 140 |
-
// Hàm renderCharts & updateFeed giữ nguyên
|
| 141 |
-
// ... giữ nguyên code renderCharts & updateFeed như bản gốc ...
|
| 142 |
-
|
| 143 |
-
function switchPeriod(event, period) {
|
| 144 |
-
currentPeriod = period;
|
| 145 |
-
document.querySelectorAll('.tab-btn').forEach(btn=>btn.classList.remove('tab-active'));
|
| 146 |
-
event.target.classList.add('tab-active');
|
| 147 |
-
loadDashboard(period);
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
function loadDashboard(period) {
|
| 151 |
-
const filteredData = filterData(period);
|
| 152 |
-
const metrics = calculateMetrics(filteredData);
|
| 153 |
-
document.getElementById('kpi-total-calls').innerText = metrics.totalCalls.toLocaleString();
|
| 154 |
-
document.getElementById('kpi-cost').innerText = metrics.avgCost.toLocaleString();
|
| 155 |
-
document.getElementById('kpi-aht').innerText = formatAHT(metrics.aht);
|
| 156 |
-
document.getElementById('kpi-fcr').innerText = metrics.fcr;
|
| 157 |
-
document.getElementById('kpi-csat').innerText = metrics.avgCSAT;
|
| 158 |
-
renderCharts(metrics, period);
|
| 159 |
-
updateFeed();
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
document.addEventListener('DOMContentLoaded', ()=>{
|
| 163 |
fetchDashboardData();
|
| 164 |
-
setInterval(fetchDashboardData,
|
| 165 |
});
|
| 166 |
</script>
|
| 167 |
</body>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>PINE AI - VNPT Smart Dashboard</title>
|
|
|
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 9 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|
|
|
| 10 |
<style>
|
| 11 |
+
body { font-family: Arial,sans-serif; background-color: #f8fafc; }
|
| 12 |
+
.kpi-card { display: inline-block; background:white; padding:20px; margin:10px; border-radius:10px; min-width:120px; text-align:center; box-shadow:0 2px 5px rgba(0,0,0,0.1); }
|
| 13 |
+
.kpi-value { font-size:1.5em; font-weight:bold; }
|
| 14 |
+
.kpi-label { font-size:0.8em; color:#555; }
|
| 15 |
+
#connection-status { color:red; font-weight:bold; margin-left:5px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
</style>
|
| 17 |
</head>
|
| 18 |
+
<body>
|
| 19 |
|
| 20 |
+
<header style="padding:20px; text-align:center; background:#00a1e4; color:white;">
|
| 21 |
+
<h1>PINE AI | Dashboard</h1>
|
| 22 |
+
<p>Last updated: <span id="last-update">...</span> <span id="connection-status"></span></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</header>
|
| 24 |
|
| 25 |
+
<main style="padding:20px; text-align:center;">
|
| 26 |
+
<!-- KPI Cards -->
|
| 27 |
+
<div class="kpi-card">
|
| 28 |
+
<div class="kpi-value" id="kpi-total-calls">0</div>
|
| 29 |
+
<div class="kpi-label">Total Calls</div>
|
| 30 |
+
</div>
|
| 31 |
+
<div class="kpi-card">
|
| 32 |
+
<div class="kpi-value" id="kpi-cost">0</div>
|
| 33 |
+
<div class="kpi-label">Avg Cost</div>
|
| 34 |
+
</div>
|
| 35 |
+
<div class="kpi-card">
|
| 36 |
+
<div class="kpi-value" id="kpi-aht">00:00</div>
|
| 37 |
+
<div class="kpi-label">AHT</div>
|
| 38 |
+
</div>
|
| 39 |
+
<div class="kpi-card">
|
| 40 |
+
<div class="kpi-value" id="kpi-fcr">0%</div>
|
| 41 |
+
<div class="kpi-label">FCR</div>
|
| 42 |
+
</div>
|
| 43 |
+
<div class="kpi-card">
|
| 44 |
+
<div class="kpi-value" id="kpi-csat">0</div>
|
| 45 |
+
<div class="kpi-label">Avg CSAT</div>
|
| 46 |
+
</div>
|
| 47 |
</main>
|
| 48 |
|
| 49 |
+
<footer style="text-align:center; padding:10px; color:#888;">© 2025 PINE AI</footer>
|
|
|
|
|
|
|
| 50 |
|
| 51 |
<script>
|
| 52 |
+
const API_URL = window.location.origin; // dùng cùng origin với frontend
|
| 53 |
let rawData = [];
|
|
|
|
|
|
|
|
|
|
| 54 |
async function fetchDashboardData() {
|
| 55 |
try {
|
| 56 |
+
const res = await fetch(`${API_URL}/api/dashboard-stats`);
|
| 57 |
const json = await res.json();
|
| 58 |
+
if(json.status === 'success') {
|
| 59 |
+
rawData = json.data || [];
|
| 60 |
+
const connEl = document.getElementById('connection-status');
|
| 61 |
+
if(connEl) connEl.innerText = '';
|
| 62 |
+
loadDashboard();
|
| 63 |
+
const lastUpdateEl = document.getElementById('last-update');
|
| 64 |
+
if(lastUpdateEl) lastUpdateEl.innerText = new Date().toLocaleTimeString('vi-VN');
|
| 65 |
}
|
| 66 |
} catch (e) {
|
| 67 |
console.error("Lỗi kết nối Dashboard:", e);
|
| 68 |
+
const connEl = document.getElementById('connection-status');
|
| 69 |
+
if(connEl) connEl.innerText = "(Mất kết nối)";
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
+
function loadDashboard() {
|
| 74 |
+
const metrics = calculateMetrics(rawData);
|
| 75 |
+
const setText = (id,val) => { const el=document.getElementById(id); if(el) el.innerText = val; }
|
| 76 |
+
setText('kpi-total-calls', metrics.totalCalls.toLocaleString());
|
| 77 |
+
setText('kpi-cost', metrics.avgCost.toLocaleString());
|
| 78 |
+
setText('kpi-aht', formatAHT(metrics.aht));
|
| 79 |
+
setText('kpi-fcr', metrics.fcr + "%");
|
| 80 |
+
setText('kpi-csat', metrics.avgCSAT);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
function formatAHT(seconds) {
|
| 84 |
if (!seconds || isNaN(seconds)) return "00:00";
|
| 85 |
+
const m = Math.floor(seconds/60).toString().padStart(2,'0');
|
| 86 |
+
const s = (seconds%60).toString().padStart(2,'0');
|
| 87 |
return `${m}:${s}`;
|
| 88 |
}
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
function calculateMetrics(data) {
|
| 91 |
+
const total = data.length || 0;
|
| 92 |
+
if(total===0) return {totalCalls:0, avgCost:0, aht:0, fcr:0, avgCSAT:0};
|
| 93 |
+
const totalCost = data.reduce((s,c)=>s+(c.cost||0),0);
|
| 94 |
+
const totalDur = data.reduce((s,c)=>s+(c.dur||0),0);
|
| 95 |
+
const totalCSAT = data.reduce((s,c)=>s+(c.csat||0),0);
|
| 96 |
const fcrCount = data.filter(c=>c.ai).length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return {
|
| 98 |
totalCalls: total,
|
| 99 |
avgCost: Math.round(totalCost/total),
|
| 100 |
aht: Math.round(totalDur/total),
|
| 101 |
fcr: ((fcrCount/total)*100).toFixed(1),
|
| 102 |
+
avgCSAT: (totalCSAT/total).toFixed(1)
|
|
|
|
|
|
|
| 103 |
};
|
| 104 |
}
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
document.addEventListener('DOMContentLoaded', ()=>{
|
| 107 |
fetchDashboardData();
|
| 108 |
+
setInterval(fetchDashboardData,3000);
|
| 109 |
});
|
| 110 |
</script>
|
| 111 |
</body>
|