Fix some progress counts sort of
This commit is contained in:
@@ -399,14 +399,14 @@ async function calculateMetrics() {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
let processedCount = processedProducts;
|
let processedCount = processedProducts;
|
||||||
outputProgress({
|
global.outputProgress({
|
||||||
status: 'running',
|
status: 'running',
|
||||||
operation: 'Creating revenue rankings',
|
operation: 'Creating revenue rankings',
|
||||||
current: processedCount,
|
current: processedCount,
|
||||||
total: totalProducts,
|
total: totalProducts,
|
||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: global.formatElapsedTime(startTime),
|
||||||
remaining: estimateRemaining(startTime, processedCount, totalProducts),
|
remaining: global.estimateRemaining(startTime, processedCount, totalProducts),
|
||||||
rate: calculateRate(startTime, processedCount),
|
rate: global.calculateRate(startTime, processedCount),
|
||||||
percentage: ((processedCount / totalProducts) * 100).toFixed(1),
|
percentage: ((processedCount / totalProducts) * 100).toFixed(1),
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
@@ -453,7 +453,7 @@ async function calculateMetrics() {
|
|||||||
// const max_rank = totalCount; // Store max_rank for use in classification
|
// const max_rank = totalCount; // Store max_rank for use in classification
|
||||||
|
|
||||||
// ABC classification progress tracking
|
// ABC classification progress tracking
|
||||||
let abcProcessedCount = 0;
|
// let abcProcessedCount = 0; // No longer needed - use processedProducts directly
|
||||||
const batchSize = 5000;
|
const batchSize = 5000;
|
||||||
let lastProgressUpdate = Date.now();
|
let lastProgressUpdate = Date.now();
|
||||||
const progressUpdateInterval = 1000; // Update every second
|
const progressUpdateInterval = 1000; // Update every second
|
||||||
@@ -501,11 +501,11 @@ async function calculateMetrics() {
|
|||||||
WHERE pm.pid IN (?)
|
WHERE pm.pid IN (?)
|
||||||
`, [abcThresholds.a_threshold, abcThresholds.b_threshold, pids.map(row => row.pid)]);
|
`, [abcThresholds.a_threshold, abcThresholds.b_threshold, pids.map(row => row.pid)]);
|
||||||
|
|
||||||
abcProcessedCount += pids.length; // Use pids.length, more accurate
|
// abcProcessedCount += pids.length; // No longer needed
|
||||||
processedProducts += pids.length; // Add to the main processedProducts
|
processedProducts += pids.length; // Add to the main processedProducts
|
||||||
|
|
||||||
// Calculate progress ensuring valid numbers
|
// Calculate progress ensuring valid numbers
|
||||||
const currentProgress = Math.floor(totalProducts * (0.99 + (abcProcessedCount / (totalProducts || 1)) * 0.01));
|
const currentProgress = Math.floor(totalProducts * (0.99 + (processedProducts / (totalProducts || 1)) * 0.01));
|
||||||
processedProducts = Number(currentProgress) || processedProducts || 0;
|
processedProducts = Number(currentProgress) || processedProducts || 0;
|
||||||
|
|
||||||
// Only update progress at most once per second
|
// Only update progress at most once per second
|
||||||
@@ -513,14 +513,14 @@ async function calculateMetrics() {
|
|||||||
if (now - lastProgressUpdate >= progressUpdateInterval) {
|
if (now - lastProgressUpdate >= progressUpdateInterval) {
|
||||||
const progress = ensureValidProgress(processedProducts, totalProducts);
|
const progress = ensureValidProgress(processedProducts, totalProducts);
|
||||||
|
|
||||||
outputProgress({
|
global.outputProgress({
|
||||||
status: 'running',
|
status: 'running',
|
||||||
operation: 'ABC classification progress',
|
operation: 'ABC classification progress',
|
||||||
current: progress.current,
|
current: progress.current,
|
||||||
total: progress.total,
|
total: progress.total,
|
||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: global.formatElapsedTime(startTime),
|
||||||
remaining: estimateRemaining(startTime, progress.current, progress.total),
|
remaining: global.estimateRemaining(startTime, progress.current, progress.total),
|
||||||
rate: calculateRate(startTime, progress.current),
|
rate: global.calculateRate(startTime, progress.current),
|
||||||
percentage: progress.percentage,
|
percentage: progress.percentage,
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
@@ -556,14 +556,14 @@ async function calculateMetrics() {
|
|||||||
const finalProgress = ensureValidProgress(totalProducts, totalProducts);
|
const finalProgress = ensureValidProgress(totalProducts, totalProducts);
|
||||||
|
|
||||||
// Final success message
|
// Final success message
|
||||||
outputProgress({
|
global.outputProgress({
|
||||||
status: 'complete',
|
status: 'complete',
|
||||||
operation: 'Metrics calculation complete',
|
operation: 'Metrics calculation complete',
|
||||||
current: finalProgress.current,
|
current: finalProgress.current,
|
||||||
total: finalProgress.total,
|
total: finalProgress.total,
|
||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: global.formatElapsedTime(startTime),
|
||||||
remaining: '0s',
|
remaining: '0s',
|
||||||
rate: calculateRate(startTime, finalProgress.current),
|
rate: global.calculateRate(startTime, finalProgress.current),
|
||||||
percentage: '100',
|
percentage: '100',
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ async function calculateProductMetrics(startTime, totalProducts, processedCount
|
|||||||
const SKIP_PRODUCT_TIME_AGGREGATES = 0;
|
const SKIP_PRODUCT_TIME_AGGREGATES = 0;
|
||||||
|
|
||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
outputProgress({
|
global.outputProgress({
|
||||||
status: 'cancelled',
|
status: 'cancelled',
|
||||||
operation: 'Product metrics calculation cancelled',
|
operation: 'Product metrics calculation cancelled',
|
||||||
current: processedCount,
|
current: processedCount,
|
||||||
@@ -276,18 +276,17 @@ async function calculateProductMetrics(startTime, totalProducts, processedCount
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
lastPid = batch[batch.length - 1].pid;
|
lastPid = batch[batch.length - 1].pid;
|
||||||
processedCount += batch.length;
|
|
||||||
myProcessedProducts += batch.length; // Increment the *module's* count
|
myProcessedProducts += batch.length; // Increment the *module's* count
|
||||||
|
|
||||||
outputProgress({
|
outputProgress({
|
||||||
status: 'running',
|
status: 'running',
|
||||||
operation: 'Processing base metrics batch',
|
operation: 'Processing base metrics batch',
|
||||||
current: processedCount,
|
current: processedCount + myProcessedProducts, // Show cumulative progress
|
||||||
total: totalProducts,
|
total: totalProducts,
|
||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: formatElapsedTime(startTime),
|
||||||
remaining: estimateRemaining(startTime, processedCount, totalProducts),
|
remaining: estimateRemaining(startTime, processedCount + myProcessedProducts, totalProducts),
|
||||||
rate: calculateRate(startTime, processedCount),
|
rate: calculateRate(startTime, processedCount + myProcessedProducts),
|
||||||
percentage: ((processedCount / totalProducts) * 100).toFixed(1),
|
percentage: (((processedCount + myProcessedProducts) / totalProducts) * 100).toFixed(1),
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
end_time: new Date().toISOString(),
|
end_time: new Date().toISOString(),
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ async function calculateSalesForecasts(startTime, totalProducts, processedCount
|
|||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: formatElapsedTime(startTime),
|
||||||
remaining: null,
|
remaining: null,
|
||||||
rate: calculateRate(startTime, processedCount),
|
rate: calculateRate(startTime, processedCount),
|
||||||
percentage: ((processedCount / totalProductsToUpdate) * 100).toFixed(1),
|
percentage: ((processedCount / totalProducts) * 100).toFixed(1),
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
end_time: new Date().toISOString(),
|
end_time: new Date().toISOString(),
|
||||||
@@ -261,12 +261,12 @@ async function calculateSalesForecasts(startTime, totalProducts, processedCount
|
|||||||
outputProgress({
|
outputProgress({
|
||||||
status: 'running',
|
status: 'running',
|
||||||
operation: 'Processing sales forecast batch',
|
operation: 'Processing sales forecast batch',
|
||||||
current: processedCount,
|
current: processedCount + myProcessedProducts,
|
||||||
total: totalProducts,
|
total: totalProducts,
|
||||||
elapsed: formatElapsedTime(startTime),
|
elapsed: formatElapsedTime(startTime),
|
||||||
remaining: estimateRemaining(startTime, processedCount, totalProducts),
|
remaining: estimateRemaining(startTime, processedCount + myProcessedProducts, totalProducts),
|
||||||
rate: calculateRate(startTime, processedCount),
|
rate: calculateRate(startTime, processedCount + myProcessedProducts),
|
||||||
percentage: ((processedCount / totalProductsToUpdate) * 100).toFixed(1),
|
percentage: (((processedCount + myProcessedProducts) / totalProducts) * 100).toFixed(1),
|
||||||
timing: {
|
timing: {
|
||||||
start_time: new Date(startTime).toISOString(),
|
start_time: new Date(startTime).toISOString(),
|
||||||
end_time: new Date().toISOString(),
|
end_time: new Date().toISOString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user