-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
204 lines (184 loc) · 8.27 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mensaar Daily Menu</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="src/w3schools.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<script src="https://kit.fontawesome.com/e357f5b9b7.js" crossorigin="anonymous"></script>
<style>
body {
font-family: "Roboto", sans-serif;
background-image: url('src/uds_spirit.jpg');
}
.maincontent {
padding: 10px;
background-color: #13467d;
max-width: 900px;
color: white;
}
th,
td {
border: 1px solid whitesmoke;
padding: 6px;
}
</style>
</head>
<body>
<div id="app" class="maincontent">
<!-- Show Menu if not showing Statistics -->
<div v-if="menu && !showingStatistics">
<h1>Mensaar Menu collection (since 25.09.2024)</h1>
<button @click="changeDate(-1)">Yesterday</button>
<button @click="showStatistics">Show Statistics</button>
<button @click="changeDate(1)">Tomorrow</button>
<h2>{{ menu.date }}</h2>
<div v-for="(mealList, mealType) in menu.meals" :key="mealType">
<div v-for="meal in mealList" :key="meal.meal">
<div v-if="Object.keys(meal.components).length > 0">
<h3>{{ mealType }}</h3>
<table>
<tr>
<th>Dish Name</th>
<th>Main/Side Dish</th>
<th>Occurrence</th>
</tr>
<tr v-for="meal in mealList" :key="meal.meal">
<td>{{ meal.meal }}</td>
<td>Main Dish</td>
<td>{{ ((mealCount[meal.meal] || 0) / totalDays * 100).toFixed(1) }}% ({{
mealCount[meal.meal]
|| 0 }} / {{ totalDays }})</td>
</tr>
<tr v-for="(count, component) in meal.components" :key="component">
<td>{{ component }}</td>
<td>Side Dish</td>
<td>{{ ((componentCount[component] || 0) / totalDays * 100).toFixed(1) }}% ({{
componentCount[component] || 0 }} / {{totalDays }})</td>
</tr>
</table>
</div>
<div v-else>
<h3>{{ mealType }}</h3>
<table>
<tr>
<th>Dish Name</th>
<th>Main/Side Dish</th>
<th>Occurrence</th>
</tr>
<tr v-for="meal in mealList" :key="meal.meal">
<td>{{ meal.meal }}</td>
<td>Main Dish</td>
<td>{{ ((mealCount[meal.meal] || 0) / totalDays * 100).toFixed(1) }}% ({{
mealCount[meal.meal]
|| 0 }} / {{ totalDays }})</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div v-if="!menu && !showingStatistics">
<h1>No data on the day you selected.</h1>
<button @click="changeDate(-1)">Yesterday</button>
<button @click="changeDate(1)">Tomorrow</button>
<h2>Valid Date Range: 25.09.2024 - Today</h2>
</div>
<!-- Statistics Section -->
<div v-if="showingStatistics">
<h1>Mensaar Statistics (since 25.09.2024)</h1>
<button @click="showingStatistics = false">Close Statistics</button>
<h2>Main Dish Statistics</h2>
<table>
<tr>
<th>Dish Name</th>
<th>Occurrence</th>
</tr>
<tr v-for="(count, meal) in mealCount" :key="meal">
<td>{{ meal }}</td>
<td>{{ ((count / totalDays) * 100).toFixed(1) }}% ({{ count }} / {{ totalDays }})</td>
</tr>
</table>
<h2>Side Dish Statistics</h2>
<table>
<tr>
<th>Dish Name</th>
<th>Occurrence</th>
</tr>
<tr v-for="(count, component) in componentCount" :key="component">
<td>{{ component }}</td>
<td>{{ ((count / totalDays) * 100).toFixed(1) }}% ({{ count }} / {{ totalDays }})</td>
</tr>
</table>
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
menu: null,
mealCount: {},
componentCount: {},
showingStatistics: false, // Flag to control statistics visibility
totalDays: 0 // To hold the total number of days
},
mounted() {
this.calculateTotalDays(); // Calculate total days on mount
this.loadMenu();
},
methods: {
loadMenu() {
const dateParam = this.getQueryParam('date') || new Date().toISOString().split('T')[0];
// Load the daily menu
axios.get(`output/menu_${dateParam}.json`)
.then(response => {
this.menu = response.data;
// Load the meal and component counts
return axios.get('output/meal_component_counts.json');
})
.then(response => {
this.mealCount = response.data.meal_counts || {};
this.componentCount = response.data.component_counts || {};
})
.catch(error => {
console.error('Error fetching menu or counts:', error);
});
},
getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
},
changeDate(offset) {
const currentDate = new Date(this.getQueryParam('date') || new Date());
currentDate.setDate(currentDate.getDate() + offset);
// Check if the new date falls on a weekend
while (currentDate.getDay() === 0 || currentDate.getDay() === 6) { // 0 = Sunday, 6 = Saturday
currentDate.setDate(currentDate.getDate() + (offset > 0 ? 1 : -1)); // Move to next weekday
}
const newDate = currentDate.toISOString().split('T')[0];
window.location.search = `?date=${newDate}`;
},
showStatistics() {
this.showingStatistics = true; // Show the statistics section
},
calculateTotalDays() {
const startDate = new Date("2024-09-25"); // Starting date
const today = new Date();
let totalDays = 0;
// Loop through each day from startDate to today
for (let d = new Date(startDate); d <= today; d.setDate(d.getDate() + 1)) {
// Check if the day is a weekday (Monday to Friday)
if (d.getDay() !== 0 && d.getDay() !== 6) { // 0 = Sunday, 6 = Saturday
totalDays++;
}
}
this.totalDays = totalDays;
}
}
});
</script>
</body>
</html>