Apply gemini suggested calculate improvements

This commit is contained in:
2025-02-10 15:20:22 -05:00
parent 09f7103472
commit 90379386d6
8 changed files with 211 additions and 250 deletions

View File

@@ -5,6 +5,7 @@ async function calculateFinancialMetrics(startTime, totalProducts, processedCoun
const connection = await getConnection();
let success = false;
const BATCH_SIZE = 5000;
let myProcessedProducts = 0; // Track products processed *within this module*
try {
// Get last calculation timestamp
@@ -54,7 +55,7 @@ async function calculateFinancialMetrics(startTime, totalProducts, processedCoun
}
});
return {
processedProducts: processedCount,
processedProducts: myProcessedProducts,
processedOrders: 0,
processedPurchaseOrders: 0,
success
@@ -133,17 +134,17 @@ async function calculateFinancialMetrics(startTime, totalProducts, processedCoun
`, [batch.map(row => row.pid)]);
lastPid = batch[batch.length - 1].pid;
processedCount += batch.length;
myProcessedProducts += batch.length;
outputProgress({
status: 'running',
operation: 'Processing financial metrics batch',
current: processedCount,
current: processedCount + myProcessedProducts,
total: totalProducts,
elapsed: formatElapsedTime(startTime),
remaining: estimateRemaining(startTime, processedCount, totalProducts),
rate: calculateRate(startTime, processedCount),
percentage: ((processedCount / totalProducts) * 100).toFixed(1),
remaining: estimateRemaining(startTime, processedCount + myProcessedProducts, totalProducts),
rate: calculateRate(startTime, processedCount + myProcessedProducts),
percentage: (((processedCount + myProcessedProducts) / totalProducts) * 100).toFixed(1),
timing: {
start_time: new Date(startTime).toISOString(),
end_time: new Date().toISOString(),
@@ -163,7 +164,7 @@ async function calculateFinancialMetrics(startTime, totalProducts, processedCoun
`);
return {
processedProducts: processedCount,
processedProducts: myProcessedProducts,
processedOrders: 0,
processedPurchaseOrders: 0,
success