forked from brocoli-midoriya/mess-menu-mate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_analytics_files.2sh
More file actions
486 lines (440 loc) · 21.9 KB
/
Copy pathupdate_analytics_files.2sh
File metadata and controls
486 lines (440 loc) · 21.9 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
if [ -d "js" ]; then
echo "Directory 'js/' already exists. Skipping creation."
else
echo "Creating directory: js/"
mkdir js
fi
echo "Writing index.html (overwriting old content)..."
cat << 'EOF' > index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mess Food Analytics Dashboard</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Chart.js CDN for the bar graph -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script>
<style>
/* Custom font and basic setup */
body {
font-family: 'Inter', sans-serif;
background-color: #f7f9fb;
}
.tab-button.active {
border-color: #10b981;
color: #10b981;
font-weight: 600;
background-color: #ecfdf5;
}
</style>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
'primary': '#10b981',
'secondary': '#3b82f6',
'neutral-bg': '#f7f9fb',
'card-bg': '#ffffff',
}
}
}
}
</script>
</head>
<body class="min-h-screen p-4 sm:p-8">
<div id="analytics-app" class="max-w-6xl mx-auto">
<header class="mb-8">
<h1 class="text-4xl font-extrabold text-gray-900 mb-2">📊 Food Review Insights</h1>
<p class="text-gray-600 text-lg">Analyze daily performance and weekly trends in mess food reviews.</p>
</header>
<!-- Tab Navigation -->
<div class="flex border-b border-gray-200 mb-6">
<button id="daily-tab-btn" onclick="showTab('daily')" class="tab-button active py-3 px-6 text-lg border-b-2 border-transparent transition duration-200 hover:border-primary-light focus:outline-none">
<span class="mr-2">📅</span> Daily Snapshot
</button>
<button id="weekly-tab-btn" onclick="showTab('weekly')" class="tab-button py-3 px-6 text-lg border-b-2 border-transparent transition duration-200 hover:border-primary-light focus:outline-none">
<span class="mr-2">📈</span> Weekly Trends
</button>
</div>
<!-- Content Containers -->
<div id="daily-content" class="tab-content">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Daily Review Analysis</h2>
<!-- Date Picker and Output -->
<div class="flex flex-col sm:flex-row items-start sm:items-center space-y-3 sm:space-y-0 sm:space-x-4 mb-6 p-4 bg-white rounded-xl shadow-lg border border-gray-100">
<label for="date-picker" class="text-lg font-medium text-gray-700">Select Date (Oct 7 - Oct 13):</label>
<input type="date" id="date-picker" class="p-3 border border-gray-300 rounded-lg text-lg focus:ring-primary focus:border-primary transition duration-150" value="2025-10-10" onchange="loadDailyData(this.value)">
<span id="daily-date-display" class="text-xl font-bold text-secondary ml-auto hidden sm:block"></span>
</div>
<!-- Daily Summary and Emoji Breakdown Grid -->
<div id="daily-summary-breakdown" class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
<!-- 1. Rating Overview -->
<div class="bg-card-bg p-6 rounded-xl shadow-lg border-t-4 border-primary transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">⭐ Daily Rating Overview</h3>
<div class="space-y-3">
<div class="flex justify-between items-center text-gray-700">
<span class="text-lg">Total Reviews Submitted:</span>
<span id="total-reviews" class="text-2xl font-bold text-secondary"></span>
</div>
<div class="flex justify-between items-center text-gray-700 border-t pt-3">
<span class="text-lg">Average Rating:</span>
<span id="average-rating" class="text-3xl font-extrabold text-primary"></span>
</div>
</div>
</div>
<!-- 2. Emoji Rating Breakdown -->
<div class="bg-card-bg p-6 rounded-xl shadow-lg border-t-4 border-secondary transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">😋 Emoji Breakdown</h3>
<div id="emoji-breakdown" class="space-y-2">
<!-- Emoji ratings will be injected here -->
</div>
</div>
</div>
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Meal-wise Satisfaction Overview</h2>
<!-- Daily Meal Breakdown Grid (Unchanged) -->
<div id="daily-meal-breakdown" class="grid grid-cols-1 md:grid-cols-3 gap-6">
<!-- Meal cards will be injected here by JavaScript -->
</div>
<div id="no-data-message" class="hidden text-center p-8 bg-white rounded-xl shadow-lg text-gray-500 text-lg">
No meal data available for the selected date.
</div>
</div>
<div id="weekly-content" class="tab-content hidden">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Weekly Performance (Previous Week)</h2>
<!-- Weekly Stats Grid -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- 1. Top 5 Dishes Bar Graph (Span 2 columns on large screens) -->
<div class="lg:col-span-2 bg-card-bg p-6 rounded-xl shadow-lg border-t-4 border-primary transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-semibold text-gray-800 mb-4">🏆 Top 5 Most Preferred Dishes</h3>
<div class="h-80">
<canvas id="topDishesChart"></canvas>
</div>
</div>
<!-- 2. Comment Summary (Good & Bad) -->
<div class="lg:col-span-1 space-y-6">
<!-- Top Good Comments -->
<div class="bg-card-bg p-6 rounded-xl shadow-lg border-t-4 border-yellow-500 transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">👍 Top Good Comments</h3>
<div id="good-comments-list" class="space-y-4">
<!-- Good comments injected here -->
</div>
</div>
<!-- Top Bad Comments -->
<div class="bg-card-bg p-6 rounded-xl shadow-lg border-t-4 border-red-500 transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">👎 Top Bad Comments (For Improvement)</h3>
<div id="bad-comments-list" class="space-y-4">
<!-- Bad comments injected here -->
</div>
</div>
</div>
</div>
</div>
</div>
<script type="module">
import './js/analytics.js';
</script>
</body>
</html>
EOF
echo "Creating js/mockData.js..."
cat << 'EOF' > js/mockData.js
export const MOCK_REVIEW_DATA = {
"2025-10-07": {
date: "Monday, Oct 7",
totalReviews: 120,
avgRating: 4.17,
emojiRatings: { "😋 Loved (5)": 40, "👍 Liked (4)": 35, "😐 Meh (3)": 30, "👎 Disliked (2)": 10, "🤢 Hated (1)": 5 },
meals: {
breakfast: { avgRating: 4.5, reviews: 40, comment: "The Poha was very light and tasty. Great start to the week!", satisfaction: 'Outstanding' },
lunch: { avgRating: 3.2, reviews: 50, comment: "Chapati quality was rubbery. Needs improvement for sure.", satisfaction: 'Fair' },
dinner: { avgRating: 4.8, reviews: 30, comment: "Loved the Chicken Curry! Full of flavor and well-cooked.", satisfaction: 'Excellent' }
}
},
"2025-10-08": {
date: "Tuesday, Oct 8",
totalReviews: 130,
avgRating: 3.63,
emojiRatings: { "😋 Loved (5)": 30, "👍 Liked (4)": 40, "😐 Meh (3)": 35, "👎 Disliked (2)": 15, "🤢 Hated (1)": 10 },
meals: {
breakfast: { avgRating: 3.8, reviews: 35, comment: "Dosa was crispy but the sambar was cold.", satisfaction: 'Good' },
lunch: { avgRating: 4.1, reviews: 55, comment: "The dessert was a pleasant surprise today!", satisfaction: 'Excellent' },
dinner: { avgRating: 3.0, reviews: 40, comment: "The dal was bland and watery. Zero flavor.", satisfaction: 'Neutral' }
}
},
"2025-10-09": {
date: "Wednesday, Oct 9",
totalReviews: 155,
avgRating: 3.7,
emojiRatings: { "😋 Loved (5)": 45, "👍 Liked (4)": 50, "😐 Meh (3)": 40, "👎 Disliked (2)": 10, "🤢 Hated (1)": 10 },
meals: {
breakfast: { avgRating: 4.7, reviews: 45, comment: "Parathas were perfectly flaky and fresh.", satisfaction: 'Outstanding' },
lunch: { avgRating: 3.9, reviews: 60, comment: "The Paneer dish was tasty, but the portions were too small.", satisfaction: 'Good' },
dinner: { avgRating: 2.5, reviews: 50, comment: "Fish was not fresh. Felt sick after eating. Please investigate.", satisfaction: 'Poor' }
}
},
"2025-10-10": {
date: "Thursday, Oct 10",
totalReviews: 160,
avgRating: 3.97,
emojiRatings: { "😋 Loved (5)": 55, "👍 Liked (4)": 45, "😐 Meh (3)": 30, "👎 Disliked (2)": 20, "🤢 Hated (1)": 10 },
meals: {
breakfast: { avgRating: 3.1, reviews: 50, comment: "Tea was oversweetened. Couldn't finish it.", satisfaction: 'Fair' },
lunch: { avgRating: 4.6, reviews: 65, comment: "Simple but perfectly made Dal Makhani. Very filling!", satisfaction: 'Excellent' },
dinner: { avgRating: 4.2, reviews: 45, comment: "Tandoori roti was crisp and hot. Great job!", satisfaction: 'Very Good' }
}
},
"2025-10-11": {
date: "Friday, Oct 11",
totalReviews: 165,
avgRating: 3.73,
emojiRatings: { "😋 Loved (5)": 40, "👍 Liked (4)": 60, "😐 Meh (3)": 35, "👎 Disliked (2)": 20, "🤢 Hated (1)": 10 },
meals: {
breakfast: { avgRating: 4.0, reviews: 40, comment: "The fruit provided was ripe and fresh.", satisfaction: 'Very Good' },
lunch: { avgRating: 3.5, reviews: 70, comment: "Waiting time for the counter was too long.", satisfaction: 'Good' },
dinner: { avgRating: 3.7, reviews: 55, comment: "Good taste, but a slightly less oily preparation would be better.", satisfaction: 'Good' }
}
},
"2025-10-12": {
date: "Saturday, Oct 12",
totalReviews: 120,
avgRating: 4.03,
emojiRatings: { "😋 Loved (5)": 50, "👍 Liked (4)": 30, "😐 Meh (3)": 20, "👎 Disliked (2)": 10, "🤢 Hated (1)": 10 },
meals: {
breakfast: { avgRating: 4.9, reviews: 30, comment: "Weekend special! The Puri Bhaji was a treat!", satisfaction: 'Outstanding' },
lunch: { avgRating: 2.9, reviews: 40, comment: "Disappointed with the lack of variety in the salad bar.", satisfaction: 'Fair' },
dinner: { avgRating: 4.3, reviews: 50, comment: "The dessert was top-notch. Everyone enjoyed it!", satisfaction: 'Excellent' }
}
},
"2025-10-13": {
date: "Sunday, Oct 13",
totalReviews: 175,
avgRating: 3.67,
emojiRatings: { "😋 Loved (5)": 45, "👍 Liked (4)": 50, "😐 Meh (3)": 40, "👎 Disliked (2)": 25, "🤢 Hated (1)": 15 },
meals: {
breakfast: { avgRating: 3.6, reviews: 40, comment: "The coffee machine was broken this morning.", satisfaction: 'Good' },
lunch: { avgRating: 4.4, reviews: 75, comment: "North Indian dishes were well spiced and satisfying.", satisfaction: 'Excellent' },
dinner: { avgRating: 3.0, reviews: 60, comment: "", satisfaction: 'Neutral' }
}
},
};
export const MOCK_WEEKLY_DATA = {
topDishes: [
{ dish: "Butter Chicken", count: 98 },
{ dish: "Aloo Paratha", count: 91 },
{ dish: "Veg Biryani", count: 75 },
{ dish: "Paneer Chilli", count: 62 },
{ dish: "Rajma Chawal", count: 55 },
],
topComments: {
good: [
{ text: "The Butter Chicken was exceptional! Best dish of the week.", likes: 154 },
{ text: "Great effort on the breakfast variety. Loved the new juice option.", likes: 88 },
{ text: "Portion size was perfect today. Keep it up!", likes: 52 },
],
bad: [
{ text: "The rice quality needs serious improvement; it was undercooked twice.", likes: 210 },
{ text: "Too much oil in the evening snacks. Please reduce.", likes: 121 },
{ text: "Serving staff seemed overwhelmed and service was slow.", likes: 95 },
]
}
};
EOF
echo "Creating js/analytics.js (Core Logic)..."
cat << 'EOF' > js/analytics.js
import { MOCK_REVIEW_DATA, MOCK_WEEKLY_DATA } from './mockData.js';
let topDishesChart = null;
function getSatisfactionStyle(satisfaction) {
switch (satisfaction) {
case 'Outstanding': return { color: 'text-green-600', bgBorder: 'border-green-500', icon: '🌟' };
case 'Excellent': return { color: 'text-primary', bgBorder: 'border-primary', icon: '✅' };
case 'Very Good': return { color: 'text-blue-500', bgBorder: 'border-blue-500', icon: '👍' };
case 'Good': return { color: 'text-yellow-600', bgBorder: 'border-yellow-500', icon: '🙂' };
case 'Neutral': return { color: 'text-gray-500', bgBorder: 'border-gray-500', icon: '😐' };
case 'Fair': return { color: 'text-orange-500', bgBorder: 'border-orange-500', icon: '⚠️' };
case 'Poor': return { color: 'text-red-500', bgBorder: 'border-red-500', icon: '❌' };
default: return { color: 'text-gray-400', bgBorder: 'border-gray-400', icon: '❓' };
}
}
function getBarColor(emoji) {
if (emoji.includes('Loved')) return '#34d399';
if (emoji.includes('Liked')) return '#60a5fa';
if (emoji.includes('Meh')) return '#facc15';
if (emoji.includes('Disliked')) return '#fb923c';
if (emoji.includes('Hated')) return '#f87171';
return '#9ca3af';
}
function renderDailySummary(data) {
document.getElementById('total-reviews').textContent = data.totalReviews;
document.getElementById('average-rating').textContent = `${data.avgRating.toFixed(2)} / 5.0`;
const breakdownEl = document.getElementById('emoji-breakdown');
breakdownEl.innerHTML = '';
Object.entries(data.emojiRatings).forEach(([emoji, count]) => {
const total = data.totalReviews;
const percentage = total > 0 ? ((count / total) * 100).toFixed(1) : 0;
const barColor = getBarColor(emoji);
const item = document.createElement('div');
item.className = 'py-2';
item.innerHTML = `
<div class="flex justify-between items-center text-sm font-medium text-gray-700">
<span>${emoji}</span>
<span>${count} reviews (${percentage}%)</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5 mt-1">
<div class="h-2.5 rounded-full" style="width: ${percentage}%; background-color: ${barColor};"></div>
</div>
`;
breakdownEl.appendChild(item);
});
}
window.loadDailyData = function(dateString) {
const data = MOCK_REVIEW_DATA[dateString];
const breakdownEl = document.getElementById('daily-meal-breakdown');
const dateDisplayEl = document.getElementById('daily-date-display');
const noDataMessage = document.getElementById('no-data-message');
breakdownEl.innerHTML = '';
noDataMessage.classList.add('hidden');
dateDisplayEl.textContent = data ? data.date : 'N/A';
if (!data || !data.meals) {
noDataMessage.classList.remove('hidden');
document.getElementById('total-reviews').textContent = 'N/A';
document.getElementById('average-rating').textContent = 'N/A';
document.getElementById('emoji-breakdown').innerHTML = '';
return;
}
renderDailySummary(data);
Object.keys(data.meals).forEach(mealKey => {
const mealData = data.meals[mealKey];
const mealTitle = mealKey.charAt(0).toUpperCase() + mealKey.slice(1);
const { color, bgBorder, icon } = getSatisfactionStyle(mealData.satisfaction);
const studentCommentHtml = mealData.comment.trim() !== ""
? `<div class="mt-4">
<h4 class="text-sm font-semibold text-gray-700 mb-2 flex items-center">📣 Top Student Comment:</h4>
<p class="text-gray-600 italic border-l-4 border-gray-200 pl-3 py-1 text-sm">"${mealData.comment}"</p>
</div>`
: `<div class="mt-4 text-center text-gray-400 text-sm italic py-2">No top comment recorded for this meal.</div>`;
const cardHtml = `
<div class="bg-card-bg p-6 rounded-xl shadow-lg border-t-4 ${bgBorder} transition duration-300 hover:shadow-xl">
<h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
<span class="mr-2">${icon}</span> ${mealTitle}
</h3>
<div class="flex justify-between items-center mb-4 border-b pb-3">
<div>
<span class="text-xs font-semibold uppercase text-gray-500 block">Avg Rating (${mealData.reviews} reviews)</span>
<span class="text-3xl font-extrabold ${color}">${mealData.avgRating.toFixed(1)} / 5.0</span>
</div>
<div class="text-right">
<span class="text-xs font-semibold uppercase text-gray-500 block">Satisfaction Level</span>
<span class="text-xl font-bold ${color}">${mealData.satisfaction}</span>
</div>
</div>
${studentCommentHtml}
</div>
`;
breakdownEl.insertAdjacentHTML('beforeend', cardHtml);
});
}
function renderWeeklyData() {
const dishes = MOCK_WEEKLY_DATA.topDishes;
const labels = dishes.map(d => d.dish);
const counts = dishes.map(d => d.count);
const ctx = document.getElementById('topDishesChart').getContext('2d');
if (topDishesChart) {
topDishesChart.destroy();
}
topDishesChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Total Votes/Preferences',
data: counts,
backgroundColor: [
'#10b981',
'#3b82f6',
'#f59e0b',
'#ef4444',
'#a855f7',
],
borderColor: '#ffffff',
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Number of Preferences'
}
},
x: {
grid: {
display: false
}
}
},
plugins: {
legend: {
display: false
},
title: {
display: false
}
}
}
});
const renderComments = (containerId, comments, isGood) => {
const container = document.getElementById(containerId);
container.innerHTML = '';
comments.forEach(comment => {
const bgColor = isGood ? 'bg-yellow-50' : 'bg-red-50';
const icon = isGood ? '⭐' : '🚨';
const heartColor = isGood ? 'text-yellow-600' : 'text-red-600';
const item = document.createElement('div');
item.className = `p-3 rounded-lg ${bgColor} border-l-4 ${isGood ? 'border-yellow-500' : 'border-red-500'}`;
item.innerHTML = `
<p class="text-gray-700 italic text-sm mb-2">${icon} "${comment.text}"</p>
<div class="flex items-center justify-end text-xs font-semibold ${heartColor}">
<span class="mr-1">❤️</span>
<span>${comment.likes} Support/Likes</span>
</div>
`;
container.appendChild(item);
});
}
renderComments('good-comments-list', MOCK_WEEKLY_DATA.topComments.good, true);
renderComments('bad-comments-list', MOCK_WEEKLY_DATA.topComments.bad, false);
}
window.showTab = function(tabId) {
const tabs = ['daily', 'weekly'];
tabs.forEach(id => {
const content = document.getElementById(`${id}-content`);
const button = document.getElementById(`${id}-tab-btn`);
if (id === tabId) {
content.classList.remove('hidden');
button.classList.add('active');
if (id === 'weekly') {
renderWeeklyData();
}
} else {
content.classList.add('hidden');
button.classList.remove('active');
}
});
}
document.addEventListener('DOMContentLoaded', () => {
const datePicker = document.getElementById('date-picker');
datePicker.min = '2025-10-07';
datePicker.max = '2025-10-13';
const initialDate = '2025-10-10';
datePicker.value = initialDate;
window.loadDailyData(initialDate);
});
EOF
echo "---"
echo "✅ All files have been updated."