updatess on the ui changs
This commit is contained in:
46
src/utils/batchBucket.js
Normal file
46
src/utils/batchBucket.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { parseDoormileTimestamp } from './doormileTimestamp';
|
||||
|
||||
// Canonical Morning/Afternoon/Evening wave definitions — extracted verbatim
|
||||
// from Dispatch.js's BATCHES_DEFAULT_RAW / getBatchForHour / getRowBatch (see
|
||||
// dispatch/CLAUDE.md §1, "Batch / wave model"). deliveries.js mirrors the
|
||||
// same ranges under its own BATCH_OPTIONS/getRowBatchId. This module exists
|
||||
// so a THIRD consumer (the operator bot) doesn't grow a fourth copy that can
|
||||
// drift from the other two — Dispatch.js and deliveries.js are NOT migrated
|
||||
// to import this (dispatch/CLAUDE.md is explicit that folder isn't touched
|
||||
// casually); this is purely additive.
|
||||
//
|
||||
// Half-open [startHour, endHour) ranges in LOCAL time. Gaps (8–9am,
|
||||
// 12:30pm–4pm, after 7pm) are intentional — a row in a gap belongs to no
|
||||
// batch, not the nearest one.
|
||||
export const BATCHES = [
|
||||
{ id: 'morning', label: 'Morning Batch', startHour: 0, endHour: 8 },
|
||||
{ id: 'afternoon', label: 'Afternoon Batch', startHour: 9, endHour: 12.5 },
|
||||
{ id: 'evening', label: 'Evening Batch', startHour: 16, endHour: 19 }
|
||||
];
|
||||
|
||||
export const getBatchForHour = (h) => {
|
||||
for (const b of BATCHES) {
|
||||
if (h >= b.startHour && h < b.endHour) return b.id;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// The one field batch bucketing uses across the app: a booking's `orderdate`
|
||||
// (== createdat — see fetchDeliveries in api.js). `assigntime` and
|
||||
// `expecteddeliverytime` were both tried and rejected — see dispatch/
|
||||
// CLAUDE.md §1's table for why. Don't bucket on either here either.
|
||||
export const getRowBatchId = (row) => {
|
||||
const t = row?.orderdate;
|
||||
if (!t) return null;
|
||||
const str = String(t).trim();
|
||||
// Skip bare date strings — no time component, would always parse to midnight.
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(str)) return null;
|
||||
const d = parseDoormileTimestamp(t);
|
||||
if (!d.isValid()) return null;
|
||||
// Fractional hour so e.g. 12:45 falls into the slot starting at 12.5, not
|
||||
// the one starting at 12 — d.hour() alone truncates and mis-buckets the
|
||||
// back half of every hour.
|
||||
return getBatchForHour(d.hour() + d.minute() / 60);
|
||||
};
|
||||
|
||||
export const getBatchLabel = (batchId) => BATCHES.find((b) => b.id === batchId)?.label || batchId;
|
||||
@@ -17,6 +17,7 @@
|
||||
"profitability": "Profitability",
|
||||
"dispatch": "Dispatch",
|
||||
"customers": "Customers",
|
||||
"assistant": "Assistant",
|
||||
"fleetops": "Fleet & Ops",
|
||||
"hubs": "Hubs",
|
||||
"vehicles": "Vehicles",
|
||||
|
||||
Reference in New Issue
Block a user