Refactor code for improved readability and consistency

- Updated formatting in SessionDetails component for better readability.
- Enhanced documentation in scheduler-fixes.md to clarify issues and solutions.
- Improved error handling and logging in csvFetcher.js and processingScheduler.js.
- Standardized code formatting across various scripts and components for consistency.
- Added validation checks for CSV URLs and transcript content to prevent processing errors.
- Enhanced logging messages for better tracking of processing status and errors.
This commit is contained in:
Max Kowalski
2025-06-25 17:46:23 +02:00
parent a9e4145001
commit 9e095e1a43
16 changed files with 455 additions and 259 deletions

View File

@ -410,15 +410,19 @@ async function fetchTranscriptContent(url, username, password) {
if (!response.ok) {
// Only log error once per batch, not for every transcript
if (Math.random() < 0.1) { // Log ~10% of errors to avoid spam
console.warn(`[CSV] Transcript fetch failed for ${url}: ${response.status} ${response.statusText}`);
if (Math.random() < 0.1) {
// Log ~10% of errors to avoid spam
console.warn(
`[CSV] Transcript fetch failed for ${url}: ${response.status} ${response.statusText}`
);
}
return null;
}
return await response.text();
} catch (error) {
// Only log error once per batch, not for every transcript
if (Math.random() < 0.1) { // Log ~10% of errors to avoid spam
if (Math.random() < 0.1) {
// Log ~10% of errors to avoid spam
console.warn(`[CSV] Transcript fetch error for ${url}:`, error.message);
}
return null;
@ -505,13 +509,20 @@ export async function fetchAndStoreSessionsForAllCompanies() {
for (const company of companies) {
if (!company.csvUrl) {
console.log(`[Scheduler] Skipping company ${company.id} - no CSV URL configured`);
console.log(
`[Scheduler] Skipping company ${company.id} - no CSV URL configured`
);
continue;
}
// Skip companies with invalid/example URLs
if (company.csvUrl.includes('example.com') || company.csvUrl === 'https://example.com/data.csv') {
console.log(`[Scheduler] Skipping company ${company.id} - invalid/example CSV URL: ${company.csvUrl}`);
if (
company.csvUrl.includes("example.com") ||
company.csvUrl === "https://example.com/data.csv"
) {
console.log(
`[Scheduler] Skipping company ${company.id} - invalid/example CSV URL: ${company.csvUrl}`
);
continue;
}
@ -581,11 +592,17 @@ export async function fetchAndStoreSessionsForAllCompanies() {
country: session.country || null,
language: session.language || null,
messagesSent:
typeof session.messagesSent === "number" ? session.messagesSent : 0,
typeof session.messagesSent === "number"
? session.messagesSent
: 0,
sentiment:
typeof session.sentiment === "number" ? session.sentiment : null,
typeof session.sentiment === "number"
? session.sentiment
: null,
escalated:
typeof session.escalated === "boolean" ? session.escalated : null,
typeof session.escalated === "boolean"
? session.escalated
: null,
forwardedHr:
typeof session.forwardedHr === "boolean"
? session.forwardedHr
@ -596,9 +613,12 @@ export async function fetchAndStoreSessionsForAllCompanies() {
typeof session.avgResponseTime === "number"
? session.avgResponseTime
: null,
tokens: typeof session.tokens === "number" ? session.tokens : null,
tokens:
typeof session.tokens === "number" ? session.tokens : null,
tokensEur:
typeof session.tokensEur === "number" ? session.tokensEur : null,
typeof session.tokensEur === "number"
? session.tokensEur
: null,
category: session.category || null,
initialMsg: session.initialMsg || null,
},
@ -607,9 +627,14 @@ export async function fetchAndStoreSessionsForAllCompanies() {
addedCount++;
}
console.log(`[Scheduler] Added ${addedCount} new sessions for company ${company.id}`);
console.log(
`[Scheduler] Added ${addedCount} new sessions for company ${company.id}`
);
} catch (error) {
console.error(`[Scheduler] Error processing company ${company.id}:`, error);
console.error(
`[Scheduler] Error processing company ${company.id}:`,
error
);
}
}
} catch (error) {