Skip to content

Commit

Permalink
Added fix to post-req calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nishikar12 committed Apr 4, 2024
1 parent 8c137f1 commit b31884b
Showing 1 changed file with 163 additions and 21 deletions.
184 changes: 163 additions & 21 deletions data/addFieldsToCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -185,42 +189,150 @@ 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,
});
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') {
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit b31884b

Please sign in to comment.