new statistics screen

This commit is contained in:
Mateo Körber Belmonte
2025-02-24 18:27:33 +01:00
parent 87336b0d77
commit 89d1d597f2
5 changed files with 238 additions and 1 deletions
+26
View File
@@ -0,0 +1,26 @@
document.addEventListener('DOMContentLoaded', () => {
fetch('/results')
.then(response => response.json())
.then(data => {
const categories = ['Fleischgericht', 'Vegetarisch', 'Tagesgericht', 'Tagessalat'];
const ratings = {
veryBad: 0,
bad: 0,
neutral: 0,
good: 0,
veryGood: 0
};
data.forEach(row => {
if (categories.includes(row.category)) {
ratings[row.rating]++;
}
});
const totalRatings = Object.values(ratings).reduce((a, b) => a + b, 0);
document.querySelector('.feedbackValue-countAllEver').textContent = totalRatings;
})
.catch(error => {
console.error('Error fetching results:', error);
});
});
+88
View File
@@ -0,0 +1,88 @@
document.addEventListener('DOMContentLoaded', () => {
fetch('/results')
.then(response => response.json())
.then(data => {
const categories = ['Fleischgericht', 'Vegetarisch', 'Tagesgericht', 'Tagessalat'];
const ratings = {
veryBad: 0,
bad: 0,
neutral: 0,
good: 0,
veryGood: 0
};
data.forEach(row => {
if (categories.includes(row.category)) {
ratings[row.rating]++;
}
});
const totalRatings = Object.values(ratings).reduce((a, b) => a + b, 0);
const ctx = document.getElementById('feedbackChart-distributionOfAllRatings').getContext('2d');
const chart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Sehr schlecht', 'Schlecht', 'Neutral', 'Gut', 'Sehr gut'],
datasets: [{
label: "Verteilung aller Bewertungen (N)",
data: [ratings.veryBad, ratings.bad, ratings.neutral, ratings.good, ratings.veryGood],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 159, 64, 0.2)',
'rgba(255, 205, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(54, 162, 235, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(255, 159, 64, 1)',
'rgba(255, 205, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(54, 162, 235, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
grid: {
color: 'rgba(126, 126, 126, 0.5)'
},
ticks: {
color: 'rgba(0, 0, 0, 1)' // Farbe der y-Achsenbeschriftungen
}
},
x: {
grid: {
color: 'rgba(126, 126, 126, 0.5)'
},
ticks: {
color: 'rgba(0, 0, 0, 1)' // Farbe der x-Achsenbeschriftungen
}
}
},
plugins: {
legend: {
onClick: (e, legendItem, legend) => {
const dataset = chart.data.datasets[0];
if (dataset.label === "Verteilung aller Bewertungen (N)") {
dataset.data = dataset.data.map(value => (value / totalRatings * 100).toFixed(2));
dataset.label = "Verteilung aller Bewertungen (%)";
} else {
dataset.data = [ratings.veryBad, ratings.bad, ratings.neutral, ratings.good, ratings.veryGood];
dataset.label = "Verteilung aller Bewertungen (N)";
}
chart.update();
}
}
}
}
});
})
.catch(error => {
console.error('Error fetching results:', error);
});
});
+75
View File
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feedback Statistics</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body style="overflow: visible;">
<h1>Feedback Statistics</h1>
<div class="charts-container">
<div class="value-wrapper">
<h2>Anzahl aller Bewertungen</h2>
<p class="feedbackValue feedbackValue-countAllEver">0</p>
<script src="countAllEver.js"></script>
</div>
<div class="chart-wrapper">
<h2>Anzahl Bewertungen letzter Woche</h2>
<canvas id="feedbackChart-totalCategoryCounts3" width="450" height="250"></canvas>
<script></script>
</div>
<div class="chart-wrapper">
<h2>Anzahl Bewertungen letzten Monat</h2>
<canvas id="feedbackChart-totalCategoryCounts4" width="450" height="250"></canvas>
<script src=""></script>
</div>
<div class="chart-wrapper">
<h2>Verteilung aller Bewertungen (N / %)</h2>
<canvas id="feedbackChart-distributionOfAllRatings" width="450" height="250"></canvas>
<script src="distributionOfAllRatings.js"></script>
</div>
<div class="chart-wrapper">
<h2>Vert. Bewertungen letzter Woche (N / %)</h2>
<canvas id="feedbackChart-totalCategoryCounts5" width="450" height="250"></canvas>
<script src=""></script>
</div>
<div class="chart-wrapper">
<h2>Vert. Bewertungen letzten Monat (N / %)</h2>
<canvas id="feedbackChart-totalCategoryCounts6" width="450" height="250"></canvas>
<script src="totalCategoryCounts.js"></script>
</div>
<div class="chart-wrapper">
<h2>Alle Bewertungen</h2>
<canvas id="feedbackChart-totalCategoryCounts7" width="450" height="250"></canvas>
<script src="totalCategoryCounts.js"></script>
</div>
<div class="chart-wrapper">
<h2>Alle Bewertungen</h2>
<canvas id="feedbackChart-totalCategoryCounts8" width="450" height="250"></canvas>
<script src="totalCategoryCounts.js"></script>
</div>
<div class="chart-wrapper">
<h2>Alle Bewertungen</h2>
<canvas id="feedbackChart-totalCategoryCounts8" width="450" height="250"></canvas>
<script src="totalCategoryCounts.js"></script>
</div>
</div>
</body>
</html>
+45 -1
View File
@@ -106,4 +106,48 @@ body {
th {
background-color: #4CAF50;
color: white;
}
}
.charts-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
}
.chart-wrapper {
padding: 0px 20px 20px 20px;
background: rgb(224, 224, 224);
border-radius: 20px;
color: black;
flex: 1 1 450px; /* Flex-grow, flex-shrink, flex-basis */
max-width: 450px;
}
.value-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
background: rgb(224, 224, 224);
border-radius: 20px;
color: black;
flex: 1 1 450px; /* Flex-grow, flex-shrink, flex-basis */
max-width: 450px;
text-align: center;
position: relative;
}
.value-wrapper h2 {
position: absolute;
top: 20px;
left: 105px;
margin: 0;
}
.feedbackValue {
font-size: 6rem;
font-weight: bold;
margin-top: 100px; /* Abstand zur Überschrift */
}
+4
View File
@@ -44,6 +44,10 @@ app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/statistics', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'statistics.html'));
});
// Handle form submission
app.post('/submit', (req, res) => {
let date = new Date().toLocaleString('de-DE', { timeZone: 'Europe/Berlin' }).replace('"', '').replace(',', '');