@happychef/algorithm 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +16 -0
- package/.github/workflows/ci-cd.yml +80 -80
- package/BRANCH_PROTECTION_SETUP.md +167 -167
- package/CHANGELOG.md +8 -8
- package/README.md +144 -144
- package/RESERVERINGEN_GIDS.md +986 -986
- package/__tests__/crossMidnight.test.js +63 -0
- package/__tests__/crossMidnightTimeblocks.test.js +312 -0
- package/__tests__/edgeCases.test.js +271 -0
- package/__tests__/filters.test.js +276 -276
- package/__tests__/isDateAvailable.test.js +179 -175
- package/__tests__/isTimeAvailable.test.js +174 -168
- package/__tests__/restaurantData.test.js +422 -422
- package/__tests__/tableHelpers.test.js +247 -247
- package/assignTables.js +506 -444
- package/changes/2025/December/PR2___change.md +14 -14
- package/changes/2025/December/PR3_add__change.md +20 -20
- package/changes/2025/December/PR4___.md +15 -15
- package/changes/2025/December/PR5___.md +15 -15
- package/changes/2025/December/PR6__del_.md +17 -17
- package/changes/2025/December/PR7_add__change.md +21 -21
- package/changes/2026/February/PR15_add__change.md +21 -21
- package/changes/2026/February/PR16_add__.md +20 -0
- package/changes/2026/February/PR16_add_getDateClosingReasons.md +31 -31
- package/changes/2026/January/PR10_add__change.md +21 -21
- package/changes/2026/January/PR11_add__change.md +19 -19
- package/changes/2026/January/PR12_add__.md +21 -21
- package/changes/2026/January/PR13_add__change.md +20 -20
- package/changes/2026/January/PR14_add__change.md +19 -19
- package/changes/2026/January/PR8_add__change.md +38 -38
- package/changes/2026/January/PR9_add__change.md +19 -19
- package/dateHelpers.js +31 -0
- package/filters/maxArrivalsFilter.js +114 -114
- package/filters/maxGroupsFilter.js +221 -221
- package/filters/timeFilter.js +89 -89
- package/getAvailableTimeblocks.js +158 -158
- package/getDateClosingReasons.js +193 -193
- package/grouping.js +162 -162
- package/index.js +48 -43
- package/isDateAvailable.js +80 -80
- package/isDateAvailableWithTableCheck.js +172 -172
- package/isTimeAvailable.js +26 -26
- package/jest.config.js +23 -23
- package/package.json +27 -27
- package/processing/dailyGuestCounts.js +73 -73
- package/processing/mealTypeCount.js +133 -133
- package/processing/timeblocksAvailable.js +344 -182
- package/reservation_data/counter.js +82 -75
- package/restaurant_data/exceptions.js +150 -150
- package/restaurant_data/openinghours.js +142 -142
- package/simulateTableAssignment.js +833 -726
- package/tableHelpers.js +209 -209
- package/tables/time/parseTime.js +19 -19
- package/tables/time/shifts.js +7 -7
- package/tables/utils/calculateDistance.js +13 -13
- package/tables/utils/isTableFreeForAllSlots.js +14 -14
- package/tables/utils/isTemporaryTableValid.js +39 -39
- package/test/test_counter.js +194 -194
- package/test/test_dailyCount.js +81 -81
- package/test/test_datesAvailable.js +106 -106
- package/test/test_exceptions.js +172 -172
- package/test/test_isDateAvailable.js +330 -330
- package/test/test_mealTypeCount.js +54 -54
- package/test/test_timesAvailable.js +88 -88
- package/test-detailed-filter.js +100 -100
- package/test-lunch-debug.js +110 -110
- package/test-max-arrivals-filter.js +79 -79
- package/test-meal-stop-fix.js +147 -147
- package/test-meal-stop-simple.js +93 -93
- package/test-timezone-debug.js +47 -47
- package/test.js +336 -336
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
// mealTypeCount.js
|
|
2
|
-
|
|
3
|
-
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
-
const { parseTime } = require('../restaurant_data/openinghours');
|
|
5
|
-
const { getGuestCountAtHour } = require('../reservation_data/counter');
|
|
6
|
-
|
|
7
|
-
function getInterval(data) {
|
|
8
|
-
let intervalReservatie = 15;
|
|
9
|
-
if (
|
|
10
|
-
data['general-settings'] &&
|
|
11
|
-
data['general-settings'].intervalReservatie &&
|
|
12
|
-
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
13
|
-
) {
|
|
14
|
-
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
15
|
-
}
|
|
16
|
-
return intervalReservatie;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves meal types with shifts enabled and at least one shift defined for the specified date.
|
|
21
|
-
* @param {Object} data - The main data object.
|
|
22
|
-
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
23
|
-
* @returns {Array} - An array of meal types with shifts.
|
|
24
|
-
*/
|
|
25
|
-
function getMealTypesWithShifts(data, dateStr) {
|
|
26
|
-
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
27
|
-
const mealTypesWithShifts = [];
|
|
28
|
-
|
|
29
|
-
for (const mealType of mealTypes) {
|
|
30
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
31
|
-
if (
|
|
32
|
-
mealData &&
|
|
33
|
-
mealData.shiftsEnabled &&
|
|
34
|
-
Array.isArray(mealData.shifts) &&
|
|
35
|
-
mealData.shifts.length > 0
|
|
36
|
-
) {
|
|
37
|
-
mealTypesWithShifts.push(mealType);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return mealTypesWithShifts;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function shouldIncludeEndTime(mealType, endTime) {
|
|
45
|
-
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
46
|
-
(mealType === 'lunch' && endTime === '16:00')) {
|
|
47
|
-
return false; // Do not include endTime for breakfast at 11:00 and lunch at 16:00
|
|
48
|
-
}
|
|
49
|
-
return true; // Include endTime for all other cases
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Calculates guest counts for each interval during a meal period or at shift times.
|
|
54
|
-
* @param {Object} data - The main data object.
|
|
55
|
-
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
56
|
-
* @param {string} mealType - The meal type ("breakfast", "lunch", "dinner").
|
|
57
|
-
* @param {Array} reservations - An array of reservation objects.
|
|
58
|
-
* @returns {Object|null} An object mapping times to guest counts, or null if meal is not available.
|
|
59
|
-
*/
|
|
60
|
-
function getGuestCountsForMeal(data, dateStr, mealType, reservations) {
|
|
61
|
-
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
62
|
-
if (!mealData) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const guestCounts = {};
|
|
67
|
-
const shiftsInfo = [];
|
|
68
|
-
|
|
69
|
-
// Get 'intervalReservatie' from general settings, default to 15 if not set or zero
|
|
70
|
-
let intervalReservatie = getInterval(data);
|
|
71
|
-
|
|
72
|
-
// Check if shifts are enabled and shifts array has valid content
|
|
73
|
-
if (
|
|
74
|
-
mealData.shiftsEnabled &&
|
|
75
|
-
Array.isArray(mealData.shifts) &&
|
|
76
|
-
mealData.shifts.length > 0
|
|
77
|
-
) {
|
|
78
|
-
// If shifts are enabled and valid, calculate guest counts at shift times
|
|
79
|
-
const shifts = mealData.shifts; // Array of shifts
|
|
80
|
-
|
|
81
|
-
for (const shift of shifts) {
|
|
82
|
-
const timeStr = shift.time; // Time of the shift in "HH:MM" format
|
|
83
|
-
|
|
84
|
-
// Get guest count at this time
|
|
85
|
-
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
86
|
-
|
|
87
|
-
// Store in guestCounts
|
|
88
|
-
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
89
|
-
|
|
90
|
-
// Store shift information
|
|
91
|
-
shiftsInfo.push({
|
|
92
|
-
mealType,
|
|
93
|
-
shiftName: shift.name,
|
|
94
|
-
time: timeStr,
|
|
95
|
-
availableSeats: mealData.maxCapacity - guestCount,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// If shifts are not enabled or shifts array is empty/invalid, calculate guest counts at intervals
|
|
100
|
-
const startTime = mealData.startTime;
|
|
101
|
-
const endTime = mealData.endTime;
|
|
102
|
-
|
|
103
|
-
// Determine if endTime should be included
|
|
104
|
-
const includeEndTime = shouldIncludeEndTime(mealType, endTime);
|
|
105
|
-
|
|
106
|
-
// Convert startTime and endTime to minutes since midnight
|
|
107
|
-
let currentTime = parseTime(startTime);
|
|
108
|
-
const endTimeMinutes = parseTime(endTime);
|
|
109
|
-
|
|
110
|
-
while (includeEndTime ? currentTime <= endTimeMinutes : currentTime < endTimeMinutes) {
|
|
111
|
-
// Convert currentTime back to "HH:MM" format
|
|
112
|
-
const hours = Math.floor(currentTime / 60).toString().padStart(2, '0');
|
|
113
|
-
const minutes = (currentTime % 60).toString().padStart(2, '0');
|
|
114
|
-
const timeStr = `${hours}:${minutes}`;
|
|
115
|
-
|
|
116
|
-
// Get guest count at this time
|
|
117
|
-
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
118
|
-
|
|
119
|
-
// Store in guestCounts
|
|
120
|
-
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
121
|
-
|
|
122
|
-
// Increment currentTime by 'intervalReservatie' minutes
|
|
123
|
-
currentTime += intervalReservatie;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { guestCounts, shiftsInfo };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = {
|
|
131
|
-
getGuestCountsForMeal,
|
|
132
|
-
getMealTypesWithShifts, // Exported
|
|
133
|
-
};
|
|
1
|
+
// mealTypeCount.js
|
|
2
|
+
|
|
3
|
+
const { getDataByDateAndMealWithExceptions } = require('../restaurant_data/exceptions');
|
|
4
|
+
const { parseTime } = require('../restaurant_data/openinghours');
|
|
5
|
+
const { getGuestCountAtHour } = require('../reservation_data/counter');
|
|
6
|
+
|
|
7
|
+
function getInterval(data) {
|
|
8
|
+
let intervalReservatie = 15;
|
|
9
|
+
if (
|
|
10
|
+
data['general-settings'] &&
|
|
11
|
+
data['general-settings'].intervalReservatie &&
|
|
12
|
+
parseInt(data['general-settings'].intervalReservatie, 10) > 0
|
|
13
|
+
) {
|
|
14
|
+
intervalReservatie = parseInt(data['general-settings'].intervalReservatie, 10);
|
|
15
|
+
}
|
|
16
|
+
return intervalReservatie;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves meal types with shifts enabled and at least one shift defined for the specified date.
|
|
21
|
+
* @param {Object} data - The main data object.
|
|
22
|
+
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
23
|
+
* @returns {Array} - An array of meal types with shifts.
|
|
24
|
+
*/
|
|
25
|
+
function getMealTypesWithShifts(data, dateStr) {
|
|
26
|
+
const mealTypes = ['breakfast', 'lunch', 'dinner'];
|
|
27
|
+
const mealTypesWithShifts = [];
|
|
28
|
+
|
|
29
|
+
for (const mealType of mealTypes) {
|
|
30
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
31
|
+
if (
|
|
32
|
+
mealData &&
|
|
33
|
+
mealData.shiftsEnabled &&
|
|
34
|
+
Array.isArray(mealData.shifts) &&
|
|
35
|
+
mealData.shifts.length > 0
|
|
36
|
+
) {
|
|
37
|
+
mealTypesWithShifts.push(mealType);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return mealTypesWithShifts;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function shouldIncludeEndTime(mealType, endTime) {
|
|
45
|
+
if ((mealType === 'breakfast' && endTime === '11:00') ||
|
|
46
|
+
(mealType === 'lunch' && endTime === '16:00')) {
|
|
47
|
+
return false; // Do not include endTime for breakfast at 11:00 and lunch at 16:00
|
|
48
|
+
}
|
|
49
|
+
return true; // Include endTime for all other cases
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Calculates guest counts for each interval during a meal period or at shift times.
|
|
54
|
+
* @param {Object} data - The main data object.
|
|
55
|
+
* @param {string} dateStr - The date string (YYYY-MM-DD).
|
|
56
|
+
* @param {string} mealType - The meal type ("breakfast", "lunch", "dinner").
|
|
57
|
+
* @param {Array} reservations - An array of reservation objects.
|
|
58
|
+
* @returns {Object|null} An object mapping times to guest counts, or null if meal is not available.
|
|
59
|
+
*/
|
|
60
|
+
function getGuestCountsForMeal(data, dateStr, mealType, reservations) {
|
|
61
|
+
const mealData = getDataByDateAndMealWithExceptions(data, dateStr, mealType);
|
|
62
|
+
if (!mealData) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const guestCounts = {};
|
|
67
|
+
const shiftsInfo = [];
|
|
68
|
+
|
|
69
|
+
// Get 'intervalReservatie' from general settings, default to 15 if not set or zero
|
|
70
|
+
let intervalReservatie = getInterval(data);
|
|
71
|
+
|
|
72
|
+
// Check if shifts are enabled and shifts array has valid content
|
|
73
|
+
if (
|
|
74
|
+
mealData.shiftsEnabled &&
|
|
75
|
+
Array.isArray(mealData.shifts) &&
|
|
76
|
+
mealData.shifts.length > 0
|
|
77
|
+
) {
|
|
78
|
+
// If shifts are enabled and valid, calculate guest counts at shift times
|
|
79
|
+
const shifts = mealData.shifts; // Array of shifts
|
|
80
|
+
|
|
81
|
+
for (const shift of shifts) {
|
|
82
|
+
const timeStr = shift.time; // Time of the shift in "HH:MM" format
|
|
83
|
+
|
|
84
|
+
// Get guest count at this time
|
|
85
|
+
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
86
|
+
|
|
87
|
+
// Store in guestCounts
|
|
88
|
+
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
89
|
+
|
|
90
|
+
// Store shift information
|
|
91
|
+
shiftsInfo.push({
|
|
92
|
+
mealType,
|
|
93
|
+
shiftName: shift.name,
|
|
94
|
+
time: timeStr,
|
|
95
|
+
availableSeats: mealData.maxCapacity - guestCount,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
// If shifts are not enabled or shifts array is empty/invalid, calculate guest counts at intervals
|
|
100
|
+
const startTime = mealData.startTime;
|
|
101
|
+
const endTime = mealData.endTime;
|
|
102
|
+
|
|
103
|
+
// Determine if endTime should be included
|
|
104
|
+
const includeEndTime = shouldIncludeEndTime(mealType, endTime);
|
|
105
|
+
|
|
106
|
+
// Convert startTime and endTime to minutes since midnight
|
|
107
|
+
let currentTime = parseTime(startTime);
|
|
108
|
+
const endTimeMinutes = parseTime(endTime);
|
|
109
|
+
|
|
110
|
+
while (includeEndTime ? currentTime <= endTimeMinutes : currentTime < endTimeMinutes) {
|
|
111
|
+
// Convert currentTime back to "HH:MM" format
|
|
112
|
+
const hours = Math.floor(currentTime / 60).toString().padStart(2, '0');
|
|
113
|
+
const minutes = (currentTime % 60).toString().padStart(2, '0');
|
|
114
|
+
const timeStr = `${hours}:${minutes}`;
|
|
115
|
+
|
|
116
|
+
// Get guest count at this time
|
|
117
|
+
const guestCount = getGuestCountAtHour(data, reservations, timeStr, dateStr);
|
|
118
|
+
|
|
119
|
+
// Store in guestCounts
|
|
120
|
+
guestCounts[timeStr] = mealData.maxCapacity - guestCount;
|
|
121
|
+
|
|
122
|
+
// Increment currentTime by 'intervalReservatie' minutes
|
|
123
|
+
currentTime += intervalReservatie;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { guestCounts, shiftsInfo };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
getGuestCountsForMeal,
|
|
132
|
+
getMealTypesWithShifts, // Exported
|
|
133
|
+
};
|