@burdenoff/microfe-movethewheels 2026.1108.1 → 2026.1108.3
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/dist/components/DocumentsCard.js +183 -55
- package/dist/components/ForecastModelsPanel.js +132 -0
- package/dist/components/UpcomingDemandPanel.js +70 -65
- package/dist/generated/wspace-operations.d.ts +25 -0
- package/dist/generated/wspace-types.d.ts +3301 -144
- package/dist/hooks/useDemandForecast.js +1 -1
- package/dist/hooks/useDocumentExtractions.js +100 -0
- package/dist/hooks/useForecastModelChoices.js +57 -0
- package/dist/movethewheels/components/ForecastModelsPanel.d.ts +4 -0
- package/dist/movethewheels/hooks/useDemandForecast.d.ts +9 -0
- package/dist/movethewheels/hooks/useDocumentExtractions.d.ts +49 -0
- package/dist/movethewheels/hooks/useEntityDocuments.d.ts +5 -5
- package/dist/movethewheels/hooks/useForecastModelChoices.d.ts +34 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/file-search.js +24 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/sigma.js +8 -0
- package/dist/pages/AnalyticsPage.js +83 -81
- package/dist/pages/MultiModalShipmentPage.js +125 -121
- package/dist/pages/RouteDetailsPage.js +212 -207
- package/package.json +1 -1
- package/src/generated/wspace-operations.ts +13 -4
- package/src/generated/wspace-types.ts +3623 -144
- package/src/movethewheels/components/DocumentsCard.tsx +174 -29
- package/src/movethewheels/components/ForecastModelsPanel.tsx +188 -0
- package/src/movethewheels/components/UpcomingDemandPanel.tsx +9 -2
- package/src/movethewheels/hooks/useDemandForecast.ts +13 -0
- package/src/movethewheels/hooks/useDocumentExtractions.ts +246 -0
- package/src/movethewheels/hooks/useEntityDocuments.ts +5 -5
- package/src/movethewheels/hooks/useForecastModelChoices.ts +138 -0
- package/src/movethewheels/pages/AnalyticsPage.tsx +7 -2
- package/src/movethewheels/pages/MultiModalShipmentPage.tsx +2 -0
- package/src/movethewheels/pages/RouteDetailsPage.tsx +2 -0
- package/src/operations/wspace/movethewheels/queries/forecast.graphql +22 -1
|
@@ -2,16 +2,44 @@
|
|
|
2
2
|
* DocumentsCard — reuse of the platform Files module (wspace-files-svc).
|
|
3
3
|
*
|
|
4
4
|
* Lists the real files tagged for a MoveTheWheels entity (vehicle / driver /
|
|
5
|
-
* order) and deep-links to the Files module for uploading
|
|
6
|
-
* MoveTheWheels does not store documents itself — this is
|
|
7
|
-
* reuse.
|
|
8
|
-
*
|
|
5
|
+
* order / shipment / route) and deep-links to the Files module for uploading
|
|
6
|
+
* and managing them. MoveTheWheels does not store documents itself — this is
|
|
7
|
+
* honest cross-module reuse.
|
|
8
|
+
*
|
|
9
|
+
* Freight document intelligence (BOFF-3892): each document can be read by the
|
|
10
|
+
* shared vision model, which PROPOSES typed fields with per-field confidence.
|
|
11
|
+
* Nothing is written until a human accepts a field — extraction proposes, the
|
|
12
|
+
* human disposes. Accepting a POD field advances the shipment through the
|
|
13
|
+
* normal ShipmentService path; accepting invoice fields records a
|
|
14
|
+
* variance comparison on the Finance page; accepting a BOL tracking number
|
|
15
|
+
* updates the shipment. Everything else records human confirmation for the
|
|
16
|
+
* audit trail.
|
|
9
17
|
*/
|
|
10
18
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
19
|
+
import { useState } from 'react';
|
|
20
|
+
import { Check, FileSearch, FileText, ExternalLink, Download, Upload } from 'lucide-react';
|
|
21
|
+
import {
|
|
22
|
+
Badge,
|
|
23
|
+
Button,
|
|
24
|
+
Card,
|
|
25
|
+
CardContent,
|
|
26
|
+
CardHeader,
|
|
27
|
+
CardTitle,
|
|
28
|
+
Input,
|
|
29
|
+
Select,
|
|
30
|
+
SelectContent,
|
|
31
|
+
SelectItem,
|
|
32
|
+
SelectTrigger,
|
|
33
|
+
SelectValue,
|
|
34
|
+
} from './ui';
|
|
13
35
|
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
14
36
|
import { useEntityDocuments, type EntityDocumentType } from '../hooks/useEntityDocuments';
|
|
37
|
+
import {
|
|
38
|
+
DOCUMENT_TYPE_OPTIONS,
|
|
39
|
+
useDocumentExtractions,
|
|
40
|
+
type DocumentExtraction,
|
|
41
|
+
type DocumentType,
|
|
42
|
+
} from '../hooks/useDocumentExtractions';
|
|
15
43
|
import { formatDate } from '../utils/formatters';
|
|
16
44
|
|
|
17
45
|
interface DocumentsCardProps {
|
|
@@ -31,6 +59,123 @@ function formatFileSize(bytes: number): string {
|
|
|
31
59
|
return `${value.toFixed(value >= 10 || unit === 0 ? 0 : 1)} ${units[unit]}`;
|
|
32
60
|
}
|
|
33
61
|
|
|
62
|
+
function statusLabel(status: DocumentExtraction['status']): string {
|
|
63
|
+
if (status === 'APPLIED') return 'Applied';
|
|
64
|
+
if (status === 'PARTIALLY_APPLIED') return 'Partially applied';
|
|
65
|
+
return 'Proposed';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function ExtractionPanel({ fileId }: { fileId: string }) {
|
|
69
|
+
const { extractions, isLoading, error, extracting, extractError, extract, apply } =
|
|
70
|
+
useDocumentExtractions(fileId);
|
|
71
|
+
const [docType, setDocType] = useState<DocumentType>('BILL_OF_LADING');
|
|
72
|
+
const [corrections, setCorrections] = useState<Record<string, string>>({});
|
|
73
|
+
const [applyError, setApplyError] = useState<string | null>(null);
|
|
74
|
+
const latest = extractions[0] ?? null;
|
|
75
|
+
|
|
76
|
+
const acceptField = async (extraction: DocumentExtraction, key: string) => {
|
|
77
|
+
setApplyError(null);
|
|
78
|
+
const corrected = corrections[key]?.trim();
|
|
79
|
+
const correction = corrected ? [{ key, value: corrected }] : null;
|
|
80
|
+
const ok = await apply(extraction.id, [key], correction);
|
|
81
|
+
if (!ok) setApplyError(`Accepting "${key}" failed — refresh and try again`);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div className="mt-2 space-y-2 border-t border-border-seam pt-2">
|
|
86
|
+
<div className="flex items-center gap-2">
|
|
87
|
+
<Select value={docType} onValueChange={(value) => setDocType(value as DocumentType)}>
|
|
88
|
+
<SelectTrigger className="w-40" aria-label="Document type">
|
|
89
|
+
<SelectValue />
|
|
90
|
+
</SelectTrigger>
|
|
91
|
+
<SelectContent>
|
|
92
|
+
{DOCUMENT_TYPE_OPTIONS.map((option) => (
|
|
93
|
+
<SelectItem key={option.value} value={option.value}>
|
|
94
|
+
{option.label}
|
|
95
|
+
</SelectItem>
|
|
96
|
+
))}
|
|
97
|
+
</SelectContent>
|
|
98
|
+
</Select>
|
|
99
|
+
<Button
|
|
100
|
+
variant="outline"
|
|
101
|
+
size="sm"
|
|
102
|
+
disabled={extracting}
|
|
103
|
+
onClick={() => void extract(fileId, docType)}
|
|
104
|
+
>
|
|
105
|
+
<FileSearch size={14} /> {extracting ? 'Reading…' : 'Extract fields'}
|
|
106
|
+
</Button>
|
|
107
|
+
</div>
|
|
108
|
+
{(extractError ?? applyError) && (
|
|
109
|
+
<p className="text-sm text-text-danger">{extractError ?? applyError}</p>
|
|
110
|
+
)}
|
|
111
|
+
{isLoading ? (
|
|
112
|
+
<p className="text-sm text-text-secondary">Loading extraction…</p>
|
|
113
|
+
) : latest ? (
|
|
114
|
+
<div className="space-y-2">
|
|
115
|
+
<div className="flex items-center gap-2 text-sm">
|
|
116
|
+
<Badge variant={latest.status === 'APPLIED' ? 'default' : 'secondary'}>
|
|
117
|
+
{statusLabel(latest.status)}
|
|
118
|
+
</Badge>
|
|
119
|
+
<span className="text-text-secondary">
|
|
120
|
+
{DOCUMENT_TYPE_OPTIONS.find((option) => option.value === latest.docType)?.label} ·{' '}
|
|
121
|
+
{formatDate(latest.createdAt, 'relative')} · {latest.model}
|
|
122
|
+
{latest.costMicroUsd
|
|
123
|
+
? ` · ${(Number(latest.costMicroUsd) / 1_000_000).toFixed(4)} USD`
|
|
124
|
+
: ''}
|
|
125
|
+
</span>
|
|
126
|
+
</div>
|
|
127
|
+
{error && <p className="text-sm text-text-danger">{error}</p>}
|
|
128
|
+
<ul className="space-y-1" key={latest.id}>
|
|
129
|
+
{latest.fields.map((field) => {
|
|
130
|
+
const accepted = latest.acceptedFields.includes(field.key);
|
|
131
|
+
const corrected = corrections[field.key];
|
|
132
|
+
return (
|
|
133
|
+
<li key={field.key} className="flex items-center gap-2 text-sm">
|
|
134
|
+
<span className="w-40 shrink-0 truncate text-text-secondary" title={field.label}>
|
|
135
|
+
{field.label}
|
|
136
|
+
</span>
|
|
137
|
+
<Input
|
|
138
|
+
className="h-7 flex-1"
|
|
139
|
+
defaultValue={corrected ?? field.value ?? ''}
|
|
140
|
+
placeholder="Not shown on document"
|
|
141
|
+
disabled={accepted}
|
|
142
|
+
onChange={(event) =>
|
|
143
|
+
setCorrections((previous) => ({
|
|
144
|
+
...previous,
|
|
145
|
+
[field.key]: event.target.value,
|
|
146
|
+
}))
|
|
147
|
+
}
|
|
148
|
+
/>
|
|
149
|
+
<span className="w-12 shrink-0 text-right text-text-secondary">
|
|
150
|
+
{Math.round(field.confidence * 100)}%
|
|
151
|
+
</span>
|
|
152
|
+
{accepted ? (
|
|
153
|
+
<Badge variant="outline" className="flex items-center gap-1">
|
|
154
|
+
<Check size={12} /> Accepted
|
|
155
|
+
</Badge>
|
|
156
|
+
) : (
|
|
157
|
+
<Button
|
|
158
|
+
variant="ghost"
|
|
159
|
+
size="sm"
|
|
160
|
+
onClick={() => void acceptField(latest, field.key)}
|
|
161
|
+
>
|
|
162
|
+
<Check size={14} /> Accept
|
|
163
|
+
</Button>
|
|
164
|
+
)}
|
|
165
|
+
</li>
|
|
166
|
+
);
|
|
167
|
+
})}
|
|
168
|
+
</ul>
|
|
169
|
+
<p className="text-xs text-text-secondary">
|
|
170
|
+
Accepting writes only what that field maps to — a delivery time closes the shipment,
|
|
171
|
+
invoice lines reconcile on Finance. Editing a value first corrects it on acceptance.
|
|
172
|
+
</p>
|
|
173
|
+
</div>
|
|
174
|
+
) : null}
|
|
175
|
+
</div>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
34
179
|
export function DocumentsCard({ entityType, entityId }: DocumentsCardProps) {
|
|
35
180
|
const { navigate } = useMoveTheWheels();
|
|
36
181
|
const { documents, hasMore, isLoading, loadMore } = useEntityDocuments(entityType, entityId);
|
|
@@ -56,30 +201,30 @@ export function DocumentsCard({ entityType, entityId }: DocumentsCardProps) {
|
|
|
56
201
|
) : documents.length > 0 ? (
|
|
57
202
|
<div className="space-y-3">
|
|
58
203
|
{documents.map((doc) => (
|
|
59
|
-
<div
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
204
|
+
<div key={doc.id} className="p-3 border rounded-lg">
|
|
205
|
+
<div className="flex items-center justify-between gap-3">
|
|
206
|
+
<div className="min-w-0">
|
|
207
|
+
<p className="font-medium truncate">{doc.name}</p>
|
|
208
|
+
<p className="text-sm text-text-secondary">
|
|
209
|
+
{formatFileSize(doc.size)} · {formatDate(doc.createdAt, 'relative')}
|
|
210
|
+
</p>
|
|
211
|
+
</div>
|
|
212
|
+
{doc.downloadUrl ? (
|
|
213
|
+
<a
|
|
214
|
+
href={doc.downloadUrl}
|
|
215
|
+
target="_blank"
|
|
216
|
+
rel="noopener noreferrer"
|
|
217
|
+
className="shrink-0 inline-flex items-center gap-1 text-sm text-primary hover:underline"
|
|
218
|
+
>
|
|
219
|
+
<Download size={14} /> Open
|
|
220
|
+
</a>
|
|
221
|
+
) : (
|
|
222
|
+
<Button variant="ghost" size="sm" onClick={openFiles}>
|
|
223
|
+
<ExternalLink size={14} /> View
|
|
224
|
+
</Button>
|
|
225
|
+
)}
|
|
68
226
|
</div>
|
|
69
|
-
{doc.
|
|
70
|
-
<a
|
|
71
|
-
href={doc.downloadUrl}
|
|
72
|
-
target="_blank"
|
|
73
|
-
rel="noopener noreferrer"
|
|
74
|
-
className="shrink-0 inline-flex items-center gap-1 text-sm text-primary hover:underline"
|
|
75
|
-
>
|
|
76
|
-
<Download size={14} /> Open
|
|
77
|
-
</a>
|
|
78
|
-
) : (
|
|
79
|
-
<Button variant="ghost" size="sm" onClick={openFiles}>
|
|
80
|
-
<ExternalLink size={14} /> View
|
|
81
|
-
</Button>
|
|
82
|
-
)}
|
|
227
|
+
<ExtractionPanel fileId={doc.id} />
|
|
83
228
|
</div>
|
|
84
229
|
))}
|
|
85
230
|
{hasMore && (
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ForecastModelsPanel
|
|
3
|
+
*
|
|
4
|
+
* Supply-chain planning v3 (BOFF-10925): which model forecasts each lane and
|
|
5
|
+
* customer, and why. A lane or customer with 26 closed weeks of history is
|
|
6
|
+
* back-tested with the moving-average heuristic, Holt linear and Holt-Winters
|
|
7
|
+
* exponential smoothing; the one with the lowest error (MAPE) on the last
|
|
8
|
+
* closed weeks produces its forecast. Shorter histories keep the heuristic.
|
|
9
|
+
*
|
|
10
|
+
* Read-only: the choices are recorded by each forecast recalculation.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useState } from 'react';
|
|
14
|
+
import { Sigma } from 'lucide-react';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
Badge,
|
|
18
|
+
Card,
|
|
19
|
+
CardContent,
|
|
20
|
+
CardDescription,
|
|
21
|
+
CardHeader,
|
|
22
|
+
CardTitle,
|
|
23
|
+
Skeleton,
|
|
24
|
+
Table,
|
|
25
|
+
TableBody,
|
|
26
|
+
TableCell,
|
|
27
|
+
TableHead,
|
|
28
|
+
TableHeader,
|
|
29
|
+
TableRow,
|
|
30
|
+
Tabs,
|
|
31
|
+
TabsContent,
|
|
32
|
+
TabsList,
|
|
33
|
+
TabsTrigger,
|
|
34
|
+
} from './ui';
|
|
35
|
+
import type { DemandForecastModel } from '../hooks/useDemandForecast';
|
|
36
|
+
import {
|
|
37
|
+
useForecastModelChoices,
|
|
38
|
+
type ForecastModelChoice,
|
|
39
|
+
type ForecastModelScore,
|
|
40
|
+
} from '../hooks/useForecastModelChoices';
|
|
41
|
+
|
|
42
|
+
/** Short display name of a forecast model. */
|
|
43
|
+
export const forecastModelLabel = (
|
|
44
|
+
model: DemandForecastModel,
|
|
45
|
+
seasonLengthWeeks?: number | null
|
|
46
|
+
): string => {
|
|
47
|
+
switch (model) {
|
|
48
|
+
case 'HOLT_LINEAR':
|
|
49
|
+
return 'Holt (trend)';
|
|
50
|
+
case 'HOLT_WINTERS':
|
|
51
|
+
return seasonLengthWeeks
|
|
52
|
+
? `Holt-Winters (${seasonLengthWeeks}-week cycle)`
|
|
53
|
+
: 'Holt-Winters (seasonal)';
|
|
54
|
+
// HEURISTIC_GROWTH_RATE is reserved and never produced; the API documents
|
|
55
|
+
// it as the moving-average heuristic, so it is labelled the same way.
|
|
56
|
+
case 'HEURISTIC_MOVING_AVG':
|
|
57
|
+
case 'HEURISTIC_GROWTH_RATE':
|
|
58
|
+
return 'Moving average';
|
|
59
|
+
default: {
|
|
60
|
+
// Exhaustive over the schema enum: a new model fails the type check here.
|
|
61
|
+
const unknownModel: never = model;
|
|
62
|
+
return String(unknownModel);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const formatMape = (mape: number | null): string =>
|
|
68
|
+
mape === null ? '—' : `${Math.round(mape * 1000) / 10}%`;
|
|
69
|
+
|
|
70
|
+
const scoreFor = (
|
|
71
|
+
choice: ForecastModelChoice,
|
|
72
|
+
model: DemandForecastModel
|
|
73
|
+
): ForecastModelScore | undefined => choice.candidates.find((c) => c.model === model);
|
|
74
|
+
|
|
75
|
+
export function ForecastModelsPanel() {
|
|
76
|
+
const { laneChoices, customerChoices, isLoading, error, refetch } = useForecastModelChoices(5);
|
|
77
|
+
const [tab, setTab] = useState<'LANE' | 'CUSTOMER'>('LANE');
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Card data-testid="forecast-models-panel">
|
|
81
|
+
<CardHeader>
|
|
82
|
+
<CardTitle className="flex items-center gap-2">
|
|
83
|
+
<Sigma size={18} aria-hidden="true" />
|
|
84
|
+
Forecast models
|
|
85
|
+
</CardTitle>
|
|
86
|
+
<CardDescription>
|
|
87
|
+
Lanes and customers with 26 closed weeks of history are back-tested on their last 8 closed
|
|
88
|
+
weeks. The model with the lowest error (MAPE) produces the forecast: the moving-average
|
|
89
|
+
heuristic, Holt (trend) or Holt-Winters (seasonal). Shorter histories use the moving
|
|
90
|
+
average.
|
|
91
|
+
</CardDescription>
|
|
92
|
+
</CardHeader>
|
|
93
|
+
<CardContent>
|
|
94
|
+
{error && !isLoading ? (
|
|
95
|
+
<div className="space-y-2 text-sm">
|
|
96
|
+
<p className="text-status-error-text font-medium">Couldn't load forecast models</p>
|
|
97
|
+
<p className="text-text-secondary">{error.message}</p>
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
onClick={refetch}
|
|
101
|
+
className="font-medium text-primary hover:underline"
|
|
102
|
+
>
|
|
103
|
+
Retry
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
) : isLoading ? (
|
|
107
|
+
<div className="space-y-3">
|
|
108
|
+
<Skeleton className="h-10 w-full" />
|
|
109
|
+
<Skeleton className="h-10 w-full" />
|
|
110
|
+
</div>
|
|
111
|
+
) : (
|
|
112
|
+
<Tabs value={tab} onValueChange={(value) => setTab(value as 'LANE' | 'CUSTOMER')}>
|
|
113
|
+
<TabsList>
|
|
114
|
+
<TabsTrigger value="LANE">Lanes</TabsTrigger>
|
|
115
|
+
<TabsTrigger value="CUSTOMER">Customers</TabsTrigger>
|
|
116
|
+
</TabsList>
|
|
117
|
+
<TabsContent value="LANE">
|
|
118
|
+
<ChoiceTable choices={laneChoices} nameHeader="Lane" />
|
|
119
|
+
</TabsContent>
|
|
120
|
+
<TabsContent value="CUSTOMER">
|
|
121
|
+
<ChoiceTable choices={customerChoices} nameHeader="Customer" />
|
|
122
|
+
</TabsContent>
|
|
123
|
+
</Tabs>
|
|
124
|
+
)}
|
|
125
|
+
</CardContent>
|
|
126
|
+
</Card>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface ChoiceTableProps {
|
|
131
|
+
choices: ForecastModelChoice[];
|
|
132
|
+
nameHeader: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function ChoiceTable({ choices, nameHeader }: ChoiceTableProps) {
|
|
136
|
+
if (choices.length === 0) {
|
|
137
|
+
return (
|
|
138
|
+
<p className="py-4 text-sm text-text-secondary">
|
|
139
|
+
No forecasts yet. Model choices appear after the first forecast recalculation.
|
|
140
|
+
</p>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return (
|
|
144
|
+
<div className="overflow-x-auto">
|
|
145
|
+
<Table>
|
|
146
|
+
<TableHeader>
|
|
147
|
+
<TableRow>
|
|
148
|
+
<TableHead>{nameHeader}</TableHead>
|
|
149
|
+
<TableHead className="text-right">History</TableHead>
|
|
150
|
+
<TableHead>Model</TableHead>
|
|
151
|
+
<TableHead className="text-right">Model error</TableHead>
|
|
152
|
+
<TableHead className="text-right">Moving-average error</TableHead>
|
|
153
|
+
</TableRow>
|
|
154
|
+
</TableHeader>
|
|
155
|
+
<TableBody>
|
|
156
|
+
{choices.map((choice) => {
|
|
157
|
+
const selected = choice.candidates.find((c) => c.selected);
|
|
158
|
+
const heuristic = scoreFor(choice, 'HEURISTIC_MOVING_AVG');
|
|
159
|
+
return (
|
|
160
|
+
<TableRow key={`${choice.scopeType}-${choice.scopeKey}`}>
|
|
161
|
+
<TableCell className="max-w-[16rem]">
|
|
162
|
+
<p className="truncate font-medium" title={choice.scopeLabel}>
|
|
163
|
+
{choice.scopeLabel}
|
|
164
|
+
</p>
|
|
165
|
+
<p className="text-xs text-text-secondary whitespace-normal">{choice.reason}</p>
|
|
166
|
+
</TableCell>
|
|
167
|
+
<TableCell className="text-right whitespace-nowrap">
|
|
168
|
+
{choice.historyWeeks} wk
|
|
169
|
+
</TableCell>
|
|
170
|
+
<TableCell>
|
|
171
|
+
<Badge
|
|
172
|
+
variant={
|
|
173
|
+
choice.selectedModel === 'HEURISTIC_MOVING_AVG' ? 'outline' : 'default'
|
|
174
|
+
}
|
|
175
|
+
>
|
|
176
|
+
{forecastModelLabel(choice.selectedModel, selected?.seasonLengthWeeks)}
|
|
177
|
+
</Badge>
|
|
178
|
+
</TableCell>
|
|
179
|
+
<TableCell className="text-right">{formatMape(selected?.mape ?? null)}</TableCell>
|
|
180
|
+
<TableCell className="text-right">{formatMape(heuristic?.mape ?? null)}</TableCell>
|
|
181
|
+
</TableRow>
|
|
182
|
+
);
|
|
183
|
+
})}
|
|
184
|
+
</TableBody>
|
|
185
|
+
</Table>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* UpcomingDemandPanel
|
|
3
3
|
*
|
|
4
4
|
* Surfaces next-week demand forecasts by lane / customer alongside the
|
|
5
|
-
* most recent closed-period variance (BOFF-4393)
|
|
5
|
+
* most recent closed-period variance (BOFF-4393), naming the model behind
|
|
6
|
+
* the headline row (BOFF-10925). Pure read-side view
|
|
6
7
|
* over `wspace-movethewheels-svc`'s DemandForecast surface.
|
|
7
8
|
*
|
|
8
9
|
* "Next week" is the first forecast week that has not begun yet: the current
|
|
@@ -16,6 +17,7 @@ import { Calendar, TrendingUp, TrendingDown, AlertCircle } from 'lucide-react';
|
|
|
16
17
|
import { Card, CardContent, CardHeader, CardTitle, Skeleton } from './ui';
|
|
17
18
|
import { formatCurrency } from '../utils/formatters';
|
|
18
19
|
|
|
20
|
+
import { forecastModelLabel } from './ForecastModelsPanel';
|
|
19
21
|
import type { ForecastPoint, ForecastVariance } from '../hooks/useDemandForecast';
|
|
20
22
|
|
|
21
23
|
interface UpcomingDemandPanelProps {
|
|
@@ -181,8 +183,13 @@ export function UpcomingDemandPanel({
|
|
|
181
183
|
<p className="text-xs uppercase tracking-wide text-text-secondary">{totalLabel}</p>
|
|
182
184
|
<p className="text-2xl font-bold">{total}</p>
|
|
183
185
|
</div>
|
|
184
|
-
<p className="text-xs text-text-secondary">
|
|
186
|
+
<p className="text-xs text-text-secondary text-right">
|
|
185
187
|
{headlineRow ? formatConfidence(headlineRow.confidence) : ''}
|
|
188
|
+
{headlineRow ? (
|
|
189
|
+
<span className="block" data-testid="upcoming-demand-model">
|
|
190
|
+
{forecastModelLabel(headlineRow.model)}
|
|
191
|
+
</span>
|
|
192
|
+
) : null}
|
|
186
193
|
</p>
|
|
187
194
|
</div>
|
|
188
195
|
|
|
@@ -9,6 +9,15 @@ import { executeGraphQL } from '../utils/graphqlClient';
|
|
|
9
9
|
* admin console exposes `recalculateDemandForecasts` separately.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The forecast model behind a row: the moving-average heuristic, or (once a
|
|
14
|
+
* lane or customer has 26 closed weeks and the model wins the back-test)
|
|
15
|
+
* Holt linear or Holt-Winters exponential smoothing. HEURISTIC_GROWTH_RATE is
|
|
16
|
+
* reserved and never produced.
|
|
17
|
+
*/
|
|
18
|
+
export type DemandForecastModel =
|
|
19
|
+
'HEURISTIC_MOVING_AVG' | 'HEURISTIC_GROWTH_RATE' | 'HOLT_LINEAR' | 'HOLT_WINTERS';
|
|
20
|
+
|
|
12
21
|
export interface ForecastPoint {
|
|
13
22
|
scopeType: 'LANE' | 'CUSTOMER';
|
|
14
23
|
scopeKey: string;
|
|
@@ -21,6 +30,8 @@ export interface ForecastPoint {
|
|
|
21
30
|
actualVolume: number | null;
|
|
22
31
|
actualRevenue: number | null;
|
|
23
32
|
confidence: number;
|
|
33
|
+
/** The model that produced the row (BOFF-10925). */
|
|
34
|
+
model: DemandForecastModel;
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
export interface ForecastVariance {
|
|
@@ -60,6 +71,7 @@ const FORECAST_QUERY = `
|
|
|
60
71
|
actualVolume
|
|
61
72
|
actualRevenue
|
|
62
73
|
confidence
|
|
74
|
+
model
|
|
63
75
|
}
|
|
64
76
|
demandForecastByCustomer(weeks: $weeks) {
|
|
65
77
|
scopeType
|
|
@@ -72,6 +84,7 @@ const FORECAST_QUERY = `
|
|
|
72
84
|
actualVolume
|
|
73
85
|
actualRevenue
|
|
74
86
|
confidence
|
|
87
|
+
model
|
|
75
88
|
}
|
|
76
89
|
laneVariance: demandForecastVariance(scopeType: LANE, limit: $varianceLimit) {
|
|
77
90
|
scopeType
|