create basic students to json file function & clean course_selection_data.csv
This commit is contained in:
2 files changed
+49
-7
No files matched your search
@@ -38,7 +38,7 @@ typedef struct {
|
|||||||
int count_lines(char data_dir[]) {
|
int count_lines(char data_dir[]) {
|
||||||
FILE *stream = fopen(data_dir, "r");
|
FILE *stream = fopen(data_dir, "r");
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
fputs("Failed to open CSV file", stderr);
|
fputs("Failed to open CSV file\n", stderr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char buff[MAX_CHAR];
|
char buff[MAX_CHAR];
|
||||||
@@ -54,7 +54,7 @@ CSV_LINE *csvReader(char data_dir[], size_t size) {
|
|||||||
|
|
||||||
FILE *stream = fopen(data_dir, "r");
|
FILE *stream = fopen(data_dir, "r");
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
fputs("Failed to open CSV file", stderr);
|
fputs("Failed to open CSV file\n", stderr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,6 +250,48 @@ COURSE *getCourses(CSV_LINE *lines, size_t lines_len, UNIQUE_COURSES unique_cour
|
|||||||
return courses;
|
return courses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** DEFINE JSON FUNCTION HANDLERS ***/
|
||||||
|
|
||||||
|
int writeStudentsToJson(STUDENT *students, size_t numberOfStudents, char output_dir[]) {
|
||||||
|
FILE *stream = fopen(output_dir, "w");
|
||||||
|
if (!stream) {
|
||||||
|
fputs("Failed to open students output file", stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: expand this function to handle schedule and remainingAlts when data is provided
|
||||||
|
*/
|
||||||
|
|
||||||
|
fprintf(stream, "[\n");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < numberOfStudents; i++) {
|
||||||
|
fprintf(stream, " {\n");
|
||||||
|
fprintf(stream, " \"pupilNum\": %d,\n", students[i].pupilNum);
|
||||||
|
fprintf(stream, " \"requests\": [\n");
|
||||||
|
|
||||||
|
for (size_t j = 0; j < students[i].requestsLen; j++) {
|
||||||
|
fprintf(stream, " {\n");
|
||||||
|
fprintf(stream, " \"crsNo\": \"%s\",\n", students[i].requests[j].crsNo);
|
||||||
|
fprintf(stream, " \"description\": \"%s\",\n", students[i].requests[j].description);
|
||||||
|
fprintf(stream, " \"alternate\": %s\n", students[i].requests[j].alternate ? "true" : "false");
|
||||||
|
fprintf(stream, " }%s\n", j == students[i].requestsLen - 1 ? "" : ",");
|
||||||
|
}
|
||||||
|
fprintf(stream, " ],\n");
|
||||||
|
|
||||||
|
fprintf(stream, " \"schedule\": [],\n");
|
||||||
|
fprintf(stream, " \"expectedClasses\": %d,\n", students[i].expectedClasses);
|
||||||
|
fprintf(stream, " \"classes\": %d,\n", students[i].classes);
|
||||||
|
fprintf(stream, " \"remainingAlts\": [],\n");
|
||||||
|
fprintf(stream, " \"grade\": %d\n", students[i].grade);
|
||||||
|
fprintf(stream, " }%s\n", i == numberOfStudents - 1 ? "" : ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stream, "]");
|
||||||
|
fclose(stream);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -287,7 +329,7 @@ int main(int argc, char **argv) {
|
|||||||
- start algorithm
|
- start algorithm
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// if (writeStudentsToJson(students, students_info.numberOfStudents, "output/students.json") == -1) return -1;
|
if (writeStudentsToJson(students, students_info.numberOfStudents, "output/students.json") == -1) return -1;
|
||||||
// if (writeCoursesToJson(courses, courses_info.numberOfCourses) == -1) return -1;
|
// if (writeCoursesToJson(courses, courses_info.numberOfCourses) == -1) return -1;
|
||||||
|
|
||||||
// Algorithm here
|
// Algorithm here
|
||||||
|
|||||||
@@ -1308,8 +1308,8 @@
|
|||||||
1203410,MTEW-10--S,WOODWORK 10,FALSE
|
1203410,MTEW-10--S,WOODWORK 10,FALSE
|
||||||
1203410,XAT--12A-S,FLEX SENIOR SEMESTER 1,FALSE
|
1203410,XAT--12A-S,FLEX SENIOR SEMESTER 1,FALSE
|
||||||
1203410,XAT--12B-S,FLEX SENIOR SEMESTER 2,FALSE
|
1203410,XAT--12B-S,FLEX SENIOR SEMESTER 2,FALSE
|
||||||
1203410,XSIEP2C--S,"LSB SR ACADEMIC SUPPORT 1, SEMESTERED",FALSE
|
1203410,XSIEP2C--S,LSB SR ACADEMIC SUPPORT 1 SEMESTERED,FALSE
|
||||||
1203410,XSIEP2D--S,"LSB SR ACADEMIC SUPPORT 2, SEMESTERED",FALSE
|
1203410,XSIEP2D--S,LSB SR ACADEMIC SUPPORT 2 SEMESTERED,FALSE
|
||||||
1203410,MVAM-10--S,MEDIA ARTS 10,TRUE
|
1203410,MVAM-10--S,MEDIA ARTS 10,TRUE
|
||||||
1219043,MCH--11--S,CHEMISTRY 11,FALSE
|
1219043,MCH--11--S,CHEMISTRY 11,FALSE
|
||||||
1219043,MEN--11--S-COMP,ENGLISH 11 COMPOSITION,FALSE
|
1219043,MEN--11--S-COMP,ENGLISH 11 COMPOSITION,FALSE
|
||||||
@@ -7283,8 +7283,8 @@
|
|||||||
5665836,MTEW-10--S,WOODWORK 10,FALSE
|
5665836,MTEW-10--S,WOODWORK 10,FALSE
|
||||||
5665836,XAT--12A-S,FLEX SENIOR SEMESTER 1,FALSE
|
5665836,XAT--12A-S,FLEX SENIOR SEMESTER 1,FALSE
|
||||||
5665836,XAT--12B-S,FLEX SENIOR SEMESTER 2,FALSE
|
5665836,XAT--12B-S,FLEX SENIOR SEMESTER 2,FALSE
|
||||||
5665836,XSIEP2C--S,"LSB SR ACADEMIC SUPPORT 1, SEMESTERED",FALSE
|
5665836,XSIEP2C--S,LSB SR ACADEMIC SUPPORT 1, SEMESTERED,FALSE
|
||||||
5665836,XSIEP2D--S,"LSB SR ACADEMIC SUPPORT 2, SEMESTERED",FALSE
|
5665836,XSIEP2D--S,LSB SR ACADEMIC SUPPORT 2, SEMESTERED,FALSE
|
||||||
5665836,MFDN-10--S,FOODS AND NUTRITION 10,TRUE
|
5665836,MFDN-10--S,FOODS AND NUTRITION 10,TRUE
|
||||||
5666390,MFR--08--Y,FRENCH 08,FALSE
|
5666390,MFR--08--Y,FRENCH 08,FALSE
|
||||||
5666390,MMA--08--Y,MATHEMATICS 08,FALSE
|
5666390,MMA--08--Y,MATHEMATICS 08,FALSE
|
||||||
|
|||||||
|
Can't render this file because it is too large.
|
Reference in new issue
Block a user