assignment-user-matcher 1.16.1 → 1.22.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 (153) hide show
  1. package/README.md +290 -8
  2. package/dist/escalation/policy.d.ts +11 -0
  3. package/dist/escalation/policy.d.ts.map +1 -1
  4. package/dist/escalation/policy.js +22 -1
  5. package/dist/forecasting/backtest.d.ts +52 -0
  6. package/dist/forecasting/backtest.d.ts.map +1 -0
  7. package/dist/forecasting/backtest.js +195 -0
  8. package/dist/forecasting/calendar.d.ts +44 -0
  9. package/dist/forecasting/calendar.d.ts.map +1 -0
  10. package/dist/forecasting/calendar.js +85 -0
  11. package/dist/forecasting/cover.d.ts +69 -0
  12. package/dist/forecasting/cover.d.ts.map +1 -0
  13. package/dist/forecasting/cover.js +103 -0
  14. package/dist/forecasting/days.d.ts +17 -0
  15. package/dist/forecasting/days.d.ts.map +1 -0
  16. package/dist/forecasting/days.js +35 -0
  17. package/dist/forecasting/distributions.d.ts +31 -0
  18. package/dist/forecasting/distributions.d.ts.map +1 -0
  19. package/dist/forecasting/distributions.js +154 -0
  20. package/dist/forecasting/effects.d.ts +88 -0
  21. package/dist/forecasting/effects.d.ts.map +1 -0
  22. package/dist/forecasting/effects.js +303 -0
  23. package/dist/forecasting/erlang.d.ts +31 -0
  24. package/dist/forecasting/erlang.d.ts.map +1 -0
  25. package/dist/forecasting/erlang.js +86 -0
  26. package/dist/forecasting/forecast.d.ts +7 -0
  27. package/dist/forecasting/forecast.d.ts.map +1 -0
  28. package/dist/forecasting/forecast.js +221 -0
  29. package/dist/forecasting/index.d.ts +18 -0
  30. package/dist/forecasting/index.d.ts.map +1 -0
  31. package/dist/forecasting/index.js +54 -0
  32. package/dist/forecasting/model.d.ts +145 -0
  33. package/dist/forecasting/model.d.ts.map +1 -0
  34. package/dist/forecasting/model.js +583 -0
  35. package/dist/forecasting/nowcast.d.ts +26 -0
  36. package/dist/forecasting/nowcast.d.ts.map +1 -0
  37. package/dist/forecasting/nowcast.js +92 -0
  38. package/dist/forecasting/simulation.d.ts +91 -0
  39. package/dist/forecasting/simulation.d.ts.map +1 -0
  40. package/dist/forecasting/simulation.js +478 -0
  41. package/dist/forecasting/spikes.d.ts +6 -0
  42. package/dist/forecasting/spikes.d.ts.map +1 -0
  43. package/dist/forecasting/spikes.js +73 -0
  44. package/dist/forecasting/staffing.d.ts +64 -0
  45. package/dist/forecasting/staffing.d.ts.map +1 -0
  46. package/dist/forecasting/staffing.js +765 -0
  47. package/dist/forecasting/stats.d.ts +11 -0
  48. package/dist/forecasting/stats.d.ts.map +1 -0
  49. package/dist/forecasting/stats.js +45 -0
  50. package/dist/forecasting/types.d.ts +299 -0
  51. package/dist/forecasting/types.d.ts.map +1 -0
  52. package/dist/forecasting/types.js +8 -0
  53. package/dist/index.d.ts +3 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +8 -1
  56. package/dist/learning/auto-weights.d.ts +1 -5
  57. package/dist/learning/auto-weights.d.ts.map +1 -1
  58. package/dist/learning/auto-weights.js +0 -3
  59. package/dist/lua/book-slot.lua +84 -0
  60. package/dist/lua/claim-queued.lua +47 -0
  61. package/dist/managers/DecisionTraceManager.d.ts +15 -0
  62. package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
  63. package/dist/managers/DecisionTraceManager.js +117 -11
  64. package/dist/managers/LearningManager.d.ts +12 -0
  65. package/dist/managers/LearningManager.d.ts.map +1 -1
  66. package/dist/managers/LearningManager.js +21 -7
  67. package/dist/managers/ReliabilityManager.d.ts +1 -2
  68. package/dist/managers/ReliabilityManager.d.ts.map +1 -1
  69. package/dist/managers/ReliabilityManager.js +1 -1
  70. package/dist/managers/TelemetryManager.d.ts.map +1 -1
  71. package/dist/managers/TelemetryManager.js +9 -3
  72. package/dist/managers/WorkflowManager.d.ts.map +1 -1
  73. package/dist/managers/WorkflowManager.js +3 -4
  74. package/dist/matcher.class.d.ts +319 -4
  75. package/dist/matcher.class.d.ts.map +1 -1
  76. package/dist/matcher.class.js +1428 -102
  77. package/dist/queries/lane-stats.d.ts +51 -0
  78. package/dist/queries/lane-stats.d.ts.map +1 -0
  79. package/dist/queries/lane-stats.js +78 -0
  80. package/dist/schedule/recurrence.d.ts +11 -0
  81. package/dist/schedule/recurrence.d.ts.map +1 -1
  82. package/dist/schedule/recurrence.js +19 -2
  83. package/dist/schedule/slot.d.ts +60 -0
  84. package/dist/schedule/slot.d.ts.map +1 -0
  85. package/dist/schedule/slot.js +86 -0
  86. package/dist/scheduling/constraints/availability.d.ts +2 -14
  87. package/dist/scheduling/constraints/availability.d.ts.map +1 -1
  88. package/dist/scheduling/constraints/availability.js +14 -15
  89. package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
  90. package/dist/scheduling/constraints/employee-scope.js +10 -2
  91. package/dist/scheduling/constraints/support.d.ts +4 -8
  92. package/dist/scheduling/constraints/support.d.ts.map +1 -1
  93. package/dist/scheduling/constraints/support.js +23 -2
  94. package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
  95. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
  96. package/dist/scheduling/constraints/weekly-rest.js +108 -21
  97. package/dist/scheduling/engine/construction.d.ts.map +1 -1
  98. package/dist/scheduling/engine/construction.js +33 -4
  99. package/dist/scheduling/engine/objective.d.ts +0 -1
  100. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  101. package/dist/scheduling/engine/objective.js +45 -3
  102. package/dist/scheduling/engine/search.d.ts +4 -0
  103. package/dist/scheduling/engine/search.d.ts.map +1 -1
  104. package/dist/scheduling/engine/search.js +2 -1
  105. package/dist/scheduling/engine/state.d.ts +14 -0
  106. package/dist/scheduling/engine/state.d.ts.map +1 -1
  107. package/dist/scheduling/engine/state.js +7 -0
  108. package/dist/scheduling/engine/timeline.d.ts +9 -1
  109. package/dist/scheduling/engine/timeline.d.ts.map +1 -1
  110. package/dist/scheduling/engine/timeline.js +52 -27
  111. package/dist/scheduling/engine/verdicts.d.ts +40 -1
  112. package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
  113. package/dist/scheduling/engine/verdicts.js +177 -17
  114. package/dist/scheduling/index.d.ts +3 -2
  115. package/dist/scheduling/index.d.ts.map +1 -1
  116. package/dist/scheduling/index.js +7 -1
  117. package/dist/scheduling/model.d.ts +2 -3
  118. package/dist/scheduling/model.d.ts.map +1 -1
  119. package/dist/scheduling/model.js +30 -12
  120. package/dist/scheduling/operations.d.ts +174 -2
  121. package/dist/scheduling/operations.d.ts.map +1 -1
  122. package/dist/scheduling/operations.js +513 -15
  123. package/dist/scheduling/preference-report.d.ts +15 -0
  124. package/dist/scheduling/preference-report.d.ts.map +1 -0
  125. package/dist/scheduling/preference-report.js +111 -0
  126. package/dist/scheduling/preferences.d.ts +30 -0
  127. package/dist/scheduling/preferences.d.ts.map +1 -0
  128. package/dist/scheduling/preferences.js +85 -0
  129. package/dist/scheduling/resilience.d.ts +46 -0
  130. package/dist/scheduling/resilience.d.ts.map +1 -0
  131. package/dist/scheduling/resilience.js +45 -0
  132. package/dist/scheduling/scheduler.class.d.ts +12 -1
  133. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  134. package/dist/scheduling/scheduler.class.js +28 -4
  135. package/dist/scheduling/time.d.ts +28 -6
  136. package/dist/scheduling/time.d.ts.map +1 -1
  137. package/dist/scheduling/time.js +59 -17
  138. package/dist/scheduling/types.d.ts +107 -1
  139. package/dist/scheduling/types.d.ts.map +1 -1
  140. package/dist/scoring/fair-arbitration.d.ts.map +1 -1
  141. package/dist/scoring/fair-arbitration.js +2 -1
  142. package/dist/tracing/decision-trace.d.ts +5 -0
  143. package/dist/tracing/decision-trace.d.ts.map +1 -1
  144. package/dist/tracing/decision-trace.js +3 -0
  145. package/dist/types/matcher.d.ts +369 -2
  146. package/dist/types/matcher.d.ts.map +1 -1
  147. package/dist/updates/assignment-update.d.ts +93 -0
  148. package/dist/updates/assignment-update.d.ts.map +1 -0
  149. package/dist/updates/assignment-update.js +91 -0
  150. package/dist/utils/keys.d.ts +10 -0
  151. package/dist/utils/keys.d.ts.map +1 -1
  152. package/dist/utils/keys.js +43 -0
  153. package/package.json +15 -2
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectSpikes = exports.SPIKE_LOOKBACK_DAYS = void 0;
4
+ /**
5
+ * "What was this?" (spec §7.1): recent days far outside what the model
6
+ * expected and that no known event or holiday explains, grouped into spans
7
+ * and broken down by which series moved. Naming one (on the platform) turns it
8
+ * into a past occurrence, which divides it out and teaches its effect.
9
+ *
10
+ * Spans are UTC days: each day's actual is the daily table's, and its
11
+ * expectation is `explainedDay` on the same UTC day — never a local-day sum.
12
+ */
13
+ const days_1 = require("./days");
14
+ const effects_1 = require("./effects");
15
+ const model_1 = require("./model");
16
+ /** How far back spikes are looked for: the hourly table's 16 weeks. */
17
+ exports.SPIKE_LOOKBACK_DAYS = 112;
18
+ /** A series moved with a span when it carries at least this share of the span's excess. */
19
+ const MIN_SHARE = 0.05;
20
+ function detectSpikes(total, others) {
21
+ if (!total.span || total.level <= 0)
22
+ return [];
23
+ const explained = (0, effects_1.specialDays)(total.occurrences);
24
+ const days = [];
25
+ // The first day of history is partial, never a spike.
26
+ const from = Math.max(total.span.to - (exports.SPIKE_LOOKBACK_DAYS - 1), total.span.from + 1);
27
+ for (let day = from; day <= total.span.to; day++) {
28
+ if (explained.has(day))
29
+ continue;
30
+ const expected = (0, model_1.explainedDay)(total, day);
31
+ const actual = (0, model_1.actualOn)(total, day) ?? 0;
32
+ if (!(0, model_1.isOutlier)(actual, expected))
33
+ continue;
34
+ days.push({ day, actual, expected, direction: actual > expected ? 'up' : 'down' });
35
+ }
36
+ const spans = [];
37
+ for (const day of days) {
38
+ const last = spans[spans.length - 1];
39
+ const prev = last?.[last.length - 1];
40
+ // One quiet day in between does not split a span.
41
+ if (prev && prev.direction === day.direction && day.day - prev.day <= 2)
42
+ last.push(day);
43
+ else
44
+ spans.push([day]);
45
+ }
46
+ return spans.map((span) => {
47
+ const excess = span.reduce((s, d) => s + d.actual - d.expected, 0);
48
+ const ratios = span.map((d) => d.actual / d.expected);
49
+ const direction = span[0].direction;
50
+ const bySeries = others
51
+ .map((model) => ({
52
+ series: model.series,
53
+ excess: span.reduce((s, d) => s + ((0, model_1.actualOn)(model, d.day) ?? 0) - (0, model_1.explainedDay)(model, d.day), 0),
54
+ }))
55
+ .filter((s) => excess !== 0 && s.excess / excess >= MIN_SHARE)
56
+ .sort((a, b) => Math.abs(b.excess) - Math.abs(a.excess))
57
+ .slice(0, 5)
58
+ .map((s) => ({
59
+ series: s.series,
60
+ excess: Math.round(s.excess * 10) / 10,
61
+ share: Math.round((s.excess / excess) * 100) / 100,
62
+ }));
63
+ return {
64
+ from: (0, days_1.dateOf)(span[0].day),
65
+ to: (0, days_1.dateOf)(span[span.length - 1].day),
66
+ direction,
67
+ excess: Math.round(excess * 10) / 10,
68
+ peakRatio: Math.round((direction === 'up' ? Math.max(...ratios) : Math.min(...ratios)) * 100) / 100,
69
+ bySeries,
70
+ };
71
+ });
72
+ }
73
+ exports.detectSpikes = detectSpikes;
@@ -0,0 +1,64 @@
1
+ import { type SimWindow } from './simulation';
2
+ import type { PoolMember, StaffingInterval, StaffingOptions, StaffingResult, TagProfile } from './types';
3
+ export declare const DEFAULT_SEEDS = 20;
4
+ export declare const DEFAULT_OVERDISPERSION = 20;
5
+ export declare const DEFAULT_QUANTIZE = 0.05;
6
+ export declare const DEFAULT_MAX_PEOPLE = 500;
7
+ /**
8
+ * The staffing run's wall-clock budget scales with volume: `baseMs` per `perPeakRate` arrivals an hour at
9
+ * the peak, never under `baseMs` and never over `maxMs`. Simulation cost grows with the tasks simulated, so
10
+ * a fixed budget would skip the busiest workspaces' hours.
11
+ */
12
+ export declare const STAFFING_BUDGET: {
13
+ readonly baseMs: 6000;
14
+ readonly perPeakRate: 300;
15
+ readonly maxMs: 20000;
16
+ };
17
+ /** `budgetMs` for a run whose busiest interval brings `peakPerHour` arrivals an hour over all tags. */
18
+ export declare function staffingBudgetMs(peakPerHour: number): number;
19
+ /** Arrivals rounded onto a relative grid, so hours with near-identical load share one simulation. */
20
+ export declare function quantize(value: number, step?: number): number;
21
+ /**
22
+ * Who is on for a head count of `n`. Heads follow the work, not the pool's mix:
23
+ *
24
+ * 1. Every busy tag somebody can take gets one person first (rarest tag first): nobody rosters ten people
25
+ * to get the one German speaker.
26
+ * 2. Then each next head goes to the worst-served tag — the one with the largest `shortfall(tag, heads it
27
+ * has)`; by default `1 − heads ÷ load`, and in `staffingNeed` the Erlang A service level it would have
28
+ * on its own against its target, so a small tag gets the second person it needs instead of a share.
29
+ *
30
+ * A head for a tag goes to a profile that covers it: one the pool still has people of first; among
31
+ * those, the one whose head makes the most progress towards the targets of all the short tags it covers
32
+ * (so a generalist goes where two queues are short), a specialist on a tie (generalists are kept for work
33
+ * only they can take), then the one with the most people left. A rare skill is still protected: its tag
34
+ * becomes the most short, and only its coverers can take that head.
35
+ * Past the declared pool, the head still goes to the tag that needs it, so `team[p]` can exceed
36
+ * `counts[p]` — the people to hire; `staffingNeed` reports it as `exceedsPool`. Without any work the
37
+ * pool's own mix is used.
38
+ */
39
+ export declare function composeTeam(n: number, pool: readonly Float64Array[], counts: readonly number[], load: ArrayLike<number>, shortfall?: (tag: number, heads: number) => number): number[];
40
+ /**
41
+ * The simulated span around one interval: a warm-up of three mean handle times (15–240 min), the
42
+ * interval, and a tail as long as the longest target, so the interval's last arrivals are judged on
43
+ * their whole wait — the run ends at target + interval length.
44
+ */
45
+ export declare function windowFor(tags: readonly TagProfile[], intervalMinutes?: number): SimWindow;
46
+ /** A target this long, or this many handle times, makes a tag's queue outlive its hour: chain the hours. */
47
+ export declare const CARRY_TARGET_MS: number;
48
+ export declare const CARRY_TARGET_HANDLES = 2;
49
+ /**
50
+ * Seeds for a chained hour whose work is mostly inherited backlog (carried-in work ≥ half the hour's), and
51
+ * for the two hours before it that built the backlog (re-read when the backlog shows): its service level
52
+ * hangs on rare big-backlog days, which twenty seeds mostly miss. No adaptive stop for them.
53
+ */
54
+ export declare const BACKLOG_SEEDS = 80;
55
+ /** Seeds every load gets before the adaptive stop may end it early. */
56
+ export declare const MIN_SEEDS = 8;
57
+ /** Stop drawing seeds once every judged tag's pooled service level is known to ±this (95 %). */
58
+ export declare const SERVICE_HALF_WIDTH = 0.01;
59
+ export declare function staffingNeed(intervals: readonly StaffingInterval[], tags: readonly TagProfile[], pool: readonly PoolMember[], options: StaffingOptions): StaffingResult;
60
+ /** People on shift for a volume at a fixed rate: units ÷ units per person-hour ÷ (1 − shrinkage), per hour. */
61
+ export declare function rateNeed(unitsPerHour: number, unitsPerPersonHour: number, shrinkage: number): number;
62
+ /** The series already counts people. */
63
+ export declare function headcountNeed(value: number): number;
64
+ //# sourceMappingURL=staffing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staffing.d.ts","sourceRoot":"","sources":["../../src/forecasting/staffing.ts"],"names":[],"mappings":"AAqBA,OAAO,EASH,KAAK,SAAS,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAER,UAAU,EAEV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,UAAU,EACb,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAGtC;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;CAA8D,CAAC;AAE3F,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,qGAAqG;AACrG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAmB,GAAG,MAAM,CAKvE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACvB,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,SAAS,YAAY,EAAE,EAC7B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EACvB,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GACnD,MAAM,EAAE,CA6EV;AAoBD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,EAAE,eAAe,SAAK,GAAG,SAAS,CAOtF;AAED,4GAA4G;AAC5G,eAAO,MAAM,eAAe,QAAc,CAAC;AAC3C,eAAO,MAAM,oBAAoB,IAAI,CAAC;AA2ItC;;;;GAIG;AACH,eAAO,MAAM,aAAa,KAAK,CAAC;AAIhC,uEAAuE;AACvE,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,gGAAgG;AAChG,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAmCvC,wBAAgB,YAAY,CACxB,SAAS,EAAE,SAAS,gBAAgB,EAAE,EACtC,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,OAAO,EAAE,eAAe,GACzB,cAAc,CAyZhB;AAaD,+GAA+G;AAC/G,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIpG;AAED,wCAAwC;AACxC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}