@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.
Files changed (71) hide show
  1. package/.claude/settings.local.json +16 -0
  2. package/.github/workflows/ci-cd.yml +80 -80
  3. package/BRANCH_PROTECTION_SETUP.md +167 -167
  4. package/CHANGELOG.md +8 -8
  5. package/README.md +144 -144
  6. package/RESERVERINGEN_GIDS.md +986 -986
  7. package/__tests__/crossMidnight.test.js +63 -0
  8. package/__tests__/crossMidnightTimeblocks.test.js +312 -0
  9. package/__tests__/edgeCases.test.js +271 -0
  10. package/__tests__/filters.test.js +276 -276
  11. package/__tests__/isDateAvailable.test.js +179 -175
  12. package/__tests__/isTimeAvailable.test.js +174 -168
  13. package/__tests__/restaurantData.test.js +422 -422
  14. package/__tests__/tableHelpers.test.js +247 -247
  15. package/assignTables.js +506 -444
  16. package/changes/2025/December/PR2___change.md +14 -14
  17. package/changes/2025/December/PR3_add__change.md +20 -20
  18. package/changes/2025/December/PR4___.md +15 -15
  19. package/changes/2025/December/PR5___.md +15 -15
  20. package/changes/2025/December/PR6__del_.md +17 -17
  21. package/changes/2025/December/PR7_add__change.md +21 -21
  22. package/changes/2026/February/PR15_add__change.md +21 -21
  23. package/changes/2026/February/PR16_add__.md +20 -0
  24. package/changes/2026/February/PR16_add_getDateClosingReasons.md +31 -31
  25. package/changes/2026/January/PR10_add__change.md +21 -21
  26. package/changes/2026/January/PR11_add__change.md +19 -19
  27. package/changes/2026/January/PR12_add__.md +21 -21
  28. package/changes/2026/January/PR13_add__change.md +20 -20
  29. package/changes/2026/January/PR14_add__change.md +19 -19
  30. package/changes/2026/January/PR8_add__change.md +38 -38
  31. package/changes/2026/January/PR9_add__change.md +19 -19
  32. package/dateHelpers.js +31 -0
  33. package/filters/maxArrivalsFilter.js +114 -114
  34. package/filters/maxGroupsFilter.js +221 -221
  35. package/filters/timeFilter.js +89 -89
  36. package/getAvailableTimeblocks.js +158 -158
  37. package/getDateClosingReasons.js +193 -193
  38. package/grouping.js +162 -162
  39. package/index.js +48 -43
  40. package/isDateAvailable.js +80 -80
  41. package/isDateAvailableWithTableCheck.js +172 -172
  42. package/isTimeAvailable.js +26 -26
  43. package/jest.config.js +23 -23
  44. package/package.json +27 -27
  45. package/processing/dailyGuestCounts.js +73 -73
  46. package/processing/mealTypeCount.js +133 -133
  47. package/processing/timeblocksAvailable.js +344 -182
  48. package/reservation_data/counter.js +82 -75
  49. package/restaurant_data/exceptions.js +150 -150
  50. package/restaurant_data/openinghours.js +142 -142
  51. package/simulateTableAssignment.js +833 -726
  52. package/tableHelpers.js +209 -209
  53. package/tables/time/parseTime.js +19 -19
  54. package/tables/time/shifts.js +7 -7
  55. package/tables/utils/calculateDistance.js +13 -13
  56. package/tables/utils/isTableFreeForAllSlots.js +14 -14
  57. package/tables/utils/isTemporaryTableValid.js +39 -39
  58. package/test/test_counter.js +194 -194
  59. package/test/test_dailyCount.js +81 -81
  60. package/test/test_datesAvailable.js +106 -106
  61. package/test/test_exceptions.js +172 -172
  62. package/test/test_isDateAvailable.js +330 -330
  63. package/test/test_mealTypeCount.js +54 -54
  64. package/test/test_timesAvailable.js +88 -88
  65. package/test-detailed-filter.js +100 -100
  66. package/test-lunch-debug.js +110 -110
  67. package/test-max-arrivals-filter.js +79 -79
  68. package/test-meal-stop-fix.js +147 -147
  69. package/test-meal-stop-simple.js +93 -93
  70. package/test-timezone-debug.js +47 -47
  71. package/test.js +336 -336
@@ -1,110 +1,110 @@
1
- // Test script to debug why Monday lunch isn't showing
2
- const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
3
- const { timeblocksAvailable } = require('./processing/timeblocksAvailable');
4
- const { getDailyGuestCounts } = require('./processing/dailyGuestCounts');
5
-
6
- // Your restaurant data
7
- const restaurantData = {
8
- "_id": "demo",
9
- "openinghours-lunch": {
10
- "schemeSettings": {
11
- "Monday": {
12
- "enabled": true,
13
- "startTime": "14:15",
14
- "endTime": "15:00",
15
- "maxCapacityEnabled": true,
16
- "maxCapacity": "10",
17
- "shiftsEnabled": false,
18
- "shifts": [],
19
- "giftcardsEnabled": false,
20
- "giftcards": [],
21
- "giftcardTakeawayEnabled": false,
22
- "giftcardTakeawayStart": "",
23
- "giftcardTakeawayEnd": ""
24
- },
25
- "Wednesday": {
26
- "enabled": true,
27
- "startTime": "13:45",
28
- "endTime": "14:45",
29
- "maxCapacityEnabled": false,
30
- "maxCapacity": "",
31
- "shiftsEnabled": false,
32
- "shifts": [],
33
- "giftcardsEnabled": false,
34
- "giftcards": [],
35
- "giftcardTakeawayEnabled": true,
36
- "giftcardTakeawayStart": "11:00",
37
- "giftcardTakeawayEnd": "16:00"
38
- }
39
- }
40
- },
41
- "general-settings": {
42
- "zitplaatsen": 13,
43
- "uurOpVoorhand": 0,
44
- "dagenInToekomst": 365,
45
- "minGasten": 1,
46
- "maxGasten": 10,
47
- "intervalReservatie": 30,
48
- "duurReservatie": 60,
49
- "ontbijtStop": "",
50
- "lunchStop": "",
51
- "dinerStop": ""
52
- },
53
- "max-arrivals-lunch": {
54
- "12:00": 6,
55
- "12:15": 1,
56
- "12:30": 6,
57
- "12:45": 4,
58
- "13:00": 10,
59
- "14:15": 10,
60
- "14:30": 10,
61
- "14:45": 10,
62
- "storedNumber": 30
63
- },
64
- "exceptions": [],
65
- "blocked-slots": []
66
- };
67
-
68
- // Test for Monday December 8, 2025
69
- const testDate = "2025-12-08"; // Monday
70
- const guests = 2;
71
- const reservations = [];
72
-
73
- console.log('=== LUNCH AVAILABILITY DEBUG ===\n');
74
- console.log('Date:', testDate, '(Monday)');
75
- console.log('Guests:', guests);
76
- console.log('Current time:', new Date().toISOString());
77
- console.log('\n--- Restaurant Settings ---');
78
- console.log('Lunch Opening Hours (Monday):', restaurantData['openinghours-lunch'].schemeSettings.Monday);
79
- console.log('General Settings:', restaurantData['general-settings']);
80
- console.log('Max Arrivals Lunch:', restaurantData['max-arrivals-lunch']);
81
-
82
- console.log('\n--- Step 1: getDailyGuestCounts ---');
83
- const { guestCounts, shiftsInfo } = getDailyGuestCounts(restaurantData, testDate, reservations);
84
- console.log('Guest Counts:', guestCounts);
85
- console.log('Shifts Info:', shiftsInfo);
86
-
87
- console.log('\n--- Step 2: timeblocksAvailable ---');
88
- const timeblocks = timeblocksAvailable(restaurantData, testDate, reservations, guests, [], null, false);
89
- console.log('Available Timeblocks:', timeblocks);
90
-
91
- console.log('\n--- Step 3: getAvailableTimeblocks (with filters) ---');
92
- const finalTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, false);
93
- console.log('Final Available Timeblocks:', finalTimeblocks);
94
-
95
- console.log('\n--- Step 4: Test with Admin Flag ---');
96
- const adminTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
97
- console.log('Admin Timeblocks (no time restrictions):', adminTimeblocks);
98
-
99
- // Check if lunch times exist
100
- const lunchTimes = ['14:15', '14:30', '14:45'];
101
- console.log('\n--- Lunch Time Analysis ---');
102
- lunchTimes.forEach(time => {
103
- console.log(`${time}:`);
104
- console.log(` - In guestCounts: ${guestCounts.hasOwnProperty(time) ? 'YES (capacity: ' + guestCounts[time] + ')' : 'NO'}`);
105
- console.log(` - In timeblocks: ${timeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
106
- console.log(` - In final: ${finalTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
107
- console.log(` - In admin: ${adminTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
108
- });
109
-
110
- console.log('\n=== END DEBUG ===');
1
+ // Test script to debug why Monday lunch isn't showing
2
+ const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
3
+ const { timeblocksAvailable } = require('./processing/timeblocksAvailable');
4
+ const { getDailyGuestCounts } = require('./processing/dailyGuestCounts');
5
+
6
+ // Your restaurant data
7
+ const restaurantData = {
8
+ "_id": "demo",
9
+ "openinghours-lunch": {
10
+ "schemeSettings": {
11
+ "Monday": {
12
+ "enabled": true,
13
+ "startTime": "14:15",
14
+ "endTime": "15:00",
15
+ "maxCapacityEnabled": true,
16
+ "maxCapacity": "10",
17
+ "shiftsEnabled": false,
18
+ "shifts": [],
19
+ "giftcardsEnabled": false,
20
+ "giftcards": [],
21
+ "giftcardTakeawayEnabled": false,
22
+ "giftcardTakeawayStart": "",
23
+ "giftcardTakeawayEnd": ""
24
+ },
25
+ "Wednesday": {
26
+ "enabled": true,
27
+ "startTime": "13:45",
28
+ "endTime": "14:45",
29
+ "maxCapacityEnabled": false,
30
+ "maxCapacity": "",
31
+ "shiftsEnabled": false,
32
+ "shifts": [],
33
+ "giftcardsEnabled": false,
34
+ "giftcards": [],
35
+ "giftcardTakeawayEnabled": true,
36
+ "giftcardTakeawayStart": "11:00",
37
+ "giftcardTakeawayEnd": "16:00"
38
+ }
39
+ }
40
+ },
41
+ "general-settings": {
42
+ "zitplaatsen": 13,
43
+ "uurOpVoorhand": 0,
44
+ "dagenInToekomst": 365,
45
+ "minGasten": 1,
46
+ "maxGasten": 10,
47
+ "intervalReservatie": 30,
48
+ "duurReservatie": 60,
49
+ "ontbijtStop": "",
50
+ "lunchStop": "",
51
+ "dinerStop": ""
52
+ },
53
+ "max-arrivals-lunch": {
54
+ "12:00": 6,
55
+ "12:15": 1,
56
+ "12:30": 6,
57
+ "12:45": 4,
58
+ "13:00": 10,
59
+ "14:15": 10,
60
+ "14:30": 10,
61
+ "14:45": 10,
62
+ "storedNumber": 30
63
+ },
64
+ "exceptions": [],
65
+ "blocked-slots": []
66
+ };
67
+
68
+ // Test for Monday December 8, 2025
69
+ const testDate = "2025-12-08"; // Monday
70
+ const guests = 2;
71
+ const reservations = [];
72
+
73
+ console.log('=== LUNCH AVAILABILITY DEBUG ===\n');
74
+ console.log('Date:', testDate, '(Monday)');
75
+ console.log('Guests:', guests);
76
+ console.log('Current time:', new Date().toISOString());
77
+ console.log('\n--- Restaurant Settings ---');
78
+ console.log('Lunch Opening Hours (Monday):', restaurantData['openinghours-lunch'].schemeSettings.Monday);
79
+ console.log('General Settings:', restaurantData['general-settings']);
80
+ console.log('Max Arrivals Lunch:', restaurantData['max-arrivals-lunch']);
81
+
82
+ console.log('\n--- Step 1: getDailyGuestCounts ---');
83
+ const { guestCounts, shiftsInfo } = getDailyGuestCounts(restaurantData, testDate, reservations);
84
+ console.log('Guest Counts:', guestCounts);
85
+ console.log('Shifts Info:', shiftsInfo);
86
+
87
+ console.log('\n--- Step 2: timeblocksAvailable ---');
88
+ const timeblocks = timeblocksAvailable(restaurantData, testDate, reservations, guests, [], null, false);
89
+ console.log('Available Timeblocks:', timeblocks);
90
+
91
+ console.log('\n--- Step 3: getAvailableTimeblocks (with filters) ---');
92
+ const finalTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, false);
93
+ console.log('Final Available Timeblocks:', finalTimeblocks);
94
+
95
+ console.log('\n--- Step 4: Test with Admin Flag ---');
96
+ const adminTimeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
97
+ console.log('Admin Timeblocks (no time restrictions):', adminTimeblocks);
98
+
99
+ // Check if lunch times exist
100
+ const lunchTimes = ['14:15', '14:30', '14:45'];
101
+ console.log('\n--- Lunch Time Analysis ---');
102
+ lunchTimes.forEach(time => {
103
+ console.log(`${time}:`);
104
+ console.log(` - In guestCounts: ${guestCounts.hasOwnProperty(time) ? 'YES (capacity: ' + guestCounts[time] + ')' : 'NO'}`);
105
+ console.log(` - In timeblocks: ${timeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
106
+ console.log(` - In final: ${finalTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
107
+ console.log(` - In admin: ${adminTimeblocks.hasOwnProperty(time) ? 'YES' : 'NO'}`);
108
+ });
109
+
110
+ console.log('\n=== END DEBUG ===');
@@ -1,79 +1,79 @@
1
- // Test the max arrivals filter specifically
2
- const { filterTimeblocksByMaxArrivals } = require('./filters/maxArrivalsFilter');
3
- const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
4
-
5
- const restaurantData = {
6
- "_id": "demo",
7
- "openinghours-lunch": {
8
- "schemeSettings": {
9
- "Monday": {
10
- "enabled": true,
11
- "startTime": "14:15",
12
- "endTime": "15:00",
13
- "maxCapacityEnabled": true,
14
- "maxCapacity": "10"
15
- }
16
- }
17
- },
18
- "general-settings": {
19
- "zitplaatsen": 13,
20
- "uurOpVoorhand": 0,
21
- "dagenInToekomst": 365,
22
- "intervalReservatie": 30,
23
- "duurReservatie": 60,
24
- "ontbijtStop": "",
25
- "lunchStop": "",
26
- "dinerStop": ""
27
- },
28
- "max-arrivals-lunch": {
29
- "12:00": 6,
30
- "12:15": 1,
31
- "12:30": 6,
32
- "12:45": 4,
33
- "13:00": 10,
34
- "14:15": 10,
35
- "14:30": 10,
36
- "14:45": 10,
37
- "storedNumber": 30
38
- }
39
- };
40
-
41
- const testDate = "2025-12-08";
42
- const guests = 2;
43
- const reservations = [];
44
-
45
- console.log('=== MAX ARRIVALS FILTER TEST ===\n');
46
-
47
- // Get initial timeblocks from algorithm
48
- const timeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
49
- console.log('Timeblocks from algorithm (admin mode):', Object.keys(timeblocks));
50
-
51
- // Apply max arrivals filter
52
- const filtered = filterTimeblocksByMaxArrivals(restaurantData, testDate, timeblocks, reservations, guests);
53
- console.log('\nAfter max arrivals filter:', Object.keys(filtered));
54
-
55
- // Debug each time slot
56
- console.log('\n--- Detailed Analysis ---');
57
- for (const time of Object.keys(timeblocks)) {
58
- const maxArrivalsConfig = restaurantData['max-arrivals-lunch'];
59
- const maxArrivals = maxArrivalsConfig ? maxArrivalsConfig[time] : null;
60
-
61
- const currentArrivals = reservations
62
- .filter(r => r.date === testDate && r.time === time)
63
- .reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
64
-
65
- const isInFiltered = filtered.hasOwnProperty(time);
66
-
67
- console.log(`\n${time}:`);
68
- console.log(` Max arrivals setting: ${maxArrivals || 'NOT SET'}`);
69
- console.log(` Current arrivals: ${currentArrivals}`);
70
- console.log(` New reservation: ${guests} guests`);
71
- console.log(` Total after adding: ${currentArrivals + guests}`);
72
- console.log(` Passes filter: ${isInFiltered ? 'YES' : 'NO'}`);
73
-
74
- if (maxArrivals !== null && maxArrivals !== undefined) {
75
- console.log(` Logic: ${currentArrivals} + ${guests} = ${currentArrivals + guests} ${currentArrivals + guests <= maxArrivals ? '<=' : '>'} ${maxArrivals}`);
76
- }
77
- }
78
-
79
- console.log('\n=== END TEST ===');
1
+ // Test the max arrivals filter specifically
2
+ const { filterTimeblocksByMaxArrivals } = require('./filters/maxArrivalsFilter');
3
+ const { getAvailableTimeblocks } = require('./getAvailableTimeblocks');
4
+
5
+ const restaurantData = {
6
+ "_id": "demo",
7
+ "openinghours-lunch": {
8
+ "schemeSettings": {
9
+ "Monday": {
10
+ "enabled": true,
11
+ "startTime": "14:15",
12
+ "endTime": "15:00",
13
+ "maxCapacityEnabled": true,
14
+ "maxCapacity": "10"
15
+ }
16
+ }
17
+ },
18
+ "general-settings": {
19
+ "zitplaatsen": 13,
20
+ "uurOpVoorhand": 0,
21
+ "dagenInToekomst": 365,
22
+ "intervalReservatie": 30,
23
+ "duurReservatie": 60,
24
+ "ontbijtStop": "",
25
+ "lunchStop": "",
26
+ "dinerStop": ""
27
+ },
28
+ "max-arrivals-lunch": {
29
+ "12:00": 6,
30
+ "12:15": 1,
31
+ "12:30": 6,
32
+ "12:45": 4,
33
+ "13:00": 10,
34
+ "14:15": 10,
35
+ "14:30": 10,
36
+ "14:45": 10,
37
+ "storedNumber": 30
38
+ }
39
+ };
40
+
41
+ const testDate = "2025-12-08";
42
+ const guests = 2;
43
+ const reservations = [];
44
+
45
+ console.log('=== MAX ARRIVALS FILTER TEST ===\n');
46
+
47
+ // Get initial timeblocks from algorithm
48
+ const timeblocks = getAvailableTimeblocks(restaurantData, testDate, reservations, guests, [], null, true);
49
+ console.log('Timeblocks from algorithm (admin mode):', Object.keys(timeblocks));
50
+
51
+ // Apply max arrivals filter
52
+ const filtered = filterTimeblocksByMaxArrivals(restaurantData, testDate, timeblocks, reservations, guests);
53
+ console.log('\nAfter max arrivals filter:', Object.keys(filtered));
54
+
55
+ // Debug each time slot
56
+ console.log('\n--- Detailed Analysis ---');
57
+ for (const time of Object.keys(timeblocks)) {
58
+ const maxArrivalsConfig = restaurantData['max-arrivals-lunch'];
59
+ const maxArrivals = maxArrivalsConfig ? maxArrivalsConfig[time] : null;
60
+
61
+ const currentArrivals = reservations
62
+ .filter(r => r.date === testDate && r.time === time)
63
+ .reduce((sum, r) => sum + (parseInt(r.guests, 10) || 0), 0);
64
+
65
+ const isInFiltered = filtered.hasOwnProperty(time);
66
+
67
+ console.log(`\n${time}:`);
68
+ console.log(` Max arrivals setting: ${maxArrivals || 'NOT SET'}`);
69
+ console.log(` Current arrivals: ${currentArrivals}`);
70
+ console.log(` New reservation: ${guests} guests`);
71
+ console.log(` Total after adding: ${currentArrivals + guests}`);
72
+ console.log(` Passes filter: ${isInFiltered ? 'YES' : 'NO'}`);
73
+
74
+ if (maxArrivals !== null && maxArrivals !== undefined) {
75
+ console.log(` Logic: ${currentArrivals} + ${guests} = ${currentArrivals + guests} ${currentArrivals + guests <= maxArrivals ? '<=' : '>'} ${maxArrivals}`);
76
+ }
77
+ }
78
+
79
+ console.log('\n=== END TEST ===');