Skip to content

Commit

Permalink
Merge pull request #64 from AnimeAllstar/Asad
Browse files Browse the repository at this point in the history
Last non-react commit (maybe)
  • Loading branch information
AnimeAllstar authored Aug 2, 2021
2 parents 833e91c + c16b994 commit aca2fe4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 14 deletions.
45 changes: 32 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"sort-json": "^2.0.0",
"uglify-js": "^3.13.10"
}
}
}
46 changes: 46 additions & 0 deletions scripts/GetPatterns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const jsonfile = require('jsonfile');
const path = require('path');

const source = path.join(__dirname, '..', 'data', 'json', 'master.json');

const patterns = [];
const re = new RegExp('\\w{3,4}\\s*\\d{3}', 'g');
const reX = new RegExp('XXX', 'g');
const rec = new RegExp('recommended', 'i');
const reall = new RegExp('all of', 'i');
const reone = new RegExp('one of', 'i');
const reand = new RegExp('and', 'i');
const reor = new RegExp('or', 'i');

jsonfile.readFile(source, (err, obj) => {
if (err) {
console.error(err);
} else {
obj.forEach((course) => {
const prereq = course.prer;
if (prereq) {
const reCourse = new RegExp(course.code.split(' ')[0] + '\\s*\\d{3}', 'g');
const matches = prereq.match(reCourse);
const p = prereq.replace(re, 'XXX');
let pat = '';
p.split('.').forEach((sentence) => {
let str = sentence;
if (sentence.match(reX) && !sentence.match(rec)) {
pat += str + '.';
}
});
if (pat.match(reone) && !pat.match(reall) && !pat.match(reand) && !pat.match(reor)) {
pat = 'ONEOF'
}
if (pat.match(reall) && !pat.match(reone) && !pat.match(reand) && !pat.match(reor)) {
pat = 'ALLOF'
}
if (!patterns.includes(pat) && matches) {
patterns.push(pat);
}
}
});
console.log(patterns);
console.log(patterns.length);
}
})

0 comments on commit aca2fe4

Please sign in to comment.