From b31884b5f5a0ed7255ba504bcb478804d3058820 Mon Sep 17 00:00:00 2001 From: nishikar12 Date: Wed, 3 Apr 2024 22:52:54 -0400 Subject: [PATCH 1/2] Added fix to post-req calculation --- data/addFieldsToCollection.js | 184 ++++++++++++++++++++++++++++++---- 1 file changed, 163 insertions(+), 21 deletions(-) diff --git a/data/addFieldsToCollection.js b/data/addFieldsToCollection.js index 1a0b072..a716a02 100644 --- a/data/addFieldsToCollection.js +++ b/data/addFieldsToCollection.js @@ -17,7 +17,11 @@ import years from '../model/Year.js'; //updateFieldsInCollection(users, {}, { whitelisted_plan_ids: [] }); //setLevelInCourses(); //setVersionInCourses(); -setPostReqsInSISCourses(); +// setPostReqsInSISCourses(); +// setPostReqsInAllSISCourses() +// setPostReqsInSISCoursesTest(); + +// setTagsInCoursesVersioning() // setPostReqsInCourses(); //setPostReqsInSISCoursesVersioning(); // setPostReqsInCoursesVersioning(); @@ -185,12 +189,72 @@ function compareDates(version1, version2) { } /* - Script to set post req field of each current course by looking for corresponding sis course. + Script to set post req field of each current course by looking for corresponding sis course. */ async function setPostReqsInCoursesVersioning() { await db.connect(); const userCourseList = await courses.find(); + var counter = 0; for (let course of userCourseList) { + const sisCourses = await SISCV.find({ + title: course.title, + number: course.number, + }); + if(sisCourses) { + for (let matchedCourse of sisCourses) { + for (let version of matchedCourse.versions) { + if (course.version === version.term) { + course.postReq = version.postReq; + continue; + } + } + } + } + counter++; + if(counter % 100 == 0 ) { + console.log(counter); + console.log(course.title); + } + } + console.log('done'); +} + +/* use this in current implementation */ + +async function setPostReqsInCourses() { + await db.connect(); + var counter = 0; + courses.find().then(async (res) => { + for (let course of res) { + let postReqs = []; + await SISCV.find({ title: course.title, number: course.number }).then( + async (res2) => { + for (let matchedCourse of res2) { + for (let version of matchedCourse.versions) { + course.postReq = version.postReq; + continue; + } + } + }, + ); + counter++; + if(counter %100 ==0) { + console.log(counter); + console.log(course.title); + } + await course.save(); + } + }); + console.log('done'); +} + + +async function setTagsInCoursesVersioning() { + await db.connect(); + + const userCourses = await courses.find(); + // console.log(userCourses); + for (let course of userCourses) { const sisCourses = await SISCV.find({ title: course.title, number: course.number, @@ -198,29 +262,77 @@ async function setPostReqsInCoursesVersioning() { for (let matchedCourse of sisCourses) { for (let version of matchedCourse.versions) { if (course.version === version.term) { - course.postReq = version.postReq; - continue; + // console.log(version.term) + // console.log(version.tags) + // console.log(course.tags) + // course.tags = version.tags; + // console.log(course.tags) + if(course.tags !== version.tags) { + console.log(course.title); + course.tags = version.tags; + } + await course.save(); + break; } } + break; } + } + + // const userCourseList = await courses.find(); + // for (let course of userCourseList) { + // const sisCourses = await SISCV.find({ + // title: course.title, + // number: course.number, + // }); + // // const sisCourses = await SISCV.find({ + // // title: "Object Oriented Software Engineering", + // // number: "EN.601.421", + // // }); + // // console.log(sisCourses) + // let counter = 1; + // for (let matchedCourse of sisCourses) { + // for (let version of matchedCourse.versions) { + // if (course.version === version.term) { + // if(course.tags !== version.tags) + // { + // console.log(course.title); + // console.log(version.tags); + + // } + // course.tags= version.tags; + // counter++ + // if(counter % 100 == 0) { + // console.log(course.title); + // console.log(version.tags); + // } + // break; + // } + // } + // } + // } console.log('done'); } -async function setPostReqsInSISCourses() { +async function setPostReqsInNewSISCourses() { await db.connect(); var counter = 0; + //finds all courses without post reqs SISCV.find({ version: { $elemMatch: { postReq: { $size: 0 } } } }).then( async (res) => { for (let course of res) { let postReqs = []; + //finds all courses that have this course as a a prereq await SISCV.find({ versions: { $elemMatch: { - preReq: { $elemMatch: { Expression: { $regex: course.number } } }, + preReq: { $elemMatch: { Expression: { $regex: course.number }, IsNegative: "N" } }, }, }, }).then(async (res2) => { + // for all courses that have this course as a pre-req, check the first version of the second course + // for all preReqs inside it, make sure the preReq is negative. If for (let matchedCourse of res2) { for (let preReq of matchedCourse.versions[0].preReq) { if (preReq.IsNegative === 'N') { @@ -250,28 +362,58 @@ async function setPostReqsInSISCourses() { console.log('done'); } -async function setPostReqsInCourses() { +async function setPostReqsInAllSISCourses() { await db.connect(); - courses.find().then(async (res) => { - for (let course of res) { - let postReqs = []; - await SISCV.find({ title: course.title, number: course.number }).then( - async (res2) => { + var counter = 0; + //finds all courses + SISCV.find().then( + async (res) => { + for (let course of res) { + let postReqs = []; + //finds all courses that have this course as a a prereq + await SISCV.find({ + versions: { + $elemMatch: { + preReq: { $elemMatch: { Expression: { $regex: course.number }, IsNegative: "N" } }, + }, + }, + }).then(async (res2) => { + // for all courses that have this course as a pre-req, check the first version of the second course + // for all preReqs inside it, make sure the preReq is negative. If for (let matchedCourse of res2) { - for (let version of matchedCourse.versions) { - course.postReq = version.postReq; - continue; + for (let preReq of matchedCourse.versions[0].preReq) { + if (preReq.IsNegative === 'N') { + postReqs.push({ + courseId: matchedCourse.id, + number: matchedCourse.number, + title: matchedCourse.title, + credits: matchedCourse.versions[0].credits, + preReqs: preReq.Expression, + }); + break; + } } } - }, - ); - console.log(course.title); - await course.save(); - } - }); + }); + counter++; + for (let version of course.versions) { + version.postReq = postReqs; + } + if (counter % 100 === 0) { + console.log(course.title); + } + await course.save(); + } + }, + ); + //doesn't print sometimes console.log('done'); } + + + + /* Script to add the 'version' field based on term and year fields */ From 7c5f878a80fb2f22813dec54a383673235d2095e Mon Sep 17 00:00:00 2001 From: nishikar12 Date: Wed, 3 Apr 2024 22:57:32 -0400 Subject: [PATCH 2/2] prettier sucks --- data/addFieldsToCollection.js | 94 ++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/data/addFieldsToCollection.js b/data/addFieldsToCollection.js index a716a02..921dc90 100644 --- a/data/addFieldsToCollection.js +++ b/data/addFieldsToCollection.js @@ -200,7 +200,7 @@ async function setPostReqsInCoursesVersioning() { title: course.title, number: course.number, }); - if(sisCourses) { + if (sisCourses) { for (let matchedCourse of sisCourses) { for (let version of matchedCourse.versions) { if (course.version === version.term) { @@ -211,7 +211,7 @@ async function setPostReqsInCoursesVersioning() { } } counter++; - if(counter % 100 == 0 ) { + if (counter % 100 == 0) { console.log(counter); console.log(course.title); } @@ -238,7 +238,7 @@ async function setPostReqsInCourses() { }, ); counter++; - if(counter %100 ==0) { + if (counter % 100 == 0) { console.log(counter); console.log(course.title); } @@ -248,7 +248,6 @@ async function setPostReqsInCourses() { console.log('done'); } - async function setTagsInCoursesVersioning() { await db.connect(); @@ -267,7 +266,7 @@ async function setTagsInCoursesVersioning() { // console.log(course.tags) // course.tags = version.tags; // console.log(course.tags) - if(course.tags !== version.tags) { + if (course.tags !== version.tags) { console.log(course.title); course.tags = version.tags; } @@ -277,7 +276,6 @@ async function setTagsInCoursesVersioning() { } break; } - } // const userCourseList = await courses.find(); @@ -327,12 +325,17 @@ async function setPostReqsInNewSISCourses() { await SISCV.find({ versions: { $elemMatch: { - preReq: { $elemMatch: { Expression: { $regex: course.number }, IsNegative: "N" } }, + preReq: { + $elemMatch: { + Expression: { $regex: course.number }, + IsNegative: 'N', + }, + }, }, }, }).then(async (res2) => { // for all courses that have this course as a pre-req, check the first version of the second course - // for all preReqs inside it, make sure the preReq is negative. If + // for all preReqs inside it, make sure the preReq is negative. If for (let matchedCourse of res2) { for (let preReq of matchedCourse.versions[0].preReq) { if (preReq.IsNegative === 'N') { @@ -366,54 +369,53 @@ async function setPostReqsInAllSISCourses() { await db.connect(); var counter = 0; //finds all courses - SISCV.find().then( - async (res) => { - for (let course of res) { - let postReqs = []; - //finds all courses that have this course as a a prereq - await SISCV.find({ - versions: { - $elemMatch: { - preReq: { $elemMatch: { Expression: { $regex: course.number }, IsNegative: "N" } }, + SISCV.find().then(async (res) => { + for (let course of res) { + let postReqs = []; + //finds all courses that have this course as a a prereq + await SISCV.find({ + versions: { + $elemMatch: { + preReq: { + $elemMatch: { + Expression: { $regex: course.number }, + IsNegative: 'N', + }, }, }, - }).then(async (res2) => { - // for all courses that have this course as a pre-req, check the first version of the second course - // for all preReqs inside it, make sure the preReq is negative. If - for (let matchedCourse of res2) { - for (let preReq of matchedCourse.versions[0].preReq) { - if (preReq.IsNegative === 'N') { - postReqs.push({ - courseId: matchedCourse.id, - number: matchedCourse.number, - title: matchedCourse.title, - credits: matchedCourse.versions[0].credits, - preReqs: preReq.Expression, - }); - break; - } + }, + }).then(async (res2) => { + // for all courses that have this course as a pre-req, check the first version of the second course + // for all preReqs inside it, make sure the preReq is negative. If + for (let matchedCourse of res2) { + for (let preReq of matchedCourse.versions[0].preReq) { + if (preReq.IsNegative === 'N') { + postReqs.push({ + courseId: matchedCourse.id, + number: matchedCourse.number, + title: matchedCourse.title, + credits: matchedCourse.versions[0].credits, + preReqs: preReq.Expression, + }); + break; } } - }); - counter++; - for (let version of course.versions) { - version.postReq = postReqs; - } - if (counter % 100 === 0) { - console.log(course.title); } - await course.save(); + }); + counter++; + for (let version of course.versions) { + version.postReq = postReqs; } - }, - ); + if (counter % 100 === 0) { + console.log(course.title); + } + await course.save(); + } + }); //doesn't print sometimes console.log('done'); } - - - - /* Script to add the 'version' field based on term and year fields */