assignment-user-matcher 1.16.0 → 1.16.1
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/README.md +22 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.d.ts +10 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.js +64 -1
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +12 -3
- package/dist/scheduling/constraints/group-composition.js +2 -2
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-staffing.js +51 -8
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +23 -3
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +20 -3
- package/dist/scheduling/engine/timeline.d.ts +14 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +33 -0
- package/dist/scheduling/index.d.ts +1 -1
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/model.d.ts +6 -1
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +209 -11
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +45 -6
- package/dist/scheduling/sites.d.ts +1 -1
- package/dist/scheduling/sites.d.ts.map +1 -1
- package/dist/scheduling/sites.js +34 -1
- package/dist/scheduling/types.d.ts +140 -6
- package/dist/scheduling/types.d.ts.map +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -1072,7 +1072,7 @@ correctness rests on:
|
|
|
1072
1072
|
- **One decision per committed attempt.** A candidate that was scored but lost
|
|
1073
1073
|
the assignment — to another worker under fair arbitration, or to another
|
|
1074
1074
|
process at the claim gate — leaves no decision behind. An assignment that is
|
|
1075
|
-
rejected and rematched opens a
|
|
1075
|
+
rejected and rematched opens a _second, independent_ attempt with its own id;
|
|
1076
1076
|
feedback for the first can never reach the second.
|
|
1077
1077
|
- **Ingestion is idempotent.** Every outcome and every feedback call is gated
|
|
1078
1078
|
on the attempt's applied-event set, so a redelivered message applies once and
|
|
@@ -1225,15 +1225,15 @@ const matcher = new AssignmentMatcher(redisClient, {
|
|
|
1225
1225
|
|
|
1226
1226
|
Each target gets its own model hash and its own label timing:
|
|
1227
1227
|
|
|
1228
|
-
| Target
|
|
1229
|
-
|
|
|
1230
|
-
| `acceptance`
|
|
1231
|
-
| `successGivenAcceptance` | one per
|
|
1232
|
-
| `quality`
|
|
1228
|
+
| Target | Denominator | Label | Missing data |
|
|
1229
|
+
| ------------------------ | --------------------------- | -------------------------------------------------------------- | ------------------------------------ |
|
|
1230
|
+
| `acceptance` | one per committed attempt | 1 on accept; 0 on reject or **pre-acceptance** response expiry | attempt still open |
|
|
1231
|
+
| `successGivenAcceptance` | one per _accepted_ attempt | 1 on complete; 0 on fail or **post-acceptance** expiry | no label when flagged a system fault |
|
|
1232
|
+
| `quality` | one per quality observation | normalized `quality` signal, clamped to [0, 1] | **no update at all** |
|
|
1233
1233
|
|
|
1234
1234
|
Component predictions come back as calibrated probabilities; the combined
|
|
1235
1235
|
utility is `acceptanceWeight * P(accept) + P(accept) * (successWeight *
|
|
1236
|
-
P(success|accept) + qualityWeight * E[quality])` and is deliberately
|
|
1236
|
+
P(success|accept) + qualityWeight * E[quality])` and is deliberately _not_
|
|
1237
1237
|
presented as a probability. Corrections revise a label rather than adding a
|
|
1238
1238
|
second one — see `learningRewardAccounting` below.
|
|
1239
1239
|
|
|
@@ -1249,7 +1249,7 @@ statistics that drive automatic routing weights:
|
|
|
1249
1249
|
call is one observation. An attempt that accepts, completes and then receives
|
|
1250
1250
|
a CSAT score counts three times.
|
|
1251
1251
|
- `'per-attempt'`: one observation per committed attempt, written at the
|
|
1252
|
-
terminal outcome with the attempt's accrued reward. Late feedback
|
|
1252
|
+
terminal outcome with the attempt's accrued reward. Late feedback _revises_
|
|
1253
1253
|
that observation instead of adding another.
|
|
1254
1254
|
|
|
1255
1255
|
`'per-attempt'` is what the veto sample floors actually assume — they are
|
|
@@ -1283,7 +1283,7 @@ any recoverable probability, so the logs it produces cannot be evaluated
|
|
|
1283
1283
|
offline at all. `'jitter'` remains the default for backward compatibility.
|
|
1284
1284
|
|
|
1285
1285
|
One honest caveat: under `fairness: 'best-match'` and the other fair modes,
|
|
1286
|
-
allocation is a constrained
|
|
1286
|
+
allocation is a constrained _joint_ decision across workers, and a per-worker
|
|
1287
1287
|
epsilon-greedy probability is not the probability of the final allocation.
|
|
1288
1288
|
Treat fair-mode logs as needing an allocation-aware estimator or a randomized
|
|
1289
1289
|
online comparison, not as ordinary contextual-bandit logs.
|
|
@@ -1293,9 +1293,9 @@ passed every hard rule, and it is disabled entirely in shadow mode.
|
|
|
1293
1293
|
|
|
1294
1294
|
### Worker Performance Features
|
|
1295
1295
|
|
|
1296
|
-
By default the feature vector is assignment-side plus the worker's
|
|
1296
|
+
By default the feature vector is assignment-side plus the worker's _declared_
|
|
1297
1297
|
tags, which means two workers with identical declared tags produce identical
|
|
1298
|
-
features for a given assignment — the model has nothing to learn about
|
|
1298
|
+
features for a given assignment — the model has nothing to learn about _who_
|
|
1299
1299
|
should get the work. `enableLearningPerformanceFeatures` adds observed
|
|
1300
1300
|
behaviour:
|
|
1301
1301
|
|
|
@@ -1371,7 +1371,7 @@ arbitrary continuous rewards is the error the explicit option exists to make
|
|
|
1371
1371
|
visible rather than implicit.
|
|
1372
1372
|
|
|
1373
1373
|
**Evidence is counted in independent attempts, not observations.** With
|
|
1374
|
-
`decayHalfLifeMs` set, the decayed weight sum is
|
|
1374
|
+
`decayHalfLifeMs` set, the decayed weight sum is _not_ a sample size: scaling
|
|
1375
1375
|
every weight equally leaves it looking like fewer observations than were
|
|
1376
1376
|
actually seen. `LearningTagStat` therefore carries `attempts` (never decayed)
|
|
1377
1377
|
and `effectiveSampleSize` (the Kish quantity `sum(w)² / sum(w²)`), and sample
|
|
@@ -2031,6 +2031,16 @@ Break entitlements are checked against shift design: `unpaidBreakMinutes` (deduc
|
|
|
2031
2031
|
|
|
2032
2032
|
**Overtime** is regulated separately from total working time where national law does so. `rules.overtime` defines the ordinary baseline (`ordinaryPerDayMinutes` / `ordinaryPerWeekMinutes`; a person's `contract.weeklyMinutes` overrides the weekly figure, so a part-timer's overtime starts at their agreed hours), caps the overtime portion per rolling 24h or per rolling window, and with `requiresConsent` makes any overtime conditional on the employee's recorded `overtimeConsent`. With `compensation: 'timeOff'`, each employee's period overtime accrues a `timeOffInLieu` entry in `result.ledger`.
|
|
2033
2033
|
|
|
2034
|
+
**Skill mix — how good the people on a shift are, and in what proportion.** `tagRequirements` counts heads holding a tag, which answers "two nurses" and neither of the two questions operational buyers ask first. The **object form** adds a grade floor: `tagRequirements: { nurse: { min: 1, level: 3 } }` is "at least one senior on every shift", satisfied only by a dated `Qualification` at or above that level — a plain `Employee.tags` entry carries no grade, so it cannot answer a question about seniority. `tagRatios: { nurse: 0.6 }` is the **proportion** form: a floor, rounded up (60% of four people is 2.4, and nobody staffs 2.4, so it means three), and silent on an empty shift because a proportion of nobody is undefined rather than zero. Both count through the same dated check `requiredTags` uses, so a lapsed certificate satisfies neither. The plain number form is unchanged and means exactly what it always meant.
|
|
2035
|
+
|
|
2036
|
+
**Weekend sequencing.** `consecutive.maxConsecutiveWeekends: 1` is "every second weekend off" — the most commonly negotiated scheduling term in Europe and the one shape fairness cannot hold, because equalising _counts_ is satisfied exactly as well by three weekends in a row as by alternating ones, and the arrangement is what people agreed to. It is a sequence rule beside consecutive days and nights, and a Saturday and the Sunday after it are one weekend; counting them as two would make an ordinary weekend breach the term.
|
|
2037
|
+
|
|
2038
|
+
**Contracts that do not span the period.** `contract.startDate` gates eligibility at the head as `endDate` does at the tail, and both **pro-rate what the person is owed**: somebody joining on day fifteen of a four-week period is owed a fortnight, not a month. Without it the contract-hours objective spent the solve closing a shortfall that was an artefact of the arithmetic, loading a new starter past everybody who had been there all month. `contract.openingBalanceMinutes` carries hours already worked into every rolling average — the scalar a twelve-month reference period needs instead of replaying a year of shift-level history on every solve.
|
|
2039
|
+
|
|
2040
|
+
**Sites carry their own calendar and clock.** `Site.publicHolidays` replaces `calendar.publicHolidays` for that site's shifts, which is what lets one roster read a border correctly: Midsummer is a public holiday on one side of it and an ordinary Friday on the other, and both are true at once. An empty array means "no holidays here"; omit the field to inherit. `Site.timeZone` is declared for **validation, not arithmetic** — instances resolve once against the period's single `PeriodClock`, so a roster whose sites span zones would place one site's night band, breaks and day boundaries an hour out and still report itself compliant. The engine refuses that input rather than answering it wrongly; solve one roster per zone.
|
|
2041
|
+
|
|
2042
|
+
**Seniority** (`Employee.seniority`) orders `rankCandidates` between otherwise indistinguishable candidates, which is what a collective agreement ordering offers by seniority actually says. It never outranks cost, travel or contract debt, and it stays inside the profiling-free boundary — a declared contractual fact of the same class as a qualification, not reliability, acceptance history or anything learned.
|
|
2043
|
+
|
|
2034
2044
|
**Temporary demand.** A shift template is the standing rule; `demandOverrides` are the temporary ones — each bounded to an inclusive `from`/`to` date range (optionally to `daysOfWeek` inside it) and applied to every occurrence whose date falls in it. An override can replace `minEmployees`, `maxEmployees` (`null` removes it), `tagRequirements`, `tagMaximums` or `requiredTags`, add `extraEmployees` on top of whatever is in force, or set `runs` — whether the shift happens on those dates at all. `runs` works in **both** directions: `false` is a closure, and `true` opens the shift on dates the template's own `dates`/`daysOfWeek` excludes, so a weekday-only shift can take one weekend without widening the template and opening every weekend from then on. A date opened this way inherits the template's own shape unless the override states otherwise. Overrides fold in array order, later wins field by field, `extraEmployees` accumulates, and a minimum raised above the standing maximum lifts the maximum with it — "three at the peak" means three. The result is an ordinary `ShiftInstance` (with `demandLabel` naming the last labelled override that touched it), so the solver, `checkCompliance`, `explainCandidate`, `rankCandidates` and `expandShiftInstances` all read one headcount and none of them knows an override exists. The day after `to`, the shift is back to its standing shape without anybody editing it.
|
|
2035
2045
|
|
|
2036
2046
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { extractMatchFeatures, cosineSimilarity } from './learning/features';
|
|
|
7
7
|
export { synthesizeRoutingWeights, explainRoutingWeights, DEFAULT_AUTO_WEIGHTS_OPTIONS } from './learning/auto-weights';
|
|
8
8
|
export { epsilonGreedySelect, greedySelect } from './learning/policy';
|
|
9
9
|
export type { PolicyChoice, EpsilonGreedyOptions } from './learning/policy';
|
|
10
|
-
export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, expandShiftInstances, checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, hours, days, weeklyAverageOver, DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, type AssignmentPair, type AvailabilityRule, type BreakRule, type ClockRange, type ClockRangeConfig, type ComplianceReport, type ConsecutiveRule, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type EmployeeContract, type ContractHoursRule, type ContractHoursSummary, type EmployeeCost, type EmployeeProtection, type EngagementRule, type FairnessRule, type HistoricalAssignment, type InfeasibilityReport, type LedgerEntry, type MinuteRange, type ModelContext, type NightVolumeQuota, type NightWorkRule, type NoticeRule, type ObjectiveWeights, type OvertimeRule, type PersonTimeline, type Qualification, type RepairCandidate, type RepairResult, type RestDayRule, type RollingAverage, type RuleVerdict, type ScheduleInput, type ScheduleProvenance, type ScheduleResult, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type ShiftDemandOverride, type Site, type SiteIndex, type TimeOffEntry, type TimelineEntry, type TimelineIndex, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
|
|
10
|
+
export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, expandShiftInstances, checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, hours, days, weeklyAverageOver, DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, type AssignmentPair, type AvailabilityRule, type BreakRule, type ClockRange, type ClockRangeConfig, type ComplianceReport, type ConsecutiveRule, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type EmployeeContract, type ContractHoursRule, type ContractHoursSummary, type EmployeeCost, type EmployeeProtection, type EngagementRule, type FairnessRule, type HistoricalAssignment, type InfeasibilityReport, type LedgerEntry, type MinuteRange, type ModelContext, type NightVolumeQuota, type NightWorkRule, type NoticeRule, type ObjectiveWeights, type OvertimeRule, type PersonTimeline, type Qualification, type RepairCandidate, type RepairResult, type RestDayRule, type RollingAverage, type RuleVerdict, type ScheduleInput, type ScheduleProvenance, type ScheduleResult, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type TagRequirement, type ShiftDemandOverride, type Site, type SiteIndex, type TimeOffEntry, type TimelineEntry, type TimelineIndex, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
|
|
11
11
|
export { WorkflowBuilder, WorkflowStepBuilder, workflow, linearWorkflow, approvalWorkflow } from './workflow-builder';
|
|
12
12
|
export { normalizeWorkflowDefinition, validateWorkflowDefinition } from './workflow-validation';
|
|
13
13
|
export * from './utils/cidr';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EACR,UAAU,EACV,cAAc,EACd,OAAO,EACP,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B,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGhG,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAe,iBAAiB,CAAC"}
|
|
@@ -19,6 +19,16 @@ import type { ConsecutiveRule, SchedulingConstraint } from '../types';
|
|
|
19
19
|
export declare const CONSECUTIVE_CITATION = "National working-time law / collective agreement";
|
|
20
20
|
/** Every sequence constraint the rule configures. */
|
|
21
21
|
export declare function consecutiveConstraints(rule: ConsecutiveRule): SchedulingConstraint[];
|
|
22
|
+
/**
|
|
23
|
+
* Weekends in a row.
|
|
24
|
+
*
|
|
25
|
+
* "Every second weekend off" — the term most often negotiated and the one a
|
|
26
|
+
* count cannot hold. Weekends are keyed by the Saturday that opens them, so a
|
|
27
|
+
* Saturday and the Sunday after it are one weekend; keying by week number would
|
|
28
|
+
* split a weekend across a year boundary and keying by day would make every
|
|
29
|
+
* ordinary weekend a run of two.
|
|
30
|
+
*/
|
|
31
|
+
export declare function consecutiveWeekends(maxWeekends: number): SchedulingConstraint;
|
|
22
32
|
export declare function consecutiveDays(maxDays: number): SchedulingConstraint;
|
|
23
33
|
export declare function consecutiveNights(rule: ConsecutiveRule): SchedulingConstraint;
|
|
24
34
|
export declare function shiftSuccession(forbidden: NonNullable<ConsecutiveRule['forbiddenSuccessions']>): SchedulingConstraint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consecutive.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/consecutive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAe,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAI/G,eAAO,MAAM,oBAAoB,qDAAqD,CAAC;AAEvF,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"consecutive.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/consecutive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAe,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAI/G,eAAO,MAAM,oBAAoB,qDAAqD,CAAC;AAEvF,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,EAAE,CASpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,oBAAoB,CAiC7E;AAwBD,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAiCrE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,CAqE7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC,GAAG,oBAAoB,CA6DrH"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* minimum.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.shiftSuccession = exports.consecutiveNights = exports.consecutiveDays = exports.consecutiveConstraints = exports.CONSECUTIVE_CITATION = void 0;
|
|
20
|
+
exports.shiftSuccession = exports.consecutiveNights = exports.consecutiveDays = exports.consecutiveWeekends = exports.consecutiveConstraints = exports.CONSECUTIVE_CITATION = void 0;
|
|
21
21
|
const support_1 = require("./support");
|
|
22
22
|
exports.CONSECUTIVE_CITATION = 'National working-time law / collective agreement';
|
|
23
23
|
/** Every sequence constraint the rule configures. */
|
|
@@ -28,11 +28,74 @@ function consecutiveConstraints(rule) {
|
|
|
28
28
|
if (rule.maxNightShifts !== undefined || rule.restAfterNightBlockMinutes !== undefined) {
|
|
29
29
|
out.push(consecutiveNights(rule));
|
|
30
30
|
}
|
|
31
|
+
if (rule.maxConsecutiveWeekends !== undefined)
|
|
32
|
+
out.push(consecutiveWeekends(rule.maxConsecutiveWeekends));
|
|
31
33
|
if (rule.forbiddenSuccessions?.length)
|
|
32
34
|
out.push(shiftSuccession(rule.forbiddenSuccessions));
|
|
33
35
|
return out;
|
|
34
36
|
}
|
|
35
37
|
exports.consecutiveConstraints = consecutiveConstraints;
|
|
38
|
+
/**
|
|
39
|
+
* Weekends in a row.
|
|
40
|
+
*
|
|
41
|
+
* "Every second weekend off" — the term most often negotiated and the one a
|
|
42
|
+
* count cannot hold. Weekends are keyed by the Saturday that opens them, so a
|
|
43
|
+
* Saturday and the Sunday after it are one weekend; keying by week number would
|
|
44
|
+
* split a weekend across a year boundary and keying by day would make every
|
|
45
|
+
* ordinary weekend a run of two.
|
|
46
|
+
*/
|
|
47
|
+
function consecutiveWeekends(maxWeekends) {
|
|
48
|
+
return (0, support_1.fromVerdict)({
|
|
49
|
+
id: 'consecutive-weekends',
|
|
50
|
+
hardness: 'hard',
|
|
51
|
+
weight: 1,
|
|
52
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
53
|
+
verdict(state, pair) {
|
|
54
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
55
|
+
if (!inst)
|
|
56
|
+
return (0, support_1.pass)('consecutive-weekends', 'unknown shift');
|
|
57
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
58
|
+
const probe = { ...(0, support_1.rangeOf)(inst), id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes };
|
|
59
|
+
const clock = state.ctx.clock;
|
|
60
|
+
return timeline.withEntry(probe, (t) => {
|
|
61
|
+
const run = t.longestConsecutiveWeekends((minute) => weekendKey(clock, minute));
|
|
62
|
+
if (run > maxWeekends) {
|
|
63
|
+
return (0, support_1.fail)('consecutive-weekends', 'hard', `employee "${pair.employeeId}" would work ${run} weekends in a row, over the ${maxWeekends} allowed`, { actual: run, required: maxWeekends, unit: 'count', citation: exports.CONSECUTIVE_CITATION });
|
|
64
|
+
}
|
|
65
|
+
return (0, support_1.pass)('consecutive-weekends', `${run} weekends in a row, within the ${maxWeekends} allowed`, {
|
|
66
|
+
actual: run,
|
|
67
|
+
required: maxWeekends,
|
|
68
|
+
unit: 'count',
|
|
69
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.consecutiveWeekends = consecutiveWeekends;
|
|
76
|
+
/**
|
|
77
|
+
* Which weekend a minute belongs to, as a consecutive ordinal, or `null` for a
|
|
78
|
+
* weekday.
|
|
79
|
+
*
|
|
80
|
+
* Resolved to the Saturday that opens the weekend first — a Sunday belongs to
|
|
81
|
+
* the weekend whose Saturday was the day before, so an ordinary weekend is one
|
|
82
|
+
* weekend rather than two — and then divided into weeks, so that successive
|
|
83
|
+
* weekends differ by exactly one and the run check is a plain `+ 1`.
|
|
84
|
+
*
|
|
85
|
+
* The division is safe at any period alignment and before the period starts:
|
|
86
|
+
* Saturdays are always seven days apart, so integer division by seven yields
|
|
87
|
+
* consecutive ordinals wherever the period begins, and `Math.floor` carries
|
|
88
|
+
* that through the negative indices history occupies.
|
|
89
|
+
*/
|
|
90
|
+
function weekendKey(clock, minute) {
|
|
91
|
+
const weekday = clock.weekdayOfMinute(minute);
|
|
92
|
+
const dayIndex = clock.dayIndexOfMinute(minute);
|
|
93
|
+
if (weekday === 6)
|
|
94
|
+
return Math.floor(dayIndex / 7);
|
|
95
|
+
if (weekday === 7)
|
|
96
|
+
return Math.floor((dayIndex - 1) / 7);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
36
99
|
function consecutiveDays(maxDays) {
|
|
37
100
|
return (0, support_1.fromVerdict)({
|
|
38
101
|
id: 'consecutive-days',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,eAAO,MAAM,uBAAuB,yEAAyE,CAAC;AAE9G,wBAAgB,cAAc,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,eAAO,MAAM,uBAAuB,yEAAyE,CAAC;AAE9G,wBAAgB,cAAc,IAAI,oBAAoB,CA8KrD"}
|
|
@@ -28,12 +28,18 @@ function contractLimits() {
|
|
|
28
28
|
weight: 1,
|
|
29
29
|
prune(ctx, eligibility) {
|
|
30
30
|
for (const [employeeId, instances] of eligibility) {
|
|
31
|
-
const
|
|
32
|
-
if (!endDate)
|
|
31
|
+
const contract = ctx.employeeById.get(employeeId)?.contract;
|
|
32
|
+
if (!contract?.startDate && !contract?.endDate)
|
|
33
33
|
continue;
|
|
34
34
|
for (const instanceId of [...instances]) {
|
|
35
35
|
const inst = ctx.instanceById.get(instanceId);
|
|
36
|
-
if (inst
|
|
36
|
+
if (!inst)
|
|
37
|
+
continue;
|
|
38
|
+
// Both ends, one rule: a shift before somebody joins is as
|
|
39
|
+
// unworkable as one after they leave.
|
|
40
|
+
if (contract.endDate && inst.date > contract.endDate)
|
|
41
|
+
instances.delete(instanceId);
|
|
42
|
+
else if (contract.startDate && inst.date < contract.startDate)
|
|
37
43
|
instances.delete(instanceId);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
@@ -46,6 +52,9 @@ function contractLimits() {
|
|
|
46
52
|
if (contract.endDate && inst.date > contract.endDate) {
|
|
47
53
|
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract ends ${contract.endDate}, before "${inst.id}"`);
|
|
48
54
|
}
|
|
55
|
+
if (contract.startDate && inst.date < contract.startDate) {
|
|
56
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract starts ${contract.startDate}, after "${inst.id}"`);
|
|
57
|
+
}
|
|
49
58
|
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
50
59
|
const probe = {
|
|
51
60
|
start: inst.startMinute,
|
|
@@ -33,7 +33,7 @@ function groupComposition() {
|
|
|
33
33
|
return (0, support_1.fail)('group-composition', 'hard', `"${inst.id}" already has its maximum of ${inst.maxEmployees} assignees`, { actual: wouldBe, required: inst.maxEmployees, unit: 'count' });
|
|
34
34
|
}
|
|
35
35
|
for (const [tag, max] of Object.entries(inst.tagMaximums)) {
|
|
36
|
-
if (!state.ctx.
|
|
36
|
+
if (!state.ctx.holdsTagOn(pair.employeeId, tag, inst.date))
|
|
37
37
|
continue;
|
|
38
38
|
const current = countTag(state, inst, tag, pair.employeeId);
|
|
39
39
|
if (current + 1 > max) {
|
|
@@ -85,7 +85,7 @@ function countTag(state, inst, tag, exclude) {
|
|
|
85
85
|
for (const employeeId of state.assignments.get(inst.id) ?? []) {
|
|
86
86
|
if (employeeId === exclude)
|
|
87
87
|
continue;
|
|
88
|
-
if (state.ctx.
|
|
88
|
+
if (state.ctx.holdsTagOn(employeeId, tag, inst.date))
|
|
89
89
|
count++;
|
|
90
90
|
}
|
|
91
91
|
return count;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-staffing.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-staffing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"min-staffing.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-staffing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AA2B/G,wBAAgB,WAAW,IAAI,oBAAoB,CAOlD;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,mBAAmB,EAAE,CA4DnH"}
|
|
@@ -10,6 +10,25 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.staffingViolations = exports.minStaffing = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* How many of the assigned team hold a tag on the shift's date, at or above an
|
|
15
|
+
* optional grade floor.
|
|
16
|
+
*
|
|
17
|
+
* One helper for both the count and the ratio, so a graded minimum and a
|
|
18
|
+
* proportion can never disagree about who counts — and both read the date, so a
|
|
19
|
+
* lapsed certificate satisfies neither.
|
|
20
|
+
*/
|
|
21
|
+
function countTag(ctx, assigned, tag, date, minLevel) {
|
|
22
|
+
if (!assigned)
|
|
23
|
+
return 0;
|
|
24
|
+
let have = 0;
|
|
25
|
+
for (const employeeId of assigned) {
|
|
26
|
+
if (minLevel === undefined ? ctx.holdsTagOn(employeeId, tag, date) : ctx.holdsTagAt(employeeId, tag, date, minLevel)) {
|
|
27
|
+
have++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return have;
|
|
31
|
+
}
|
|
13
32
|
function minStaffing() {
|
|
14
33
|
return {
|
|
15
34
|
id: 'min-staffing',
|
|
@@ -36,20 +55,44 @@ function staffingViolations(ctx, state, severity) {
|
|
|
36
55
|
unit: 'count',
|
|
37
56
|
});
|
|
38
57
|
}
|
|
39
|
-
for (const [tag,
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
|
|
59
|
+
const have = countTag(ctx, assigned, tag, inst.date, requirement.level);
|
|
60
|
+
if (have < requirement.min) {
|
|
61
|
+
const graded = requirement.level === undefined ? '' : ` at level ${requirement.level}`;
|
|
62
|
+
out.push({
|
|
63
|
+
constraintId: 'min-staffing',
|
|
64
|
+
severity,
|
|
65
|
+
shiftInstanceId: inst.id,
|
|
66
|
+
message: `shift "${inst.id}" needs ${requirement.min} employees with tag "${tag}"${graded}, has ${have}`,
|
|
67
|
+
actual: have,
|
|
68
|
+
required: requirement.min,
|
|
69
|
+
unit: 'count',
|
|
70
|
+
});
|
|
46
71
|
}
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
* Proportions, which a headcount cannot express.
|
|
75
|
+
*
|
|
76
|
+
* A floor rounded up: 60% of four people is 2.4, and nobody staffs 2.4.
|
|
77
|
+
* An empty shift is silent — a proportion of nobody is undefined, and
|
|
78
|
+
* reporting it as a breach would bury the real finding, which is the
|
|
79
|
+
* unstaffed shift already reported above.
|
|
80
|
+
*/
|
|
81
|
+
for (const [tag, ratio] of Object.entries(inst.tagRatios)) {
|
|
82
|
+
if (count === 0)
|
|
83
|
+
continue;
|
|
84
|
+
const needed = Math.ceil(ratio * count);
|
|
85
|
+
const have = countTag(ctx, assigned, tag, inst.date);
|
|
47
86
|
if (have < needed) {
|
|
48
87
|
out.push({
|
|
49
88
|
constraintId: 'min-staffing',
|
|
50
89
|
severity,
|
|
51
90
|
shiftInstanceId: inst.id,
|
|
52
|
-
message: `shift "${inst.id}" needs ${
|
|
91
|
+
message: `shift "${inst.id}" needs ${Math.round(ratio * 100)}% of its team tagged "${tag}" ` +
|
|
92
|
+
`(${needed} of ${count}), has ${have} of ${count}`,
|
|
93
|
+
actual: have,
|
|
94
|
+
required: needed,
|
|
95
|
+
unit: 'count',
|
|
53
96
|
});
|
|
54
97
|
}
|
|
55
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolling-hours.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rolling-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,qBAAqB,6CAA6C,CAAC;AAEhF,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"rolling-hours.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rolling-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,qBAAqB,6CAA6C,CAAC;AAEhF,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,CAoF5E"}
|
|
@@ -57,9 +57,13 @@ function rollingHours(limits) {
|
|
|
57
57
|
return over('week', weekTotal, limits.maxPerWeekAbsoluteMinutes, pair.employeeId, inst.id);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// Which average the opening balance belongs to. Computed once
|
|
61
|
+
// per verdict rather than per average, and ties are harmless:
|
|
62
|
+
// two averages over the same window are the same window.
|
|
63
|
+
const longestWindowDays = Math.max(0, ...(limits.rollingAverages ?? []).map((a) => a.windowDays));
|
|
60
64
|
for (const average of limits.rollingAverages ?? []) {
|
|
61
65
|
const span = average.windowDays * support_1.MINUTES_PER_DAY;
|
|
62
|
-
const breach = worstAverageBreach(state, t, pair.employeeId, average.maxMinutes, span, range, limits);
|
|
66
|
+
const breach = worstAverageBreach(state, t, pair.employeeId, average.maxMinutes, span, range, limits, average.windowDays === longestWindowDays);
|
|
63
67
|
if (breach !== null) {
|
|
64
68
|
const label = average.label ?? `${(0, support_1.h)(average.maxMinutes)}/${average.windowDays}d`;
|
|
65
69
|
return (0, support_1.fail)('rolling-hours', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(breach.worked)} in some ${average.windowDays}-day window, over the ${label} limit of ${(0, support_1.h)(breach.allowance)}`, {
|
|
@@ -114,14 +118,35 @@ function dayAverageHolds(timeline, limits, range) {
|
|
|
114
118
|
* start, with breakpoints at entry and absence boundaries, so the extreme lies
|
|
115
119
|
* on a window whose edge touches one of those boundaries (or the probe bounds).
|
|
116
120
|
*/
|
|
117
|
-
function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range, limits) {
|
|
121
|
+
function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range, limits, appliesTo) {
|
|
118
122
|
const bounds = windowFor(range, span);
|
|
119
123
|
const kinds = limits.neutraliseAbsenceKinds;
|
|
120
124
|
const neutral = kinds?.length
|
|
121
125
|
? (state.ctx.absences.get(employeeId) ?? []).filter((a) => a.kind !== undefined && kinds.includes(a.kind))
|
|
122
126
|
: [];
|
|
127
|
+
/*
|
|
128
|
+
* Hours already inside the window when the period opened.
|
|
129
|
+
*
|
|
130
|
+
* A twelve-month reference period otherwise needs twelve months of
|
|
131
|
+
* shift-level history replayed on every solve, because the only way to put
|
|
132
|
+
* minutes into a window was one assignment at a time. The balance is added
|
|
133
|
+
* to the *worked* side rather than taken off the cap so the reported
|
|
134
|
+
* numbers stay legible: "would work 114h against a 100h budget" is what a
|
|
135
|
+
* person needs to read, not "would work 16h against 2h".
|
|
136
|
+
*
|
|
137
|
+
* It belongs to the **longest** window and to no other. Hours worked last
|
|
138
|
+
* autumn are inside a 365-day window and are plainly not inside the last
|
|
139
|
+
* seven days, so adding the figure to every average made 1,500 hours into
|
|
140
|
+
* an annual budget breach a 48-hour *week* — and the one configuration the
|
|
141
|
+
* field exists for, an annual reference period beside the ordinary weekly
|
|
142
|
+
* average, produced an empty roster with no error at all.
|
|
143
|
+
*
|
|
144
|
+
* The longest window is the reference period the balance was measured over,
|
|
145
|
+
* which is the only window it can honestly be added to.
|
|
146
|
+
*/
|
|
147
|
+
const carried = appliesTo ? (state.ctx.employeeById.get(employeeId)?.contract?.openingBalanceMinutes ?? 0) : 0;
|
|
123
148
|
if (neutral.length === 0) {
|
|
124
|
-
const worked = timeline.maxWorkingMinutesInAnyWindow(span, bounds);
|
|
149
|
+
const worked = timeline.maxWorkingMinutesInAnyWindow(span, bounds) + carried;
|
|
125
150
|
return worked > maxMinutes ? { worked, allowance: maxMinutes } : null;
|
|
126
151
|
}
|
|
127
152
|
const starts = new Set([bounds.start, bounds.end - span]);
|
|
@@ -136,7 +161,7 @@ function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range
|
|
|
136
161
|
let worst = null;
|
|
137
162
|
for (const start of starts) {
|
|
138
163
|
const window = { start, end: start + span };
|
|
139
|
-
const worked = timeline.workingMinutesIn(window);
|
|
164
|
+
const worked = timeline.workingMinutesIn(window) + carried;
|
|
140
165
|
const neutralMinutes = neutral.reduce((sum, a) => sum + Math.max(0, Math.min(a.end, window.end) - Math.max(a.start, window.start)), 0);
|
|
141
166
|
const allowance = maxMinutes * (1 - Math.min(1, neutralMinutes / span));
|
|
142
167
|
const excess = worked - allowance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;
|
|
1
|
+
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;AAmFD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAwDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,IAAI,EAAE,MAAM,MAAM,GACnB,IAAI,CA0CN;AAKD;;;;GAIG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,CA6BN"}
|
|
@@ -36,17 +36,37 @@ function rankCandidate(ctx, state, instanceId, employeeId, objective, rand) {
|
|
|
36
36
|
const inst = ctx.instanceById.get(instanceId);
|
|
37
37
|
if (inst) {
|
|
38
38
|
const assigned = state.assignments.get(instanceId);
|
|
39
|
-
for (const [tag,
|
|
39
|
+
for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
|
|
40
|
+
const counts = (id) => requirement.level === undefined
|
|
41
|
+
? ctx.holdsTagOn(id, tag, inst.date)
|
|
42
|
+
: ctx.holdsTagAt(id, tag, inst.date, requirement.level);
|
|
40
43
|
let have = 0;
|
|
41
44
|
if (assigned)
|
|
42
45
|
for (const e of assigned)
|
|
43
|
-
if (
|
|
46
|
+
if (counts(e))
|
|
44
47
|
have++;
|
|
45
|
-
if (have <
|
|
48
|
+
if (have < requirement.min && counts(employeeId)) {
|
|
46
49
|
rank -= 1000;
|
|
47
50
|
reasons.push(`fills tag requirement "${tag}"`);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
53
|
+
// Somebody who moves a proportion toward its floor. Judged against the
|
|
54
|
+
// team as it stands, so the preference strengthens as the shift fills
|
|
55
|
+
// rather than being decided when it was empty.
|
|
56
|
+
const onShift = assigned?.size ?? 0;
|
|
57
|
+
for (const [tag, ratio] of Object.entries(inst.tagRatios)) {
|
|
58
|
+
if (!ctx.holdsTagOn(employeeId, tag, inst.date))
|
|
59
|
+
continue;
|
|
60
|
+
let have = 0;
|
|
61
|
+
if (assigned)
|
|
62
|
+
for (const e of assigned)
|
|
63
|
+
if (ctx.holdsTagOn(e, tag, inst.date))
|
|
64
|
+
have++;
|
|
65
|
+
if (have < Math.ceil(ratio * (onShift + 1))) {
|
|
66
|
+
rank -= 800;
|
|
67
|
+
reasons.push(`helps the "${tag}" ratio`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
50
70
|
}
|
|
51
71
|
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
52
72
|
const contracted = ctx.contractedPeriodMinutes.get(employeeId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKxE,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAI9D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,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AM,CA8B7F;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAI3E;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAK3E;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAMhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,QAAQ,CAgB5E;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE1E;AAED,kEAAkE;AAClE,wBAAgB,QAAQ,CACpB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,YAAY,EAAE,GAC/B,QAAQ,CA6BV;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACjB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,GACvB,MAAM,CAGR"}
|
|
@@ -63,14 +63,31 @@ function tagShortage(ctx, state, instanceId) {
|
|
|
63
63
|
return 0;
|
|
64
64
|
const assigned = state.assignments.get(instanceId);
|
|
65
65
|
let short = 0;
|
|
66
|
-
for (const [tag,
|
|
66
|
+
for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
|
|
67
67
|
let have = 0;
|
|
68
68
|
if (assigned) {
|
|
69
|
+
for (const employeeId of assigned) {
|
|
70
|
+
const holds = requirement.level === undefined
|
|
71
|
+
? ctx.holdsTagOn(employeeId, tag, inst.date)
|
|
72
|
+
: ctx.holdsTagAt(employeeId, tag, inst.date, requirement.level);
|
|
73
|
+
if (holds)
|
|
74
|
+
have++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
short += Math.max(0, requirement.min - have);
|
|
78
|
+
}
|
|
79
|
+
// A ratio's shortfall is measured against the team that is actually on, so
|
|
80
|
+
// it moves as the shift fills — which is what lets the search close it by
|
|
81
|
+
// adding the right person rather than by adding anybody.
|
|
82
|
+
const size = assigned?.size ?? 0;
|
|
83
|
+
if (size > 0) {
|
|
84
|
+
for (const [tag, ratio] of Object.entries(inst.tagRatios)) {
|
|
85
|
+
let have = 0;
|
|
69
86
|
for (const employeeId of assigned)
|
|
70
|
-
if (ctx.
|
|
87
|
+
if (ctx.holdsTagOn(employeeId, tag, inst.date))
|
|
71
88
|
have++;
|
|
89
|
+
short += Math.max(0, Math.ceil(ratio * size) - have);
|
|
72
90
|
}
|
|
73
|
-
short += Math.max(0, needed - have);
|
|
74
91
|
}
|
|
75
92
|
return short;
|
|
76
93
|
}
|
|
@@ -148,6 +148,20 @@ export declare class PersonTimeline {
|
|
|
148
148
|
* a day so the caller's clock owns DST, not this structure.
|
|
149
149
|
*/
|
|
150
150
|
longestConsecutiveDays(dayIndexOf: (minute: number) => number): number;
|
|
151
|
+
/**
|
|
152
|
+
* The longest run of consecutive weekends any entry falls in.
|
|
153
|
+
*
|
|
154
|
+
* "Every second weekend off" is the most commonly negotiated scheduling
|
|
155
|
+
* term in Europe and the one shape a *count* cannot express: three weekends
|
|
156
|
+
* each is satisfied exactly as well by three in a row as by alternating
|
|
157
|
+
* ones, and the arrangement is the thing people agreed to.
|
|
158
|
+
*
|
|
159
|
+
* Weekends are keyed by the week they belong to, so a Saturday and the
|
|
160
|
+
* Sunday after it are one weekend rather than two — otherwise working an
|
|
161
|
+
* ordinary weekend would breach "every second", which is the opposite of
|
|
162
|
+
* what it asks. A Sunday belongs to the week whose Saturday preceded it.
|
|
163
|
+
*/
|
|
164
|
+
longestConsecutiveWeekends(weekendKeyOf: (minute: number) => number | null): number;
|
|
151
165
|
/**
|
|
152
166
|
* First index that may overlap a window starting at `windowStart`.
|
|
153
167
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,0EAA0E;IAC1E,EAAE,EAAE,MAAM,CAAC;IACX,wFAAwF;IACxF,cAAc,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,OAAO,CAAuB;IACtC,+DAA+D;IAC/D,OAAO,CAAC,MAAM,CAAiB;IAC/B,4EAA4E;IAC5E,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,GAAE,aAAa,EAAO;IAMzC,oDAAoD;IACpD,GAAG,IAAI,SAAS,aAAa,EAAE;IAK/B,yEAAyE;IACzE,mBAAmB,IAAI,MAAM;IAK7B,GAAG,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAQ/B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAQ3B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB;;;;;;;;;OASG;IACH,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM;IAc7C;;;;;;;;;;OAUG;IACH,4BAA4B,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM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O,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAElD,OAAO,GAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAa;IAM7D,yDAAyD;IACzD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IASrC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;IAIjD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD,SAAS,IAAI,MAAM,EAAE;CAGxB"}
|
|
@@ -309,6 +309,39 @@ class PersonTimeline {
|
|
|
309
309
|
}
|
|
310
310
|
return longest;
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* The longest run of consecutive weekends any entry falls in.
|
|
314
|
+
*
|
|
315
|
+
* "Every second weekend off" is the most commonly negotiated scheduling
|
|
316
|
+
* term in Europe and the one shape a *count* cannot express: three weekends
|
|
317
|
+
* each is satisfied exactly as well by three in a row as by alternating
|
|
318
|
+
* ones, and the arrangement is the thing people agreed to.
|
|
319
|
+
*
|
|
320
|
+
* Weekends are keyed by the week they belong to, so a Saturday and the
|
|
321
|
+
* Sunday after it are one weekend rather than two — otherwise working an
|
|
322
|
+
* ordinary weekend would breach "every second", which is the opposite of
|
|
323
|
+
* what it asks. A Sunday belongs to the week whose Saturday preceded it.
|
|
324
|
+
*/
|
|
325
|
+
longestConsecutiveWeekends(weekendKeyOf) {
|
|
326
|
+
this.ensureClean();
|
|
327
|
+
const weekends = new Set();
|
|
328
|
+
for (const entry of this.entries) {
|
|
329
|
+
const key = weekendKeyOf(entry.start);
|
|
330
|
+
if (key !== null)
|
|
331
|
+
weekends.add(key);
|
|
332
|
+
}
|
|
333
|
+
const sorted = [...weekends].sort((a, b) => a - b);
|
|
334
|
+
let longest = 0;
|
|
335
|
+
let current = 0;
|
|
336
|
+
let previous;
|
|
337
|
+
for (const weekend of sorted) {
|
|
338
|
+
current = previous !== undefined && weekend === previous + 1 ? current + 1 : 1;
|
|
339
|
+
if (current > longest)
|
|
340
|
+
longest = current;
|
|
341
|
+
previous = weekend;
|
|
342
|
+
}
|
|
343
|
+
return longest;
|
|
344
|
+
}
|
|
312
345
|
/**
|
|
313
346
|
* First index that may overlap a window starting at `windowStart`.
|
|
314
347
|
*
|