const axios = require('axios'); const logger = require('../utils/logger'); const ugaService = require('./ugaService'); const { redisUtils } = require('../utils/redis'); class FacultyService { constructor() { this.baseUrls = { elc: process.env.ELC_API_URL || 'https://elc.uga.edu/api', athena: process.env.ATHENA_API_URL || 'https://athena.uga.edu/api', facultyPortal: process.env.FACULTY_PORTAL_API || 'https://faculty.uga.edu/api' }; this.cacheTimeout = 300; // 5 minutes } // Class Roster Management async getClassRoster(facultyId, courseId, semester, token) { try { const cacheKey = `roster:${facultyId}:${courseId}:${semester}`; const cached = await redisUtils.get(cacheKey); if (cached) { return { success: true, data: cached }; } // Simulated roster data - would normally come from Athena/eLC API const roster = { courseInfo: { courseId, courseName: 'Introduction to Computer Science', courseCode: 'CSCI 1301', section: '001', semester: semester || 'Fall 2024', credits: 4, meetingTimes: ['MWF 10:00-10:50 AM'], location: 'Boyd GSRC 303', enrollment: { current: 28, capacity: 30, waitlist: 2 } }, students: [ { id: 'stu001', ugaId: '811234567', name: 'John Smith', email: 'jsmith@uga.edu', classification: 'Sophomore', major: 'Computer Science', gpa: 3.45, attendance: { present: 12, absent: 2, excused: 1, percentage: 86.7 }, grades: { assignments: [ { name: 'Assignment 1', score: 95, maxScore: 100 }, { name: 'Midterm Exam', score: 87, maxScore: 100 }, { name: 'Project 1', score: 92, maxScore: 100 } ], currentGrade: 91.3, letterGrade: 'A-' }, participation: 'Excellent', lastLogin: new Date().toISOString() }, { id: 'stu002', ugaId: '811234568', name: 'Sarah Johnson', email: 'sjohnson@uga.edu', classification: 'Junior', major: 'Computer Science', gpa: 3.78, attendance: { present: 14, absent: 1, excused: 0, percentage: 93.3 }, grades: { assignments: [ { name: 'Assignment 1', score: 98, maxScore: 100 }, { name: 'Midterm Exam', score: 94, maxScore: 100 }, { name: 'Project 1', score: 96, maxScore: 100 } ], currentGrade: 96.0, letterGrade: 'A' }, participation: 'Outstanding', lastLogin: new Date().toISOString() }, { id: 'stu003', ugaId: '811234569', name: 'Michael Davis', email: 'mdavis@uga.edu', classification: 'Freshman', major: 'Computer Science', gpa: 2.89, attendance: { present: 10, absent: 4, excused: 1, percentage: 71.4 }, grades: { assignments: [ { name: 'Assignment 1', score: 78, maxScore: 100 }, { name: 'Midterm Exam', score: 72, maxScore: 100 }, { name: 'Project 1', score: 85, maxScore: 100 } ], currentGrade: 78.3, letterGrade: 'C+' }, participation: 'Needs improvement', lastLogin: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString() } ] }; // Cache for 10 minutes await redisUtils.setex(cacheKey, 600, roster); return { success: true, data: roster }; } catch (error) { logger.error('Get class roster error:', error.message); return { success: false, error: 'Unable to fetch class roster' }; } } // Grade Submission async submitGrades(facultyId, courseId, gradeSubmissions, token) { try { const results = []; for (const submission of gradeSubmissions) { const result = await this.processGradeSubmission(submission, courseId, token); results.push(result); } const successCount = results.filter(r => r.success).length; logger.info('Grade submission completed', { facultyId, courseId, totalSubmissions: gradeSubmissions.length, successfulSubmissions: successCount }); return { success: true, data: { totalSubmissions: gradeSubmissions.length, successfulSubmissions: successCount, failedSubmissions: results.length - successCount, results } }; } catch (error) { logger.error('Submit grades error:', error.message); return { success: false, error: 'Failed to submit grades' }; } } async processGradeSubmission(submission, courseId, token) { try { // Simulate grade submission to Athena const success = Math.random() > 0.1; // 90% success rate if (success) { return { studentId: submission.studentId, success: true, message: 'Grade submitted successfully', finalGrade: submission.finalGrade }; } else { return { studentId: submission.studentId, success: false, message: 'Failed to submit grade - system error' }; } } catch (error) { return { studentId: submission.studentId, success: false, message: `Grade submission failed: ${error.message}` }; } } // Student Analytics async getStudentAnalytics(facultyId, courseId, semester, token) { try { const cacheKey = `analytics:${facultyId}:${courseId}:${semester}`; const cached = await redisUtils.get(cacheKey); if (cached) { return { success: true, data: cached }; } const analytics = { courseOverview: { totalStudents: 28, averageGrade: 85.2, gradeDistribution: { 'A': 8, 'B': 12, 'C': 6, 'D': 2, 'F': 0 }, attendanceRate: 83.5, participationRate: 76.8 }, performanceMetrics: { assignmentAverages: [ { name: 'Assignment 1', average: 87.3, submissions: 28 }, { name: 'Midterm Exam', average: 82.1, submissions: 27 }, { name: 'Project 1', average: 89.5, submissions: 26 } ], lowPerformingStudents: [ { name: 'Michael Davis', ugaId: '811234569', currentGrade: 78.3, risk: 'medium' }, { name: 'Emily Wilson', ugaId: '811234570', currentGrade: 65.8, risk: 'high' } ], highPerformingStudents: [ { name: 'Sarah Johnson', ugaId: '811234568', currentGrade: 96.0 }, { name: 'Alex Thompson', ugaId: '811234571', currentGrade: 94.2 } ] }, engagementMetrics: { elcActivity: { averageLogins: 4.2, averageTimeSpent: '2h 15m', resourceViews: 156, forumPosts: 23 }, attendanceTrends: { week1: 96.4, week2: 92.9, week3: 89.3, week4: 85.7, week5: 83.9 } }, recommendations: [ 'Consider additional office hours for students at risk', 'Midterm exam scores suggest need for review session', 'High participation in forum discussions indicates good engagement', 'Attendance is declining - consider attendance policy reminder' ] }; // Cache for 30 minutes await redisUtils.setex(cacheKey, 1800, analytics); return { success: true, data: analytics }; } catch (error) { logger.error('Get student analytics error:', error.message); return { success: false, error: 'Unable to fetch student analytics' }; } } // Course Material Management async getCourseContent(facultyId, courseId, token) { try { const cacheKey = `content:${facultyId}:${courseId}`; const cached = await redisUtils.get(cacheKey); if (cached) { return { success: true, data: cached }; } const content = { syllabus: { lastUpdated: '2024-08-15', sections: [ 'Course Description', 'Learning Objectives', 'Required Materials', 'Grading Policy', 'Schedule', 'Policies' ], status: 'published' }, modules: [ { id: 'mod1', title: 'Introduction to Programming', status: 'published', materials: ['Lecture slides', 'Reading assignment', 'Video lectures'], assignments: ['Assignment 1'], dueDate: '2024-09-15' }, { id: 'mod2', title: 'Variables and Data Types', status: 'published', materials: ['Lecture slides', 'Code examples', 'Practice problems'], assignments: [], dueDate: null }, { id: 'mod3', title: 'Control Structures', status: 'draft', materials: ['Lecture slides (draft)'], assignments: ['Assignment 2'], dueDate: '2024-09-29' } ], assignments: [ { id: 'assign1', title: 'Hello World Program', type: 'Programming', dueDate: '2024-09-15', points: 100, submissions: 26, status: 'published' }, { id: 'assign2', title: 'Loops and Conditionals', type: 'Programming', dueDate: '2024-09-29', points: 150, submissions: 0, status: 'draft' } ], announcements: [ { id: 'ann1', title: 'Midterm Exam Schedule', content: 'The midterm exam will be held on October 15th...', posted: '2024-09-01', priority: 'high' }, { id: 'ann2', title: 'Office Hours Update', content: 'Office hours have been moved to Tuesday 2-4 PM...', posted: '2024-08-28', priority: 'medium' } ] }; // Cache for 15 minutes await redisUtils.setex(cacheKey, 900, content); return { success: true, data: content }; } catch (error) { logger.error('Get course content error:', error.message); return { success: false, error: 'Unable to fetch course content' }; } } // Administrative Tasks async getFacultyDashboard(facultyId, token) { try { const cacheKey = `dashboard:${facultyId}`; const cached = await redisUtils.get(cacheKey); if (cached) { return { success: true, data: cached }; } const dashboard = { summary: { totalCourses: 3, totalStudents: 85, pendingGrades: 12, upcomingDeadlines: 4, unreadMessages: 7 }, courses: [ { id: 'csci1301-001', name: 'CSCI 1301 - Intro to Computer Science I', section: '001', semester: 'Fall 2024', enrollment: 28, recentActivity: 'Assignment 1 submissions', nextDeadline: '2024-09-15' }, { id: 'csci1302-002', name: 'CSCI 1302 - Software Development', section: '002', semester: 'Fall 2024', enrollment: 32, recentActivity: 'Project 2 grades posted', nextDeadline: '2024-09-20' }, { id: 'csci4830-001', name: 'CSCI 4830 - Senior Seminar', section: '001', semester: 'Fall 2024', enrollment: 25, recentActivity: 'Final presentation topics due', nextDeadline: '2024-09-18' } ], recentActivity: [ { action: 'Grade posted', course: 'CSCI 1301', timestamp: new Date().toISOString() }, { action: 'Announcement created', course: 'CSCI 1302', timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString() }, { action: 'Assignment created', course: 'CSCI 4830', timestamp: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString() } ], notifications: [ { type: 'deadline', message: 'Midterm grades due in 3 days', priority: 'high' }, { type: 'system', message: 'eLC maintenance scheduled for Sunday', priority: 'medium' }, { type: 'reminder', message: 'Faculty meeting tomorrow at 2 PM', priority: 'medium' } ] }; // Cache for 5 minutes await redisUtils.setex(cacheKey, 300, dashboard); return { success: true, data: dashboard }; } catch (error) { logger.error('Get faculty dashboard error:', error.message); return { success: false, error: 'Unable to fetch faculty dashboard' }; } } // Faculty Resources async getFacultyResources(facultyId, token) { try { const resources = { teaching: [ { name: 'eLC User Guide', url: 'https://elc.uga.edu/help', type: 'documentation' }, { name: 'Grade Submission Tutorial', url: 'https://athena.uga.edu/help/grades', type: 'tutorial' }, { name: 'Online Teaching Best Practices', url: 'https://ctl.uga.edu/online', type: 'guide' } ], technology: [ { name: 'Zoom for Education', url: 'https://zoom.uga.edu', type: 'tool' }, { name: 'Microsoft Teams', url: 'https://teams.uga.edu', type: 'tool' }, { name: 'UGA WiFi Setup', url: 'https://eits.uga.edu/wifi', type: 'setup' } ], administrative: [ { name: 'Faculty Handbook', url: 'https://provost.uga.edu/handbook', type: 'policy' }, { name: 'Academic Calendar', url: 'https://reg.uga.edu/calendar', type: 'reference' }, { name: 'Course Scheduling', url: 'https://reg.uga.edu/scheduling', type: 'tool' } ], support: [ { name: 'Center for Teaching and Learning', phone: '706-542-1355', type: 'contact' }, { name: 'EITS Help Desk', phone: '706-542-3106', type: 'contact' }, { name: 'Faculty Development', url: 'https://provost.uga.edu/faculty-development', type: 'resource' } ] }; return { success: true, data: resources }; } catch (error) { logger.error('Get faculty resources error:', error.message); return { success: false, error: 'Unable to fetch faculty resources' }; } } } module.exports = new FacultyService();