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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Caliceo Affluence</title>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3"></script>
|
| 9 |
+
<style>
|
| 10 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 11 |
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f7fa; color: #1a1a2e; }
|
| 12 |
+
header { background: linear-gradient(135deg, #0077b6, #00b4d8); color: #fff; padding: 1.5rem 2rem; }
|
| 13 |
+
header h1 { font-size: 1.5rem; font-weight: 600; }
|
| 14 |
+
header p { font-size: 0.9rem; opacity: 0.85; margin-top: 0.25rem; }
|
| 15 |
+
.container { max-width: 1200px; margin: 2rem auto; padding: 0 1.5rem; }
|
| 16 |
+
.card { background: #fff; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); padding: 1.5rem; }
|
| 17 |
+
.stats { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
|
| 18 |
+
.stat { background: #f0f4f8; border-radius: 8px; padding: 0.75rem 1.25rem; flex: 1; min-width: 140px; }
|
| 19 |
+
.stat .label { font-size: 0.75rem; text-transform: uppercase; color: #666; letter-spacing: 0.05em; }
|
| 20 |
+
.stat .value { font-size: 1.4rem; font-weight: 700; color: #0077b6; margin-top: 0.15rem; }
|
| 21 |
+
.chart-wrapper { position: relative; height: 400px; }
|
| 22 |
+
.controls { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
|
| 23 |
+
.controls button { padding: 0.4rem 1rem; border: 1px solid #ddd; border-radius: 6px; background: #fff; cursor: pointer; font-size: 0.85rem; transition: all 0.15s; }
|
| 24 |
+
.controls button:hover { border-color: #0077b6; color: #0077b6; }
|
| 25 |
+
.controls button.active { background: #0077b6; color: #fff; border-color: #0077b6; }
|
| 26 |
+
</style>
|
| 27 |
+
</head>
|
| 28 |
+
<body>
|
| 29 |
+
<header>
|
| 30 |
+
<h1>Caliceo Affluence</h1>
|
| 31 |
+
<p>Time-series data from julien-c/caliceo dataset</p>
|
| 32 |
+
</header>
|
| 33 |
+
<div class="container">
|
| 34 |
+
<div class="stats" id="stats"></div>
|
| 35 |
+
<div class="card">
|
| 36 |
+
<div class="controls" id="controls"></div>
|
| 37 |
+
<div class="chart-wrapper">
|
| 38 |
+
<canvas id="chart"></canvas>
|
| 39 |
+
</div>
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
<script>
|
| 43 |
+
let chart;
|
| 44 |
+
let allData = [];
|
| 45 |
+
|
| 46 |
+
async function loadCSV() {
|
| 47 |
+
const res = await fetch('https://huggingface.co/datasets/julien-c/caliceo/resolve/main/affluence.csv');
|
| 48 |
+
const text = await res.text();
|
| 49 |
+
const lines = text.trim().split('\n').slice(1);
|
| 50 |
+
allData = lines.map(line => {
|
| 51 |
+
const [timestamp, affluence] = line.split(',');
|
| 52 |
+
return { x: new Date(timestamp), y: parseInt(affluence, 10) };
|
| 53 |
+
});
|
| 54 |
+
renderStats(allData);
|
| 55 |
+
buildControls();
|
| 56 |
+
renderChart(allData);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function renderStats(data) {
|
| 60 |
+
const values = data.map(d => d.y);
|
| 61 |
+
const max = Math.max(...values);
|
| 62 |
+
const min = Math.min(...values);
|
| 63 |
+
const avg = (values.reduce((a, b) => a + b, 0) / values.length).toFixed(1);
|
| 64 |
+
const first = data[0].x.toLocaleDateString();
|
| 65 |
+
const last = data[data.length - 1].x.toLocaleDateString();
|
| 66 |
+
document.getElementById('stats').innerHTML = `
|
| 67 |
+
<div class="stat"><div class="label">Data points</div><div class="value">${data.length.toLocaleString()}</div></div>
|
| 68 |
+
<div class="stat"><div class="label">Peak</div><div class="value">${max} %</div></div>
|
| 69 |
+
<div class="stat"><div class="label">Low</div><div class="value">${min} %</div></div>
|
| 70 |
+
<div class="stat"><div class="label">Average</div><div class="value">${avg} %</div></div>
|
| 71 |
+
<div class="stat"><div class="label">Period</div><div class="value" style="font-size:0.95rem">${first} – ${last}</div></div>
|
| 72 |
+
<div class="stat"><div class="label">Last data point</div><div class="value" style="font-size:0.95rem">${data[data.length - 1].x.toLocaleString()}</div></div>
|
| 73 |
+
`;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function buildControls() {
|
| 77 |
+
const ranges = [
|
| 78 |
+
{ label: 'All', days: null },
|
| 79 |
+
{ label: '7d', days: 7 },
|
| 80 |
+
{ label: '14d', days: 14 },
|
| 81 |
+
{ label: '30d', days: 30 },
|
| 82 |
+
];
|
| 83 |
+
const container = document.getElementById('controls');
|
| 84 |
+
ranges.forEach((r, i) => {
|
| 85 |
+
const btn = document.createElement('button');
|
| 86 |
+
btn.textContent = r.label;
|
| 87 |
+
if (i === 0) btn.classList.add('active');
|
| 88 |
+
btn.addEventListener('click', () => {
|
| 89 |
+
container.querySelectorAll('button').forEach(b => b.classList.remove('active'));
|
| 90 |
+
btn.classList.add('active');
|
| 91 |
+
const filtered = filterData(r.days);
|
| 92 |
+
renderStats(filtered);
|
| 93 |
+
renderChart(filtered);
|
| 94 |
+
});
|
| 95 |
+
container.appendChild(btn);
|
| 96 |
+
});
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function filterData(days) {
|
| 100 |
+
if (!days) return allData;
|
| 101 |
+
const cutoff = new Date(allData[allData.length - 1].x);
|
| 102 |
+
cutoff.setDate(cutoff.getDate() - days);
|
| 103 |
+
return allData.filter(d => d.x >= cutoff);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
const weekendBandsPlugin = {
|
| 107 |
+
id: 'weekendBands',
|
| 108 |
+
beforeDraw(chart) {
|
| 109 |
+
const { ctx, chartArea: { left, right, top, bottom }, scales: { x } } = chart;
|
| 110 |
+
if (!x) return;
|
| 111 |
+
const min = x.min;
|
| 112 |
+
const max = x.max;
|
| 113 |
+
// Find the first Saturday at midnight on or before the data start
|
| 114 |
+
const start = new Date(min);
|
| 115 |
+
start.setHours(0, 0, 0, 0);
|
| 116 |
+
while (start.getDay() !== 6) start.setDate(start.getDate() - 1);
|
| 117 |
+
|
| 118 |
+
ctx.save();
|
| 119 |
+
ctx.fillStyle = 'rgba(255, 140, 66, 0.1)';
|
| 120 |
+
const d = new Date(start);
|
| 121 |
+
while (d.getTime() <= max) {
|
| 122 |
+
const satStart = d.getTime();
|
| 123 |
+
const sunEnd = satStart + 2 * 24 * 60 * 60 * 1000;
|
| 124 |
+
const x0 = Math.max(x.getPixelForValue(satStart), left);
|
| 125 |
+
const x1 = Math.min(x.getPixelForValue(sunEnd), right);
|
| 126 |
+
if (x1 > left && x0 < right) {
|
| 127 |
+
ctx.fillRect(x0, top, x1 - x0, bottom - top);
|
| 128 |
+
}
|
| 129 |
+
d.setDate(d.getDate() + 7);
|
| 130 |
+
}
|
| 131 |
+
ctx.restore();
|
| 132 |
+
}
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
function isWeekend(date) {
|
| 136 |
+
const day = date.getDay();
|
| 137 |
+
return day === 0 || day === 6;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function renderChart(data) {
|
| 141 |
+
if (chart) chart.destroy();
|
| 142 |
+
const ctx = document.getElementById('chart').getContext('2d');
|
| 143 |
+
|
| 144 |
+
const gradient = ctx.createLinearGradient(0, 0, 0, 400);
|
| 145 |
+
gradient.addColorStop(0, 'rgba(0, 119, 182, 0.3)');
|
| 146 |
+
gradient.addColorStop(1, 'rgba(0, 119, 182, 0.01)');
|
| 147 |
+
|
| 148 |
+
const weekendGradient = ctx.createLinearGradient(0, 0, 0, 400);
|
| 149 |
+
weekendGradient.addColorStop(0, 'rgba(255, 140, 66, 0.3)');
|
| 150 |
+
weekendGradient.addColorStop(1, 'rgba(255, 140, 66, 0.01)');
|
| 151 |
+
|
| 152 |
+
chart = new Chart(ctx, {
|
| 153 |
+
type: 'line',
|
| 154 |
+
data: {
|
| 155 |
+
datasets: [{
|
| 156 |
+
label: 'Affluence',
|
| 157 |
+
data: data,
|
| 158 |
+
segment: {
|
| 159 |
+
borderColor: ctx2 => isWeekend(data[ctx2.p0DataIndex].x) && isWeekend(data[ctx2.p1DataIndex].x) ? '#e07020' : '#0077b6',
|
| 160 |
+
backgroundColor: ctx2 => isWeekend(data[ctx2.p0DataIndex].x) && isWeekend(data[ctx2.p1DataIndex].x) ? weekendGradient : gradient,
|
| 161 |
+
},
|
| 162 |
+
borderColor: '#0077b6',
|
| 163 |
+
backgroundColor: gradient,
|
| 164 |
+
borderWidth: 1.5,
|
| 165 |
+
fill: true,
|
| 166 |
+
pointRadius: 0,
|
| 167 |
+
pointHitRadius: 8,
|
| 168 |
+
tension: 0.3,
|
| 169 |
+
}]
|
| 170 |
+
},
|
| 171 |
+
plugins: [weekendBandsPlugin],
|
| 172 |
+
options: {
|
| 173 |
+
responsive: true,
|
| 174 |
+
maintainAspectRatio: false,
|
| 175 |
+
interaction: { mode: 'index', intersect: false },
|
| 176 |
+
scales: {
|
| 177 |
+
x: {
|
| 178 |
+
type: 'time',
|
| 179 |
+
time: { tooltipFormat: 'PPP p' },
|
| 180 |
+
grid: { display: false },
|
| 181 |
+
ticks: { maxTicksLimit: 10 },
|
| 182 |
+
},
|
| 183 |
+
y: {
|
| 184 |
+
beginAtZero: true,
|
| 185 |
+
title: { display: true, text: 'Affluence' },
|
| 186 |
+
grid: { color: '#eee' },
|
| 187 |
+
}
|
| 188 |
+
},
|
| 189 |
+
plugins: {
|
| 190 |
+
legend: { display: false },
|
| 191 |
+
tooltip: {
|
| 192 |
+
backgroundColor: 'rgba(0,0,0,0.8)',
|
| 193 |
+
padding: 10,
|
| 194 |
+
cornerRadius: 8,
|
| 195 |
+
callbacks: {
|
| 196 |
+
afterTitle: (items) => {
|
| 197 |
+
if (items.length && isWeekend(data[items[0].dataIndex].x)) return '(Weekend)';
|
| 198 |
+
return '';
|
| 199 |
+
},
|
| 200 |
+
label: (item) => ` Affluence: ${item.formattedValue} %`
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
});
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
loadCSV();
|
| 209 |
+
</script>
|
| 210 |
+
</body>
|
| 211 |
+
</html>
|