Spaces:
Sleeping
Sleeping
| const mongoose = require('mongoose'); | |
| const Submission = require('./models/Submission'); | |
| const SourceText = require('./models/SourceText'); | |
| // Connect to MongoDB | |
| mongoose.connect('mongodb://localhost:27017/transcreation-sandbox', { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true, | |
| }); | |
| const sampleTranscreations = [ | |
| "This is a sample transcreation for stress testing", | |
| "Another creative translation approach", | |
| "Cultural adaptation with local flavor", | |
| "Modern interpretation of the source text", | |
| "Traditional approach with contemporary twist", | |
| "Innovative translation strategy", | |
| "Balanced cultural and linguistic adaptation", | |
| "Dynamic transcreation with cultural sensitivity", | |
| "Comprehensive translation solution", | |
| "Strategic cultural adaptation", | |
| "Linguistic excellence with cultural awareness", | |
| "Creative translation methodology", | |
| "Cultural bridge through translation", | |
| "Adaptive translation approach", | |
| "Comprehensive cultural translation" | |
| ]; | |
| const sampleExplanations = [ | |
| "This translation adapts the cultural context while maintaining the original meaning.", | |
| "The transcreation considers local cultural nuances and preferences.", | |
| "Cultural elements have been adapted to resonate with the target audience.", | |
| "This version maintains the essence while adapting to cultural differences.", | |
| "The translation strategy focuses on cultural relevance and accessibility.", | |
| "Adaptive approach that bridges cultural gaps effectively.", | |
| "Cultural sensitivity guides this translation approach.", | |
| "This transcreation balances authenticity with cultural adaptation.", | |
| "Strategic cultural adaptation for maximum impact.", | |
| "Comprehensive approach to cultural translation challenges.", | |
| "Linguistic excellence combined with cultural awareness.", | |
| "Creative methodology for cultural translation.", | |
| "Cultural bridge building through thoughtful translation.", | |
| "Adaptive approach to cultural translation challenges.", | |
| "Comprehensive cultural translation strategy." | |
| ]; | |
| const sampleUsers = [ | |
| { name: "Alice Johnson", role: "student" }, | |
| { name: "Bob Smith", role: "student" }, | |
| { name: "Carol Davis", role: "student" }, | |
| { name: "David Wilson", role: "student" }, | |
| { name: "Eva Brown", role: "student" }, | |
| { name: "Frank Miller", role: "student" }, | |
| { name: "Grace Taylor", role: "student" }, | |
| { name: "Henry Anderson", role: "student" }, | |
| { name: "Ivy Martinez", role: "student" }, | |
| { name: "Jack Thompson", role: "student" }, | |
| { name: "Kate Garcia", role: "student" }, | |
| { name: "Leo Rodriguez", role: "student" }, | |
| { name: "Maya Lee", role: "student" }, | |
| { name: "Noah White", role: "student" }, | |
| { name: "Olivia Clark", role: "student" } | |
| ]; | |
| async function createStressTestData() { | |
| try { | |
| console.log('Starting stress test data creation...'); | |
| // Get all source texts | |
| const sourceTexts = await SourceText.find({}); | |
| console.log(`Found ${sourceTexts.length} source texts`); | |
| let totalSubmissions = 0; | |
| for (const sourceText of sourceTexts) { | |
| console.log(`Adding 15 submissions for source text: ${sourceText.title}`); | |
| for (let i = 0; i < 15; i++) { | |
| const user = sampleUsers[i]; | |
| const transcreation = sampleTranscreations[i]; | |
| const explanation = sampleExplanations[i]; | |
| // Create a consistent ObjectId for the user | |
| const crypto = require('crypto'); | |
| const hash = crypto.createHash('md5').update(user.name).digest('hex'); | |
| const userId = new mongoose.Types.ObjectId(hash.substring(0, 24)); | |
| const submissionData = { | |
| sourceTextId: sourceText._id, | |
| userId: userId, | |
| username: user.name, | |
| groupNumber: sourceText.category === 'tutorial' ? (i % 8) + 1 : undefined, | |
| targetCulture: 'Western', | |
| targetLanguage: 'English', | |
| transcreation: transcreation, | |
| explanation: explanation, | |
| culturalAdaptations: ['Cultural adaptation 1', 'Cultural adaptation 2'], | |
| isAnonymous: Math.random() > 0.5, // Randomly make some anonymous | |
| status: 'submitted', | |
| difficulty: ['beginner', 'intermediate', 'advanced'][Math.floor(Math.random() * 3)], | |
| votes: [], | |
| feedback: [], | |
| score: Math.floor(Math.random() * 100), | |
| createdAt: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000) // Random date within last 30 days | |
| }; | |
| const submission = new Submission(submissionData); | |
| await submission.save(); | |
| totalSubmissions++; | |
| } | |
| } | |
| console.log(`β Successfully created ${totalSubmissions} stress test submissions`); | |
| console.log(`π Total submissions in database: ${await Submission.countDocuments()}`); | |
| } catch (error) { | |
| console.error('β Error creating stress test data:', error); | |
| } finally { | |
| mongoose.connection.close(); | |
| console.log('Database connection closed'); | |
| } | |
| } | |
| // Run the stress test | |
| createStressTestData(); |