diff --git a/lib/network_interface/api_clients/scheduler_api_client.dart b/lib/network_interface/api_clients/scheduler_api_client.dart index 97fd471..29177c9 100644 --- a/lib/network_interface/api_clients/scheduler_api_client.dart +++ b/lib/network_interface/api_clients/scheduler_api_client.dart @@ -1,4 +1,3 @@ - import 'package:adams_county_scheduler/network_interface/collection_names.dart'; import 'package:adams_county_scheduler/objects/time_session.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; @@ -23,7 +22,7 @@ class SchedulerApiClient { required String session, }) async { DocumentReference ref = - await _firestore.collection(sessionsCollection).add({ + await _firestore.collection(sessionsCollection).add({ 'time': Timestamp.fromDate(time), 'session': session, }); @@ -50,9 +49,9 @@ class SchedulerApiClient { return querySnapshot.docs .map( (doc) => TimeSession.fromJson( - doc.data() as Map, - ), - ) // Assign the document ID to the TimeSession id field + doc.data() as Map, + ), + ) // Assign the document ID to the TimeSession id field .toList(); } @@ -90,15 +89,15 @@ class SchedulerApiClient { // Iterate over the schedules and fill the data for (var career in careers) { - List row = [ - career.excelId.toString(), + List row = [ + career.excelId, career.career, career.room, ]; // Assuming there are always 3 sessions for (int session in career.sessionCounts) { - row.add(session.toString()); + row.add(session); } sheetObject.appendRow(row); @@ -213,7 +212,7 @@ class SchedulerApiClient { if (students.isEmpty) continue; final TimeSession time = times[i]; students.sort( - (a, b) => '${a.lastName}, ${a.firstName}' + (a, b) => '${a.lastName}, ${a.firstName}' .compareTo('${b.lastName}, ${b.firstName}'), ); List rows = []; diff --git a/lib/network_interface/repositories/scheduler/schedule_repository.dart b/lib/network_interface/repositories/scheduler/schedule_repository.dart index 7a9b10a..16e86d2 100644 --- a/lib/network_interface/repositories/scheduler/schedule_repository.dart +++ b/lib/network_interface/repositories/scheduler/schedule_repository.dart @@ -22,13 +22,16 @@ class ScheduleRepository extends BaseScheduleRepository { final Stopwatch stopwatch = Stopwatch(); List classes = []; List studentSchedules = []; + @override Future generateSchedule(bool isAm) async { + classes = []; + studentSchedules = []; debugPrint('Start'); stopwatch.reset(); stopwatch.start(); final String time = isAm ? 'AM' : 'PM'; - + print("TIME: $time"); final List careers = await _getAllCareers(); debugPrint( 'Done downloading careers: ${stopwatch.elapsedMilliseconds} ms in', @@ -40,13 +43,14 @@ class ScheduleRepository extends BaseScheduleRepository { final Map schoolMap = { for (var school in schools) school.shortName: school, }; - + print(schoolMap); final List unfiltered = await _getAllStudents(); -// Filter students where their school's time matches the `time` variable final List students = unfiltered.where((student) { // Use the student's school field to get the corresponding School object from the map final School? studentSchool = schoolMap[student.school]; - // Check if the school's time matches the specified time + if (studentSchool?.time == time) { + print("Student: ${student.lastName}, School: ${student.school}"); + } return studentSchool?.time == time; }).toList(); debugPrint( @@ -87,7 +91,8 @@ class ScheduleRepository extends BaseScheduleRepository { Future _createInFirebase({ required List careers, - required List timeSessions, required String time, + required List timeSessions, + required String time, }) async { final FirebaseFirestore firestore = FirebaseFirestore.instance; try { @@ -106,7 +111,7 @@ class ScheduleRepository extends BaseScheduleRepository { exportStudentSchedule.add( ExportStudentSchedule( formattedName: - '${schedule.student.lastName}, ${schedule.student.firstName}', + '${schedule.student.lastName}, ${schedule.student.firstName}', school: schedule.student.school, sessions: exportStudentSessions, ), @@ -121,7 +126,7 @@ class ScheduleRepository extends BaseScheduleRepository { List exportCareerSchedule = []; for (Career career in careers) { List sessions = - classes.where((element) => element.career.id == career.id).toList(); + classes.where((element) => element.career.id == career.id).toList(); List counts = [0, 0, 0]; List> students = [[], [], []]; sessions @@ -172,7 +177,6 @@ class ScheduleRepository extends BaseScheduleRepository { debugPrint( 'Done Deleting old generation: ${stopwatch.elapsedMilliseconds} ms in', ); - await _batchUpload(firestore.collection('studentExport'), studentExport); debugPrint('Student Batch Done: ${stopwatch.elapsedMilliseconds} ms in'); await _batchUpload(firestore.collection('careerExport'), careerExport); @@ -181,21 +185,27 @@ class ScheduleRepository extends BaseScheduleRepository { stopwatch.stop(); await _schedulerApiClient.createMasterList( - schedules: exportStudentSchedule, time: time,); + schedules: exportStudentSchedule, + time: time, + ); await _schedulerApiClient.createStudentSchedule( - schedules: exportStudentSchedule, time: time,); + schedules: exportStudentSchedule, + time: time, + ); await _schedulerApiClient.createAttendanceSchedule( careerSessions: exportCareerSchedule, - times: timeSessions, time: time, + times: timeSessions, + time: time, ); await _schedulerApiClient.createCareerCounts( - careers: exportCareerSchedule, time: time,); + careers: exportCareerSchedule, + time: time, + ); } catch (e) { debugPrint('Error with firebase: $e'); } } - Future> _getAllSchools() async => await SchoolsApiClient().loadSchools(); @@ -213,9 +223,9 @@ class ScheduleRepository extends BaseScheduleRepository { } Future _batchUpload( - CollectionReference collection, - List> data, - ) async { + CollectionReference collection, + List> data, + ) async { WriteBatch batch = FirebaseFirestore.instance.batch(); for (var item in data) { DocumentReference docRef = collection.doc(); @@ -234,12 +244,11 @@ class ScheduleRepository extends BaseScheduleRepository { return a.student.firstName.compareTo(b.student.firstName); }); - } void _finalAssignment() { List remainingSchedules = - studentSchedules.where((element) => !element.isFull).toList(); + studentSchedules.where((element) => !element.isFull).toList(); for (StudentSchedule remainingSchedule in remainingSchedules) { while (!remainingSchedule.isFull) { for (ClassSession remainingClass in classes) { @@ -260,7 +269,7 @@ class ScheduleRepository extends BaseScheduleRepository { final List notMin = classes .where( (element) => element.students.length < element.career.minClassSize, - ) + ) .toList(); for (var minClass in notMin) { for (StudentSchedule schedule in studentSchedules) { @@ -274,7 +283,7 @@ class ScheduleRepository extends BaseScheduleRepository { void _secondaryAssignment() { List remainingSchedules = - studentSchedules.where((element) => !element.isFull).toList(); + studentSchedules.where((element) => !element.isFull).toList(); for (StudentSchedule remainingSchedule in remainingSchedules) { while (!remainingSchedule.isFull) { for (ClassSession remainingClass in classes) { @@ -332,10 +341,10 @@ class ScheduleRepository extends BaseScheduleRepository { continue; } final Career career = - careers.firstWhere((element) => element.excelNum == careerPriority); + careers.firstWhere((element) => element.excelNum == careerPriority); final List correspondingClasses = - classes.where((element) => element.career.id == career.id).toList(); + classes.where((element) => element.career.id == career.id).toList(); for (ClassSession correspondingClass in correspondingClasses) { bool sessionAvailable = getSessionAvailable( correspondingClass: correspondingClass, @@ -385,7 +394,7 @@ class ScheduleRepository extends BaseScheduleRepository { required StudentSchedule schedule, }) => !schedule.sessions.any( - (session) => - correspondingClass.timeSession.time == session.timeSession.time, + (session) => + correspondingClass.timeSession.time == session.timeSession.time, ); }