mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 07:32:11 +01:00
Major code quality overhaul addressing 58% of all linting issues: • Type Safety Improvements: - Replace all any types with proper TypeScript interfaces - Fix Map component shadowing (renamed to CountryMap) - Add comprehensive custom error classes system - Enhance API route type safety • Accessibility Enhancements: - Add explicit button types to all interactive elements - Implement useId() hooks for form element accessibility - Add SVG title attributes for screen readers - Fix static element interactions with keyboard handlers • React Best Practices: - Resolve exhaustive dependencies warnings with useCallback - Extract nested component definitions to top level - Fix array index keys with proper unique identifiers - Improve component organization and prop typing • Code Organization: - Automatic import organization and type import optimization - Fix unused function parameters and variables - Enhanced error handling with structured error responses - Improve component reusability and maintainability Results: 248 → 104 total issues (58% reduction) - Fixed all critical type safety and security issues - Enhanced accessibility compliance significantly - Improved code maintainability and performance
137 lines
4.0 KiB
JavaScript
137 lines
4.0 KiB
JavaScript
// Test script for the refactored data processing pipeline
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { processQueuedImports } from "./lib/importProcessor.ts";
|
|
import {
|
|
getAIProcessingCosts,
|
|
processUnprocessedSessions,
|
|
} from "./lib/processingScheduler.ts";
|
|
import { processAllUnparsedTranscripts } from "./lib/transcriptParser.ts";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function testRefactoredPipeline() {
|
|
console.log("🧪 Testing Refactored Data Processing Pipeline\n");
|
|
|
|
// Step 1: Check current state
|
|
console.log("📊 Current Database State:");
|
|
const stats = await getDatabaseStats();
|
|
console.log(stats);
|
|
console.log("");
|
|
|
|
// Step 2: Test import processing (minimal fields only)
|
|
console.log("🔄 Testing Import Processing (Phase 1)...");
|
|
await processQueuedImports(5); // Process 5 imports
|
|
console.log("");
|
|
|
|
// Step 3: Test transcript parsing
|
|
console.log("📝 Testing Transcript Parsing (Phase 2)...");
|
|
await processAllUnparsedTranscripts();
|
|
console.log("");
|
|
|
|
// Step 4: Test AI processing with cost tracking
|
|
console.log("🤖 Testing AI Processing with Cost Tracking (Phase 3)...");
|
|
await processUnprocessedSessions(3, 2); // Process 3 sessions with concurrency 2
|
|
console.log("");
|
|
|
|
// Step 5: Show final results
|
|
console.log("📈 Final Results:");
|
|
const finalStats = await getDatabaseStats();
|
|
console.log(finalStats);
|
|
console.log("");
|
|
|
|
// Step 6: Show AI processing costs
|
|
console.log("💰 AI Processing Costs:");
|
|
const costs = await getAIProcessingCosts();
|
|
console.log(costs);
|
|
console.log("");
|
|
|
|
// Step 7: Show sample processed session
|
|
console.log("🔍 Sample Processed Session:");
|
|
const sampleSession = await getSampleProcessedSession();
|
|
if (sampleSession) {
|
|
console.log(`Session ID: ${sampleSession.id}`);
|
|
console.log(`Language: ${sampleSession.language}`);
|
|
console.log(`Messages Sent: ${sampleSession.messagesSent}`);
|
|
console.log(`Sentiment: ${sampleSession.sentiment}`);
|
|
console.log(`Category: ${sampleSession.category}`);
|
|
console.log(`Escalated: ${sampleSession.escalated}`);
|
|
console.log(`Forwarded HR: ${sampleSession.forwardedHr}`);
|
|
console.log(`Summary: ${sampleSession.summary}`);
|
|
console.log(
|
|
`Questions: ${sampleSession.sessionQuestions.length} questions`
|
|
);
|
|
console.log(
|
|
`AI Requests: ${sampleSession.aiProcessingRequests.length} requests`
|
|
);
|
|
|
|
if (sampleSession.sessionQuestions.length > 0) {
|
|
console.log("Sample Questions:");
|
|
sampleSession.sessionQuestions.slice(0, 3).forEach((sq, i) => {
|
|
console.log(` ${i + 1}. ${sq.question.content}`);
|
|
});
|
|
}
|
|
}
|
|
console.log("");
|
|
|
|
console.log("✅ Pipeline test completed!");
|
|
}
|
|
|
|
async function getDatabaseStats() {
|
|
const [
|
|
totalSessions,
|
|
sessionsWithImports,
|
|
sessionsWithMessages,
|
|
processedSessions,
|
|
totalMessages,
|
|
totalQuestions,
|
|
totalSessionQuestions,
|
|
totalAIRequests,
|
|
] = await Promise.all([
|
|
prisma.session.count(),
|
|
prisma.session.count({ where: { importId: { not: null } } }),
|
|
prisma.session.count({ where: { messages: { some: {} } } }),
|
|
prisma.session.count({ where: { processed: true } }),
|
|
prisma.message.count(),
|
|
prisma.question.count(),
|
|
prisma.sessionQuestion.count(),
|
|
prisma.aIProcessingRequest.count(),
|
|
]);
|
|
|
|
return {
|
|
totalSessions,
|
|
sessionsWithImports,
|
|
sessionsWithMessages,
|
|
processedSessions,
|
|
unprocessedSessions: sessionsWithMessages - processedSessions,
|
|
totalMessages,
|
|
totalQuestions,
|
|
totalSessionQuestions,
|
|
totalAIRequests,
|
|
};
|
|
}
|
|
|
|
async function getSampleProcessedSession() {
|
|
return await prisma.session.findFirst({
|
|
where: {
|
|
processed: true,
|
|
messages: { some: {} },
|
|
},
|
|
include: {
|
|
sessionQuestions: {
|
|
include: {
|
|
question: true,
|
|
},
|
|
orderBy: { order: "asc" },
|
|
},
|
|
aiProcessingRequests: {
|
|
orderBy: { requestedAt: "desc" },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
// Run the test
|
|
testRefactoredPipeline()
|
|
.catch(console.error)
|
|
.finally(() => prisma.$disconnect());
|