move to using /src - still css issue work
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 26s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 26s
This commit is contained in:
44
src/utils/processingTimer.ts
Normal file
44
src/utils/processingTimer.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
const PROCESSING_TIMES_KEY = 'flyerProcessingTimes';
|
||||
const MAX_SAMPLES = 5;
|
||||
|
||||
/**
|
||||
* Records the duration of a flyer processing job in localStorage.
|
||||
* @param durationInSeconds - The processing time in seconds.
|
||||
*/
|
||||
export const recordProcessingTime = (durationInSeconds: number): void => {
|
||||
try {
|
||||
const storedTimes = localStorage.getItem(PROCESSING_TIMES_KEY);
|
||||
const times: number[] = storedTimes ? JSON.parse(storedTimes) : [];
|
||||
|
||||
// Add the new time and keep only the last MAX_SAMPLES
|
||||
times.push(durationInSeconds);
|
||||
const recentTimes = times.slice(-MAX_SAMPLES);
|
||||
|
||||
localStorage.setItem(PROCESSING_TIMES_KEY, JSON.stringify(recentTimes));
|
||||
} catch (error) {
|
||||
console.error("Could not record processing time:", error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the average processing time from stored durations.
|
||||
* @returns The average time in seconds, or a default of 45 seconds if no data exists.
|
||||
*/
|
||||
export const getAverageProcessingTime = (): number => {
|
||||
try {
|
||||
const storedTimes = localStorage.getItem(PROCESSING_TIMES_KEY);
|
||||
if (!storedTimes) return 45; // Default estimate if no history
|
||||
|
||||
const times: number[] = JSON.parse(storedTimes);
|
||||
if (times.length === 0) return 45;
|
||||
|
||||
const sum = times.reduce((acc, time) => acc + time, 0);
|
||||
const average = sum / times.length;
|
||||
|
||||
// Return a rounded, reasonable number
|
||||
return Math.round(average);
|
||||
} catch (error) {
|
||||
console.error("Could not get average processing time:", error);
|
||||
return 45; // Default on error
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user