Spaces:
Running
Running
File size: 6,259 Bytes
dd6f9a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | <!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#0e9f6e">
<title>EcoLens — Thống kê quét rác</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📊</text></svg>">
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.umd.min.js"></script>
<script src="data.js"></script>
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="brand-logo">📊</span>
<div>
<div class="brand-name">Thống kê EcoLens</div>
<div class="brand-sub">Dữ liệu quét rác trên máy này</div>
</div>
</div>
<a class="stats-link" href="index.html" title="Về trang chụp">📷</a>
</header>
<main id="app">
<section class="screen">
<div class="ai-status">ℹ️ Thống kê này tính riêng cho máy bạn đang dùng (dữ liệu lưu ngay trên máy, không gửi đi đâu).</div>
<div class="stats-grid">
<div class="card stat-tile"><div class="stat-num" id="tile-total">–</div><div class="stat-cap">Tổng lượt quét</div></div>
<div class="card stat-tile"><div class="stat-num" id="tile-none">–</div><div class="stat-cap">Lượt chưa nhận ra</div></div>
</div>
<div class="card chart-card">
<h2>🗑️ Loại rác được quét nhiều nhất</h2>
<div class="bins-mini-legend" id="bin-legend"></div>
<div class="chart-box"><canvas id="chart-class" height="300"></canvas></div>
<details class="table-view"><summary>Xem dạng bảng</summary><table id="table-class"></table></details>
</div>
<div class="card chart-card">
<h2>📅 Lượt quét theo ngày</h2>
<div class="chart-box"><canvas id="chart-day" height="220"></canvas></div>
</div>
<div class="card empty-card" id="no-data" hidden>
<div class="hero-emoji">🌱</div>
<h2>Chưa có dữ liệu</h2>
<p>Hãy quét vài món rác ở trang chính, thống kê sẽ hiện ở đây!</p>
<a class="btn-capture" href="index.html" style="text-decoration:none">📸 Bắt đầu quét</a>
</div>
<div class="card" style="text-align:center">
<button id="btn-reset" class="btn-gallery" style="border:none;background:none">🗑️ Xóa thống kê trên máy này</button>
</div>
</section>
</main>
<footer class="footer">EcoLens 🌱 Dự án AI bảo vệ môi trường học đường</footer>
<style>
.chart-card h2 { font-size:16px; margin-bottom:10px; }
.chart-box { position:relative; width:100%; }
.stats-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:14px; }
.stat-tile { text-align:center; padding:18px 10px; }
.stat-num { font-size:32px; font-weight:800; color:var(--green-dark); }
.stat-cap { font-size:13px; color:var(--ink-soft); font-weight:600; }
</style>
<script>
const INK = "#14332a", INK_SOFT = "#4b6b5e", GRID = "rgba(20,51,42,.08)", GREEN = "#0e9f6e";
Chart.defaults.font.family = getComputedStyle(document.body).fontFamily;
Chart.defaults.color = INK_SOFT;
const INFO = {}; EL_CLASSES.forEach((c) => (INFO[c.class_name] = c));
const s = JSON.parse(localStorage.getItem("ecolens_stats") || '{"total":0,"none":0,"byClass":{},"byDay":{}}');
document.getElementById("tile-total").textContent = s.total;
document.getElementById("tile-none").textContent = s.none;
document.getElementById("btn-reset").addEventListener("click", () => {
if (confirm("Xóa toàn bộ thống kê trên máy này?")) { localStorage.removeItem("ecolens_stats"); location.reload(); }
});
const classRows = Object.entries(s.byClass)
.map(([c, n]) => ({ c, n, info: INFO[c] })).filter((r) => r.info)
.sort((a, b) => b.n - a.n);
if (!classRows.length) {
document.getElementById("no-data").hidden = false;
} else {
const bins = [...new Map(classRows.map((r) => [EL_BINS[r.info.bin].label, EL_BINS[r.info.bin].color]))];
document.getElementById("bin-legend").innerHTML =
bins.map(([b, col]) => `<span><i style="background:${col}"></i>${b}</span>`).join("");
new Chart(document.getElementById("chart-class"), {
type: "bar",
data: { labels: classRows.map((r) => r.info.name_vi),
datasets: [{ data: classRows.map((r) => r.n),
backgroundColor: classRows.map((r) => EL_BINS[r.info.bin].color), borderRadius: 4, barThickness: 18 }] },
options: { indexAxis: "y", maintainAspectRatio: false,
plugins: { legend: { display: false },
tooltip: { callbacks: { label: (ctx) => ` ${ctx.parsed.x} lượt · Thùng ${EL_BINS[classRows[ctx.dataIndex].info.bin].label}` } } },
scales: { x: { grid: { color: GRID }, ticks: { precision: 0 }, border: { display: false } },
y: { grid: { display: false }, ticks: { color: INK, font: { weight: 600 } }, border: { display: false } } } },
});
document.getElementById("table-class").innerHTML =
"<tr><th>Loại rác</th><th>Thùng</th><th>Lượt</th></tr>" +
classRows.map((r) => `<tr><td>${r.info.name_vi}</td><td>${EL_BINS[r.info.bin].label}</td><td>${r.n}</td></tr>`).join("");
const days = Object.keys(s.byDay).sort().slice(-30);
new Chart(document.getElementById("chart-day"), {
type: "line",
data: { labels: days.map((d) => d.slice(5)),
datasets: [{ data: days.map((d) => s.byDay[d]), borderColor: GREEN, borderWidth: 2,
pointRadius: 3, pointHoverRadius: 6, pointBackgroundColor: GREEN,
fill: { target: "origin" }, backgroundColor: "rgba(14,159,110,.08)", tension: .3 }] },
options: { maintainAspectRatio: false, interaction: { mode: "index", intersect: false },
plugins: { legend: { display: false } },
scales: { x: { grid: { display: false }, border: { display: false } },
y: { grid: { color: GRID }, ticks: { precision: 0 }, border: { display: false }, beginAtZero: true } } },
});
}
</script>
</body>
</html>
|