Add value distribution to order range dialog
This commit is contained in:
@@ -1654,22 +1654,37 @@ export class EventsService {
|
||||
dayStats.orderValueRange.smallestOrderId = orderId;
|
||||
}
|
||||
|
||||
// Track order value distribution
|
||||
if (totalAmount < 25) {
|
||||
dayStats.orderValueRange.distribution.under25.count++;
|
||||
dayStats.orderValueRange.distribution.under25.total += totalAmount;
|
||||
} else if (totalAmount < 50) {
|
||||
dayStats.orderValueRange.distribution.under50.count++;
|
||||
dayStats.orderValueRange.distribution.under50.total += totalAmount;
|
||||
} else if (totalAmount < 100) {
|
||||
dayStats.orderValueRange.distribution.under100.count++;
|
||||
dayStats.orderValueRange.distribution.under100.total += totalAmount;
|
||||
} else if (totalAmount < 200) {
|
||||
dayStats.orderValueRange.distribution.under200.count++;
|
||||
dayStats.orderValueRange.distribution.under200.total += totalAmount;
|
||||
} else {
|
||||
dayStats.orderValueRange.distribution.over200.count++;
|
||||
dayStats.orderValueRange.distribution.over200.total += totalAmount;
|
||||
// Track order value distribution with more granular ranges
|
||||
const ranges = [
|
||||
{ min: 0, max: 25 },
|
||||
{ min: 25, max: 50 },
|
||||
{ min: 50, max: 75 },
|
||||
{ min: 75, max: 100 },
|
||||
{ min: 100, max: 150 },
|
||||
{ min: 150, max: 200 },
|
||||
{ min: 200, max: 300 },
|
||||
{ min: 300, max: 500 },
|
||||
{ min: 500, max: Infinity }
|
||||
];
|
||||
|
||||
// Initialize distribution if not exists
|
||||
if (!dayStats.orderValueDistribution) {
|
||||
dayStats.orderValueDistribution = ranges.map(range => ({
|
||||
min: range.min,
|
||||
max: range.max === Infinity ? 'Infinity' : range.max,
|
||||
count: 0,
|
||||
total: 0
|
||||
}));
|
||||
}
|
||||
|
||||
// Find the appropriate range and update counts
|
||||
const rangeIndex = ranges.findIndex(range =>
|
||||
totalAmount >= range.min && totalAmount < range.max
|
||||
);
|
||||
|
||||
if (rangeIndex !== -1) {
|
||||
dayStats.orderValueDistribution[rangeIndex].count++;
|
||||
dayStats.orderValueDistribution[rangeIndex].total += totalAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1764,30 +1779,9 @@ export class EventsService {
|
||||
largest: Number(day.orderValueRange?.largest || 0),
|
||||
smallest: Number(day.orderValueRange?.smallest || 0),
|
||||
largestOrderId: day.orderValueRange?.largestOrderId || null,
|
||||
smallestOrderId: day.orderValueRange?.smallestOrderId || null,
|
||||
distribution: {
|
||||
under25: {
|
||||
count: Number(day.orderValueRange?.distribution?.under25?.count || 0),
|
||||
total: Number(day.orderValueRange?.distribution?.under25?.total || 0)
|
||||
},
|
||||
under50: {
|
||||
count: Number(day.orderValueRange?.distribution?.under50?.count || 0),
|
||||
total: Number(day.orderValueRange?.distribution?.under50?.total || 0)
|
||||
},
|
||||
under100: {
|
||||
count: Number(day.orderValueRange?.distribution?.under100?.count || 0),
|
||||
total: Number(day.orderValueRange?.distribution?.under100?.total || 0)
|
||||
},
|
||||
under200: {
|
||||
count: Number(day.orderValueRange?.distribution?.under200?.count || 0),
|
||||
total: Number(day.orderValueRange?.distribution?.under200?.total || 0)
|
||||
},
|
||||
over200: {
|
||||
count: Number(day.orderValueRange?.distribution?.over200?.count || 0),
|
||||
total: Number(day.orderValueRange?.distribution?.over200?.total || 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
smallestOrderId: day.orderValueRange?.smallestOrderId || null
|
||||
},
|
||||
orderValueDistribution: day.orderValueDistribution || []
|
||||
}));
|
||||
|
||||
return stats;
|
||||
|
||||
Reference in New Issue
Block a user