Add YAML-driven report generation

This commit is contained in:
Jordan Wages 2025-07-18 01:24:26 -05:00
commit 6241fd2685
6 changed files with 214 additions and 60 deletions

View file

@ -9,34 +9,42 @@
<body class="section">
<div class="container">
<h1 class="title">{{ interval.title() }} Report</h1>
<canvas id="chart"></canvas>
{% for report in reports %}
<div class="box">
<h2 class="subtitle">{{ report.label }}</h2>
<canvas id="chart-{{ report.name }}"></canvas>
</div>
{% endfor %}
</div>
<script>
fetch('{{ json_path }}')
.then(r => r.json())
.then(data => {
const labels = data.map(x => x.bucket);
const hits = data.map(x => x.hits);
new Chart(document.getElementById('chart'), {
type: '{{ 'bar' if interval == 'hourly' else 'line' }}',
data: {
labels: labels,
datasets: [{
label: 'Hits',
data: hits,
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
fill: true,
}]
},
options: {
scales: {
y: { beginAtZero: true }
const reports = {{ reports | tojson }};
reports.forEach(rep => {
fetch(rep.json)
.then(r => r.json())
.then(data => {
const labels = data.map(x => x.bucket);
const values = data.map(x => x.value);
new Chart(document.getElementById('chart-' + rep.name), {
type: rep.chart,
data: {
labels: labels,
datasets: [{
label: rep.label,
data: values,
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
fill: rep.chart !== 'bar',
}]
},
options: {
scales: {
y: { beginAtZero: true }
}
}
}
});
});
});
});
</script>
</body>
</html>