Merge pull request #1 from Matewoo/beta

Beta to main
This commit is contained in:
Mateo Körber Belmonte
2025-02-07 20:08:42 +01:00
committed by GitHub
5 changed files with 80 additions and 79 deletions
+10 -9
View File
@@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<h1>Bitte bewerten Sie Ihren heutigen Besuch</h1> <h1>Bitte bewerten Sie Ihren heutigen Besuch</h1>
<div class="content"> <div class="content" id="content">
<div> <div>
<div class="rating-container" style="justify-content:left;"> <div class="rating-container" style="justify-content:left;">
<h3>Fleisch/Fisch</h3> <h3>Fleisch/Fisch</h3>
@@ -21,8 +21,8 @@
<div class="rating-container" style="justify-content:left;"> <div class="rating-container" style="justify-content:left;">
<h3>Tagesgericht</h3> <h3>Tagesgericht</h3>
</div> </div>
<div class="rating-container" style="justify-content:left; margin-top: 20px; margin-bottom: 20px;"> <div class="rating-container" style="justify-content:left;">
<h3>Service</h3> <h3>Tagesalat</h3>
</div> </div>
</div> </div>
<div> <div>
@@ -53,11 +53,13 @@
<button class="emoji" data-category="Tagesgericht" id="veryGood">😋</button> <button class="emoji" data-category="Tagesgericht" id="veryGood">😋</button>
</div> </div>
</div> </div>
<div class="rating-container" style="margin-top: 20px; margin-bottom: 20px;"> <div class="rating-container">
<div class="emojies"> <div class="emojies">
<button class="emoji" data-category="Service" id="bad">☹️</button> <button class="emoji" data-category="Tagessalat" id="veryBad">😟</button>
<button class="emoji" data-category="Service" id="neutral">😐</button> <button class="emoji" data-category="Tagessalat" id="bad">☹️</button>
<button class="emoji" data-category="Service" id="good">🙂</button> <button class="emoji" data-category="Tagessalat" id="neutral">😐</button>
<button class="emoji" data-category="Tagessalat" id="good">🙂</button>
<button class="emoji" data-category="Tagessalat" id="veryGood">😋</button>
</div> </div>
</div> </div>
</div> </div>
@@ -66,13 +68,12 @@
<div style="width: 20rem;"> <div style="width: 20rem;">
</div> </div>
<div style="width: 20rem;"> <div style="width: 20rem;">
<button id="submit" style="margin-top: 0;">Abschicken</button>
</div> </div>
<div style="width: 20rem;"> <div style="width: 20rem;">
<img src="/resources/logo.png" alt="Logo" class="logo" height="100" style="margin-top: 40px;"> <img src="/resources/logo.png" alt="Logo" class="logo" height="100" style="margin-top: 40px;">
</div> </div>
</div> </div>
<div id="thank-you-message" style="display: none; margin-top: 20px; font-size: 2rem;">Vielen Dank für Ihr Feedback!</div> <div id="thank-you-message" style="display: none; margin-top: -420px; font-size: 5rem;">Vielen Dank für Ihr Feedback!</div>
<script src="script.js"></script> <script src="script.js"></script>
</body> </body>
</html> </html>
+6 -24
View File
@@ -1,23 +1,9 @@
document.querySelectorAll('.emoji').forEach(button => { document.querySelectorAll('.emoji').forEach(button => {
button.addEventListener('click', () => { button.addEventListener('click', () => {
const category = button.getAttribute('data-category'); const category = button.getAttribute('data-category');
if (category === 'Fleischgericht' || category === 'Vegetarisch' || category === 'Tagesgericht') { const results = {};
document.querySelectorAll('.emoji[data-category="Fleischgericht"], .emoji[data-category="Vegetarisch"], .emoji[data-category="Tagesgericht"]').forEach(btn => btn.classList.remove('selected'));
} else {
document.querySelectorAll(`.emoji[data-category="${category}"]`).forEach(btn => btn.classList.remove('selected'));
}
button.classList.add('selected');
});
});
document.getElementById('submit').addEventListener('click', () => {
const results = {};
document.querySelectorAll('.emoji.selected').forEach(button => {
const category = button.getAttribute('data-category');
results[category] = button.id; results[category] = button.id;
});
if (Object.keys(results).length > 0) {
fetch('/submit', { fetch('/submit', {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -29,19 +15,15 @@ document.getElementById('submit').addEventListener('click', () => {
.then(data => { .then(data => {
console.log('Success:', data); console.log('Success:', data);
document.getElementById('thank-you-message').style.display = 'block'; document.getElementById('thank-you-message').style.display = 'block';
document.getElementById('content').style.visibility = 'hidden';
setTimeout(() => { setTimeout(() => {
document.getElementById('thank-you-message').style.display = 'none'; document.getElementById('thank-you-message').style.display = 'none';
document.getElementById('content').style.visibility = 'visible';
document.querySelectorAll('.emoji').forEach(button => button.classList.remove('selected')); document.querySelectorAll('.emoji').forEach(button => button.classList.remove('selected'));
}, 1000); }, 2500);
}) })
.catch((error) => { .catch((error) => {
console.error('Error:', error); console.error('Error:', error);
}); });
} });
});
const submitButton = document.getElementById('submit');
submitButton.disabled = true;
setTimeout(() => {
submitButton.disabled = false;
}, 1000);
});
+4 -4
View File
@@ -20,7 +20,7 @@ body {
h1 { h1 {
font-size: 3rem; font-size: 3rem;
margin-bottom: 70px; margin-bottom: 70px;
padding-top: 3rem; padding-top: 1rem;
-webkit-user-select: none; /* Safari */ -webkit-user-select: none; /* Safari */
-moz-user-select: none; -moz-user-select: none;
-ms-user-select: none; -ms-user-select: none;
@@ -41,7 +41,7 @@ body {
grid-template-columns:auto 3fr; grid-template-columns:auto 3fr;
gap: 250px; gap: 250px;
align-items: flex-start; align-items: flex-start;
margin-top:30px; margin-top:20px;
margin-left: 12rem; margin-left: 12rem;
margin-right: 12rem; margin-right: 12rem;
margin-bottom: -70px; margin-bottom: -70px;
@@ -51,7 +51,7 @@ body {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
height: 130px; /* Feste Höhe für die Zeilen */ height: 150px; /* Feste Höhe für die Zeilen */
} }
.rating-container h3 { .rating-container h3 {
@@ -64,7 +64,7 @@ body {
} }
button { button {
font-size: 5rem; font-size: 6rem;
border: none; border: none;
border-radius: 10px; border-radius: 10px;
background-color: #f0f0f0; background-color: #f0f0f0;
+60 -42
View File
@@ -17,8 +17,20 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json()); app.use(bodyParser.json());
// CSV Writer setup // CSV Writer setup
const csvFilePath = path.join(__dirname, '../tablet-web-survey-data/data.csv');
const csvDir = path.dirname(csvFilePath);
// Ensure the directory exists
if (!fs.existsSync(csvDir)) {
fs.mkdirSync(csvDir, { recursive: true });
}
// Ensure the file exists
if (!fs.existsSync(csvFilePath)) {
fs.writeFileSync(csvFilePath, 'DATE,CATEGORY,RATING\n');
}
const csvWriter = createCsvWriter({ const csvWriter = createCsvWriter({
path: 'survey_results.csv', path: csvFilePath,
header: [ header: [
{ id: 'date', title: 'DATE' }, { id: 'date', title: 'DATE' },
{ id: 'category', title: 'CATEGORY' }, { id: 'category', title: 'CATEGORY' },
@@ -34,7 +46,7 @@ app.get('/', (req, res) => {
// Handle form submission // Handle form submission
app.post('/submit', (req, res) => { app.post('/submit', (req, res) => {
const date = new Date().toISOString().replace('T', ' ').split('.')[0]; // Aktuelles Datum und Uhrzeit let date = new Date().toLocaleString('de-DE', { timeZone: 'Europe/Berlin' }).replace('"', '').replace(',', '');
const results = req.body; const results = req.body;
// Ergebnisse in die CSV-Datei einfügen // Ergebnisse in die CSV-Datei einfügen
@@ -70,7 +82,7 @@ app.get('/survey', (req, res) => {
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
</head> </head>
<body> <body style="overflow-y: scroll;">
<h1>Survey Results</h1> <h1>Survey Results</h1>
<div id="results"></div> <div id="results"></div>
<script> <script>
@@ -95,7 +107,7 @@ app.get('/survey', (req, res) => {
// Serve the survey results data // Serve the survey results data
app.get('/results', (req, res) => { app.get('/results', (req, res) => {
const csvFilePath = 'survey_results.csv'; const csvFilePath = path.join(__dirname, '../tablet-web-survey-data/data.csv');
csv({ csv({
noheader: true, noheader: true,
headers: ['date', 'category', 'rating'] headers: ['date', 'category', 'rating']
@@ -131,12 +143,12 @@ app.get('/summary', (req, res) => {
<table id="summary-table"> <table id="summary-table">
<thead> <thead>
<tr> <tr>
<th>Category</th> <th>Gericht</th>
<th>Monday</th> <th style="width: 18%;">Montag</th>
<th>Tuesday</th> <th style="width: 18%;">Dienstg</th>
<th>Wednesday</th> <th style="width: 18%;">Mittwoch</th>
<th>Thursday</th> <th style="width: 18%;">Donnerstag</th>
<th>Friday</th> <th style="width: 18%;">Freitag</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -155,21 +167,21 @@ app.get('/summary', (req, res) => {
} }
function fetchSummary() { function fetchSummary() {
fetch(\`/weekly-summary?week=\${currentWeek.toISOString()}\`) fetch(\`/weekly-summary?week=\${currentWeek.toISOString().split('T')[0]}\`)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
const tableBody = document.getElementById('summary-table').getElementsByTagName('tbody')[0]; const tableBody = document.getElementById('summary-table').getElementsByTagName('tbody')[0];
tableBody.innerHTML = ''; tableBody.innerHTML = '';
const categories = ['Fleischgericht', 'Vegetarisch', 'Tagesgericht', 'Service']; const categories = ['Fleischgericht', 'Vegetarisch', 'Tagesgericht', 'Tagessalat'];
categories.forEach(category => { categories.forEach(category => {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.innerHTML = \` tr.innerHTML = \`
<td>\${category}</td> <td>\${category}</td>
<td>\${data.Monday[category]}</td> <td>\${data.Monday[category].average} ⭐ (\${data.Monday[category].count} P)</td>
<td>\${data.Tuesday[category]}</td> <td>\${data.Tuesday[category].average} ⭐ (\${data.Tuesday[category].count} P)</td>
<td>\${data.Wednesday[category]}</td> <td>\${data.Wednesday[category].average} ⭐ (\${data.Wednesday[category].count} P)</td>
<td>\${data.Thursday[category]}</td> <td>\${data.Thursday[category].average} ⭐ (\${data.Thursday[category].count} P)</td>
<td>\${data.Friday[category]}</td> <td>\${data.Friday[category].average} ⭐ (\${data.Friday[category].count} P)</td>
\`; \`;
tableBody.appendChild(tr); tableBody.appendChild(tr);
}); });
@@ -201,11 +213,22 @@ app.get('/summary', (req, res) => {
// Serve the weekly summary data // Serve the weekly summary data
app.get('/weekly-summary', (req, res) => { app.get('/weekly-summary', (req, res) => {
const weekStart = new Date(req.query.week); const week = req.query.week;
const weekEnd = new Date(weekStart); if (!week) {
weekEnd.setDate(weekStart.getDate() + 4); // Friday of the selected week return res.status(400).json({ status: 'error', message: 'Week query parameter is required! Example: domain.com/weekly-summary?week=2025-02-03' });
}
const csvFilePath = 'survey_results.csv'; const [year, month, day] = week.split('-').map(Number);
const weekStart = new Date(Date.UTC(year, month - 1, day));
if (isNaN(weekStart.getTime())) {
return res.status(400).json({ status: 'error', message: 'Invalid date format' });
}
const weekEnd = new Date(weekStart);
weekEnd.setUTCDate(weekStart.getUTCDate() + 4); // Friday of the selected week
weekEnd.setUTCHours(23, 59, 59, 999); // End of Friday
const csvFilePath = path.join(__dirname, '../tablet-web-survey-data/data.csv');
csv({ csv({
noheader: true, noheader: true,
headers: ['date', 'category', 'rating'] headers: ['date', 'category', 'rating']
@@ -213,11 +236,11 @@ app.get('/weekly-summary', (req, res) => {
.fromFile(csvFilePath) .fromFile(csvFilePath)
.then((jsonObj) => { .then((jsonObj) => {
const summary = { const summary = {
Monday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Service: [] }, Monday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Tagessalat: [] },
Tuesday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Service: [] }, Tuesday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Tagessalat: [] },
Wednesday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Service: [] }, Wednesday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Tagessalat: [] },
Thursday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Service: [] }, Thursday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Tagessalat: [] },
Friday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Service: [] } Friday: { Fleischgericht: [], Vegetarisch: [], Tagesgericht: [], Tagessalat: [] }
}; };
const ratingValues = { const ratingValues = {
@@ -228,34 +251,29 @@ app.get('/weekly-summary', (req, res) => {
veryGood: 5 veryGood: 5
}; };
const serviceRatingValues = { jsonObj.slice(1).forEach(row => {
bad: 1, const [datePart, timePart] = row.date.split(' ');
neutral: 2, const [day, month, year] = datePart.split('.').map(Number);
good: 3 const [hours, minutes, seconds] = timePart.split(':').map(Number);
}; const date = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
jsonObj.forEach(row => {
const date = new Date(row.date);
if (date >= weekStart && date <= weekEnd) { if (date >= weekStart && date <= weekEnd) {
const day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getDay()]; const dayName = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getUTCDay()];
if (summary[day]) { if (summary[dayName]) {
if (row.category === 'Service') { summary[dayName][row.category].push(ratingValues[row.rating]);
summary[day][row.category].push(serviceRatingValues[row.rating]);
} else {
summary[day][row.category].push(ratingValues[row.rating]);
}
} }
} }
}); });
// Calculate average ratings // Calculate average ratings and count votes
const averageSummary = {}; const averageSummary = {};
Object.keys(summary).forEach(day => { Object.keys(summary).forEach(day => {
averageSummary[day] = {}; averageSummary[day] = {};
Object.keys(summary[day]).forEach(category => { Object.keys(summary[day]).forEach(category => {
const ratings = summary[day][category]; const ratings = summary[day][category];
const average = ratings.length ? (ratings.reduce((a, b) => a + b, 0) / ratings.length).toFixed(2) : 'N/A'; const average = ratings.length ? (ratings.reduce((a, b) => a + b, 0) / ratings.length).toFixed(2) : 'N/A';
averageSummary[day][category] = average; const count = ratings.length;
averageSummary[day][category] = { average, count };
}); });
}); });
View File