Improves CSV data parsing and normalization

Normalizes data from CSV files by mapping sentiment strings to numeric scores and standardizing boolean values.

This change enhances data consistency and accuracy, ensuring reliable data processing for sentiment analysis and boolean evaluations. It also handles multiple languages for sentiment strings.
This commit is contained in:
2025-05-22 00:30:01 +02:00
parent 7479f3ec97
commit 4db0104e2c
2 changed files with 71 additions and 8 deletions

View File

@ -87,17 +87,28 @@ export default async function handler(
data: {
id: sessionData.id,
companyId: sessionData.companyId,
startTime: startTime,
// endTime is required in the schema, so use valid startTime if not available
startTime: startTime,
endTime: endTime,
ipAddress: session.ipAddress || null,
country: session.country || null,
language: session.language || null,
sentiment:
typeof session.sentiment === "number" ? session.sentiment : null,
language: session.language || null,
messagesSent:
typeof session.messagesSent === "number" ? session.messagesSent : 0,
sentiment:
typeof session.sentiment === "number" ? session.sentiment : null,
escalated:
typeof session.escalated === "boolean" ? session.escalated : null,
forwardedHr:
typeof session.forwardedHr === "boolean" ? session.forwardedHr : null,
fullTranscriptUrl: session.fullTranscriptUrl || null,
avgResponseTime:
typeof session.avgResponseTime === "number" ? session.avgResponseTime : null,
tokens:
typeof session.tokens === "number" ? session.tokens : null,
tokensEur:
typeof session.tokensEur === "number" ? session.tokensEur : null,
category: session.category || null,
initialMsg: session.initialMsg || null,
},
});
}