Spaces:
Sleeping
Sleeping
Download backend/seed-data.js from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 12.1 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/seed-data.js
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/backend/seed-data.js
-
curl -L -o seed-data.js https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/seed-data.js
12.1 kB
| const mongoose = require('mongoose'); | |
| const { faker } = require('@faker-js/faker'); | |
| require('dotenv').config(); | |
| // MongoDB connection | |
| const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/uga_chatbot'; | |
| // UGA-specific data arrays | |
| const ugaColleges = [ | |
| 'Franklin College of Arts & Sciences', | |
| 'Terry College of Business', | |
| 'College of Engineering', | |
| 'College of Education', | |
| 'College of Agricultural & Environmental Sciences', | |
| 'College of Family & Consumer Sciences', | |
| 'School of Law', | |
| 'College of Veterinary Medicine', | |
| 'College of Pharmacy', | |
| 'School of Medicine', | |
| 'College of Public Health', | |
| 'Grady College of Journalism & Mass Communication', | |
| 'School of Social Work', | |
| 'School of Nursing' | |
| ]; | |
| const ugaDepartments = { | |
| 'Franklin College of Arts & Sciences': [ | |
| 'Computer Science', 'Mathematics', 'Physics', 'Chemistry', 'Biology', | |
| 'Psychology', 'English', 'History', 'Philosophy', 'Political Science', | |
| 'Anthropology', 'Sociology', 'Art', 'Music', 'Theatre & Film Studies' | |
| ], | |
| 'Terry College of Business': [ | |
| 'Accounting', 'Finance', 'Management', 'Marketing', 'Management Information Systems', | |
| 'Economics', 'International Business', 'Real Estate' | |
| ], | |
| 'College of Engineering': [ | |
| 'Computer Science & Engineering', 'Electrical & Electronic Engineering', | |
| 'Mechanical Engineering', 'Civil Engineering', 'Chemical Engineering', | |
| 'Biomedical Engineering', 'Environmental Engineering' | |
| ], | |
| 'College of Education': [ | |
| 'Educational Psychology', 'Elementary Education', 'Secondary Education', | |
| 'Special Education', 'Educational Leadership', 'Kinesiology' | |
| ] | |
| }; | |
| const ugaMajors = [ | |
| 'Computer Science', 'Business Administration', 'Biology', 'Psychology', | |
| 'Engineering', 'Education', 'Pre-Med', 'English', 'History', 'Mathematics', | |
| 'Chemistry', 'Physics', 'Political Science', 'Marketing', 'Finance', | |
| 'Accounting', 'Journalism', 'Art', 'Music', 'Theatre', 'Philosophy', | |
| 'Anthropology', 'Sociology', 'International Affairs', 'Public Relations', | |
| 'Agricultural Engineering', 'Veterinary Medicine', 'Pharmacy', 'Nursing', | |
| 'Public Health', 'Social Work', 'Law', 'Medicine' | |
| ]; | |
| const ugaCampusBuildings = [ | |
| 'Miller Learning Center', 'Tate Student Center', 'Memorial Hall', 'Old College', | |
| 'Chapel', 'Holmes Hall', 'Boyd Graduate Studies Research Center', | |
| 'Science Learning Center', 'Zell B. Miller Learning Center', 'Russell Special Collections Building', | |
| 'Terry College of Business Complex', 'Engineering Building', 'Pharmacy Building', | |
| 'Veterinary Medicine Complex', 'Tifton Campus', 'Griffin Campus', 'Gwinnett Campus', | |
| 'Joe Frank Harris Commons', 'Bolton Dining Commons', 'Snelling Dining Commons', | |
| 'Village Summit', 'East Campus Village', 'University Village', 'Reed Hall', | |
| 'Creswell Hall', 'Russell Hall', 'Brumby Hall', 'O-House', 'Boggs Hall' | |
| ]; | |
| const ugaServices = [ | |
| 'Academic Advising', 'Career Center', 'Counseling & Psychiatric Services', | |
| 'Disability Resource Center', 'Financial Aid', 'Registrar', 'Bursar', | |
| 'UGA Card Services', 'Transportation & Parking', 'Dining Services', | |
| 'Housing', 'Health Center', 'Recreation Centers', 'Libraries', | |
| 'Student Activities', 'Greek Life', 'International Education' | |
| ]; | |
| // Schema definitions | |
| const CourseSchema = new mongoose.Schema({ | |
| courseCode: String, | |
| title: String, | |
| description: String, | |
| credits: Number, | |
| college: String, | |
| department: String, | |
| semester: String, | |
| instructor: String, | |
| capacity: Number, | |
| enrolled: Number, | |
| prerequisites: [String], | |
| schedule: { | |
| days: [String], | |
| time: String, | |
| location: String | |
| } | |
| }); | |
| const KnowledgeArticleSchema = new mongoose.Schema({ | |
| title: String, | |
| content: String, | |
| category: String, | |
| tags: [String], | |
| author: String, | |
| publishedAt: Date, | |
| updatedAt: Date, | |
| views: Number, | |
| helpful: Number, | |
| notHelpful: Number | |
| }); | |
| const StudentServiceSchema = new mongoose.Schema({ | |
| name: String, | |
| description: String, | |
| category: String, | |
| location: String, | |
| hours: String, | |
| contact: { | |
| phone: String, | |
| email: String, | |
| website: String | |
| }, | |
| services: [String] | |
| }); | |
| const CampusFacilitySchema = new mongoose.Schema({ | |
| name: String, | |
| type: String, | |
| description: String, | |
| location: { | |
| address: String, | |
| coordinates: [Number] | |
| }, | |
| hours: String, | |
| amenities: [String], | |
| capacity: Number, | |
| accessibility: Boolean | |
| }); | |
| // Create models | |
| const Course = mongoose.model('Course', CourseSchema); | |
| const KnowledgeArticle = mongoose.model('KnowledgeArticle', KnowledgeArticleSchema); | |
| const StudentService = mongoose.model('StudentService', StudentServiceSchema); | |
| const CampusFacility = mongoose.model('CampusFacility', CampusFacilitySchema); | |
| // Generate sample data functions | |
| function generateCourses(count = 1000) { | |
| const courses = []; | |
| const semesters = ['Fall 2024', 'Spring 2025', 'Summer 2025', 'Fall 2025']; | |
| const times = ['8:00-9:15', '9:30-10:45', '11:00-12:15', '12:30-1:45', '2:00-3:15', '3:30-4:45']; | |
| const days = [['MWF'], ['TR'], ['MW'], ['WF'], ['MTWRF']]; | |
| for (let i = 0; i < count; i++) { | |
| const college = faker.helpers.arrayElement(ugaColleges); | |
| const department = faker.helpers.arrayElement(ugaDepartments[college] || ['General Studies']); | |
| const courseNum = faker.number.int({ min: 1000, max: 9999 }); | |
| courses.push({ | |
| courseCode: `${department.replace(/[^A-Z]/g, '').substring(0, 4)}${courseNum}`, | |
| title: faker.lorem.words(3), | |
| description: faker.lorem.paragraph(3), | |
| credits: faker.helpers.arrayElement([1, 2, 3, 4, 5]), | |
| college, | |
| department, | |
| semester: faker.helpers.arrayElement(semesters), | |
| instructor: `Dr. ${faker.person.lastName()}`, | |
| capacity: faker.number.int({ min: 15, max: 300 }), | |
| enrolled: faker.number.int({ min: 5, max: 250 }), | |
| prerequisites: faker.helpers.maybe(() => [ | |
| faker.helpers.arrayElement(ugaMajors) + ' ' + faker.number.int({ min: 1000, max: 3999 }) | |
| ], 0.3) || [], | |
| schedule: { | |
| days: faker.helpers.arrayElement(days), | |
| time: faker.helpers.arrayElement(times), | |
| location: `${faker.helpers.arrayElement(ugaCampusBuildings)} ${faker.number.int({ min: 100, max: 999 })}` | |
| } | |
| }); | |
| } | |
| return courses; | |
| } | |
| function generateKnowledgeArticles(count = 500) { | |
| const articles = []; | |
| const categories = [ | |
| 'Academic Policies', 'Registration', 'Financial Aid', 'Student Life', | |
| 'Campus Resources', 'Technology', 'Housing', 'Dining', 'Transportation', | |
| 'Health & Wellness', 'Career Services', 'International Programs', | |
| 'Research Opportunities', 'Library Services', 'Accessibility Services' | |
| ]; | |
| for (let i = 0; i < count; i++) { | |
| const category = faker.helpers.arrayElement(categories); | |
| articles.push({ | |
| title: faker.lorem.words(5), | |
| content: faker.lorem.paragraphs(faker.number.int({ min: 3, max: 15 }), '\n\n'), | |
| category, | |
| tags: faker.helpers.arrayElements(['uga', 'student', 'academic', 'campus', 'service'], { min: 2, max: 5 }), | |
| author: faker.person.fullName(), | |
| publishedAt: faker.date.past({ years: 2 }), | |
| updatedAt: faker.date.recent({ days: 30 }), | |
| views: faker.number.int({ min: 10, max: 5000 }), | |
| helpful: faker.number.int({ min: 0, max: 100 }), | |
| notHelpful: faker.number.int({ min: 0, max: 20 }) | |
| }); | |
| } | |
| return articles; | |
| } | |
| function generateStudentServices(count = 100) { | |
| const services = []; | |
| const categories = [ | |
| 'Academic Support', 'Financial Services', 'Health & Wellness', | |
| 'Student Life', 'Career Development', 'Technology', 'Administrative' | |
| ]; | |
| for (let i = 0; i < count; i++) { | |
| services.push({ | |
| name: faker.helpers.arrayElement(ugaServices), | |
| description: faker.lorem.paragraph(2), | |
| category: faker.helpers.arrayElement(categories), | |
| location: faker.helpers.arrayElement(ugaCampusBuildings), | |
| hours: 'Monday-Friday 8:00 AM - 5:00 PM', | |
| contact: { | |
| phone: faker.phone.number(), | |
| email: faker.internet.email(), | |
| website: faker.internet.url() | |
| }, | |
| services: faker.helpers.arrayElements([ | |
| 'Consultation', 'Workshops', 'Online Resources', 'Appointment Scheduling', | |
| 'Walk-in Support', 'Emergency Services', 'Group Sessions' | |
| ], { min: 2, max: 5 }) | |
| }); | |
| } | |
| return services; | |
| } | |
| function generateCampusFacilities(count = 200) { | |
| const facilities = []; | |
| const types = [ | |
| 'Academic Building', 'Dining Hall', 'Residence Hall', 'Recreation Center', | |
| 'Library', 'Administrative Building', 'Parking Facility', 'Medical Facility', | |
| 'Student Center', 'Athletic Facility', 'Research Building' | |
| ]; | |
| for (let i = 0; i < count; i++) { | |
| facilities.push({ | |
| name: faker.helpers.arrayElement(ugaCampusBuildings), | |
| type: faker.helpers.arrayElement(types), | |
| description: faker.lorem.paragraph(), | |
| location: { | |
| address: faker.location.streetAddress() + ', Athens, GA 30602', | |
| coordinates: [ | |
| faker.location.longitude({ min: -83.4, max: -83.3 }), | |
| faker.location.latitude({ min: 33.9, max: 34.0 }) | |
| ] | |
| }, | |
| hours: faker.helpers.arrayElement([ | |
| '24/7', 'Monday-Friday 8:00 AM - 5:00 PM', 'Monday-Sunday 6:00 AM - 11:00 PM', | |
| 'Monday-Thursday 7:00 AM - 2:00 AM, Friday-Sunday 7:00 AM - 12:00 AM' | |
| ]), | |
| amenities: faker.helpers.arrayElements([ | |
| 'WiFi', 'Air Conditioning', 'Elevator Access', 'Parking', | |
| 'Restrooms', 'Study Spaces', 'Food Services', 'Computer Lab', | |
| 'Meeting Rooms', 'Accessibility Features', 'Security' | |
| ], { min: 3, max: 8 }), | |
| capacity: faker.number.int({ min: 50, max: 2000 }), | |
| accessibility: faker.datatype.boolean({ probability: 0.9 }) | |
| }); | |
| } | |
| return facilities; | |
| } | |
| async function seedDatabase() { | |
| try { | |
| console.log('Connecting to MongoDB...'); | |
| await mongoose.connect(MONGODB_URI); | |
| console.log('Connected to MongoDB successfully!'); | |
| // Clear existing data | |
| console.log('Clearing existing data...'); | |
| await Course.deleteMany({}); | |
| await KnowledgeArticle.deleteMany({}); | |
| await StudentService.deleteMany({}); | |
| await CampusFacility.deleteMany({}); | |
| console.log('Generating and inserting data...'); | |
| // Generate and insert courses (largest dataset) | |
| console.log('Inserting courses...'); | |
| const courses = generateCourses(2000); | |
| await Course.insertMany(courses, { ordered: false }); | |
| console.log(`Inserted ${courses.length} courses`); | |
| // Generate and insert knowledge articles | |
| console.log('Inserting knowledge articles...'); | |
| const articles = generateKnowledgeArticles(1000); | |
| await KnowledgeArticle.insertMany(articles, { ordered: false }); | |
| console.log(`Inserted ${articles.length} knowledge articles`); | |
| // Generate and insert student services | |
| console.log('Inserting student services...'); | |
| const services = generateStudentServices(200); | |
| await StudentService.insertMany(services, { ordered: false }); | |
| console.log(`Inserted ${services.length} student services`); | |
| // Generate and insert campus facilities | |
| console.log('Inserting campus facilities...'); | |
| const facilities = generateCampusFacilities(500); | |
| await CampusFacility.insertMany(facilities, { ordered: false }); | |
| console.log(`Inserted ${facilities.length} campus facilities`); | |
| // Check database size | |
| const stats = await mongoose.connection.db.stats(); | |
| const sizeInMB = (stats.dataSize / (1024 * 1024)).toFixed(2); | |
| console.log(`\n📊 Database Statistics:`); | |
| console.log(`Total Data Size: ${sizeInMB} MB`); | |
| console.log(`Storage Size: ${(stats.storageSize / (1024 * 1024)).toFixed(2)} MB`); | |
| console.log(`Index Size: ${(stats.indexSize / (1024 * 1024)).toFixed(2)} MB`); | |
| console.log(`Total Collections: ${stats.collections}`); | |
| console.log('\n✅ Database seeding completed successfully!'); | |
| } catch (error) { | |
| console.error('❌ Error seeding database:', error); | |
| } finally { | |
| await mongoose.disconnect(); | |
| console.log('Disconnected from MongoDB'); | |
| } | |
| } | |
| // Run if called directly | |
| if (require.main === module) { | |
| seedDatabase(); | |
| } | |
| module.exports = { seedDatabase }; |