Skip to content

Commit

Permalink
Enum for Course and Marks Type
Browse files Browse the repository at this point in the history
  • Loading branch information
aneesh-neelam committed Feb 4, 2015
1 parent 2c708ea commit 46d2e2f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 82 deletions.
39 changes: 27 additions & 12 deletions api-0.14/scraper/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ exports.get = function (app, data, callback) {
var forEachCourse = function (element, asyncCallback) {
var foundAttendance = false;
var foundMarks = false;
switch (element.course_mode.toUpperCase()) {
case 'CBL':
element.course_type = 1.0;
break;
case 'LBC':
element.course_type = 2.0;
break;
case 'PBL':
element.course_type = 3.1;
break;
case 'RBL':
element.course_type = 3.2;
break;
case 'PBC':
if (element.project_title) {
element.course_type = 4.1;
}
else {
element.course_type = 4.2;

This comment has been minimized.

Copy link
@karthikb351

karthikb351 Feb 5, 2015

Collaborator

Enums are integers only. Floats are too confusing.

}
break;
default:
element.course_type = 0;
break;
}
var forEachAttendance = function (elt, i, arr) {
if (element['class_number'] === elt['class_number']) {
foundAttendance = true;
Expand All @@ -135,12 +160,7 @@ exports.get = function (app, data, callback) {
delete elt['course_code'];
delete elt['course_title'];
delete elt['course_type'];
if (elt.details) {
element['pbl_marks'] = underscore.values(elt.details);
}
else {
element[element.course_mode.toLowerCase() + '_marks'] = elt;
}
element.marks = elt;
}
};
results.attendance.forEach(forEachAttendance);
Expand All @@ -152,12 +172,7 @@ exports.get = function (app, data, callback) {
element.attendance = noData;
}
if (!foundMarks) {
if (element.course_mode === 'PBL' || element.course_mode === 'RBL') {
element['pbl_marks'] = noData;
}
else {
element[element.course_mode.toLowerCase() + '_marks'] = noData;
}
element.marks = noData;
}
asyncCallback(null, element);
};
Expand Down
38 changes: 19 additions & 19 deletions api-0.14/scraper/attendance.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ exports.scrapeAttendance = function (app, data, callback) {
var attendance = [];
try {
var scraper = cheerio.load(response.body);
scraper = cheerio.load(scraper('table table').eq(1).html());
scraper = cheerio.load(scraper('table table').eq(1).html())
var onEach = function (i, elem) {
var htmlRow = cheerio.load(scraper(this).html());
var htmlColumn = htmlRow('td');
if (i > 0) {
var classnbr = htmlRow('input[name=classnbr]').attr('value');
attendance.push({
'class_number': classnbr,
'course_code': htmlColumn.eq(1).text(),
'course_title': htmlColumn.eq(2).text(),
'course_type': htmlColumn.eq(3).text(),
'slot': htmlColumn.eq(4).text(),
'registration_date': htmlColumn.eq(5).text(),
'attended_classes': htmlColumn.eq(6).text(),
'total_classes': htmlColumn.eq(7).text(),
'attendance_percentage': htmlColumn.eq(8).text(),
'form': {
'semcode': htmlRow('input[name=semcode]').attr('value'),
'from_date': htmlRow('input[name=from_date]').attr('value'),
'to_date': htmlRow('input[name=to_date]').attr('value'),
'classnbr': classnbr
class_number: classnbr,
course_code: htmlColumn.eq(1).text(),
course_title: htmlColumn.eq(2).text(),
course_type: htmlColumn.eq(3).text(),
slot: htmlColumn.eq(4).text(),
registration_date: htmlColumn.eq(5).text(),
attended_classes: htmlColumn.eq(6).text(),
total_classes: htmlColumn.eq(7).text(),
attendance_percentage: htmlColumn.eq(8).text(),
form: {
semcode: htmlRow('input[name=semcode]').attr('value'),
from_date: htmlRow('input[name=from_date]').attr('value'),
to_date: htmlRow('inpt[name=to_date]').attr('value'),
classnbr: classnbr
}
});
}
Expand All @@ -94,10 +94,10 @@ exports.scrapeAttendance = function (app, data, callback) {
var htmlColumn = cheerio.load(scraper(this).html())('td');
if (i > 1) {
details.push({
'sl': htmlColumn.eq(0).text(),
'date': htmlColumn.eq(1).text(),
'status': htmlColumn.eq(3).text(),
'reason': htmlColumn.eq(5).text()
sl: htmlColumn.eq(0).text(),
date: htmlColumn.eq(1).text(),
status: htmlColumn.eq(3).text(),
reason: htmlColumn.eq(5).text()
});
}
};
Expand Down
66 changes: 35 additions & 31 deletions api-0.14/scraper/marks.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,43 @@ exports.scrapeMarks = function (app, data, callback) {
var classnbr = htmlColumn.eq(1).text();
if (length == 18) {
marks.push({
'class_number': classnbr,
'course_code': htmlColumn.eq(2).text(),
'course_title': htmlColumn.eq(3).text(),
'course_type': htmlColumn.eq(4).text(),
'cat1': htmlColumn.eq(6).text(),
'cat1_status': htmlColumn.eq(5).text(),
'cat2': htmlColumn.eq(8).text(),
'cat2_status': htmlColumn.eq(7).text(),
'quiz1': htmlColumn.eq(10).text(),
'quiz1_status': htmlColumn.eq(9).text(),
'quiz2': htmlColumn.eq(12).text(),
'quiz2_status': htmlColumn.eq(11).text(),
'quiz3': htmlColumn.eq(14).text(),
'quiz3_status': htmlColumn.eq(13).text(),
'assignment': htmlColumn.eq(16).text(),
'assignment_status': htmlColumn.eq(15).text()
class_number: classnbr,
course_code: htmlColumn.eq(2).text(),
course_title: htmlColumn.eq(3).text(),
course_type: htmlColumn.eq(4).text(),
cat1: htmlColumn.eq(6).text(),
cat1_status: htmlColumn.eq(5).text(),
cat2: htmlColumn.eq(8).text(),
cat2_status: htmlColumn.eq(7).text(),
quiz1: htmlColumn.eq(10).text(),
quiz1_status: htmlColumn.eq(9).text(),
quiz2: htmlColumn.eq(12).text(),
quiz2_status: htmlColumn.eq(11).text(),
quiz3: htmlColumn.eq(14).text(),
quiz3_status: htmlColumn.eq(13).text(),
assignment: htmlColumn.eq(16).text(),
assignment_status: htmlColumn.eq(15).text(),
marks_type: 1
});
}
else if (length == 8) {
marks.push({
'class_number': classnbr,
'course_code': htmlColumn.eq(2).text(),
'course_title': htmlColumn.eq(3).text(),
'course_type': htmlColumn.eq(4).text(),
'lab_cam': htmlColumn.eq(7).text(),
'lab_cam_status': htmlColumn.eq(6).text()
class_number: classnbr,
course_code: htmlColumn.eq(2).text(),
course_title: htmlColumn.eq(3).text(),
course_type: htmColumn.eq(4).text(),
lab_cam: htmlColumn.eq(7).text(),
lab_cam_status: htmlColumn.eq(6).text(),
marks_type: 2
});
}
else if (length == 6) {
marks.push({
'class_number': classnbr,
'course_code': htmlColumn.eq(2).text(),
'course_title': htmlColumn.eq(3).text(),
'course_type': htmlColumn.eq(4).text()
class_number: classnbr,
course_code: htmlColumn.eq(2).text(),
course_title: htmlColumn.eq(3).text(),
course_type: htmlColumn.eq(4).text(),
marks_type = 3
});
}
}
Expand All @@ -118,11 +121,12 @@ exports.scrapeMarks = function (app, data, callback) {
switch (row) {
case 0:
pblMarks[course] = {
'class_number': htmlColumn.eq(1).text(),
'course_code': htmlColumn.eq(2).text(),
'course_title': htmlColumn.eq(3).text(),
'course_type': htmlColumn.eq(4).text(),
'details': {
class_number: htmlColumn.eq(1).text(),
course_code: htmlColumn.eq(2).text(),
course_title: htmlColumn.eq(3).text(),
course_type: htmlColumn.eq(4).text(),
marks_type = 4,
details: {
1: {title: htmlColumn.eq(6).text()},
2: {title: htmlColumn.eq(7).text()},
3: {title: htmlColumn.eq(8).text()},
Expand Down
38 changes: 19 additions & 19 deletions api-0.14/scraper/timetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ exports.scrapeTimetable = function (app, data, callback) {
}
tmp[code] = classnbr;
timetable['courses'].push({
'class_number': classnbr,
'course_code': htmlColumn.eq(2).text(),
'course_title': htmlColumn.eq(3).text(),
'course_type': courseType,
'ltpc': htmlColumn.eq(5).text().replace(/[^a-zA-Z0-9]/g, ''),
'course_mode': htmlColumn.eq(6).text(),
'course_option': htmlColumn.eq(7).text(),
'slot': slot,
'venue': venue,
'faculty': faculty,
'registration_status': registrationStatus,
'bill_date': billDate,
'project_title': projectTitle
class_number: classnbr,
course_code: htmlColumn.eq(2).text(),
course_title: htmlColumn.eq(3).text(),
course_type: courseType,
ltpc: htmlColumn.eq(5).text().replace(/[^a-zA-Z0-9]/g, ''),
course_mode: htmlColumn.eq(6).text(),
course_option: htmlColumn.eq(7).text(),
slot: slot,
venue: venue,
faculty: faculty,
registration_status: registrationStatus,
bill_date: billDate,
project_title: projectTitle
});
}
};
Expand Down Expand Up @@ -148,22 +148,22 @@ exports.scrapeTimetable = function (app, data, callback) {
}
switch (i) {
case 2:
timetable.timetable.mon = day;
timetable.timetable.monday = day;
break;
case 3:
timetable.timetable.tue = day;
timetable.timetable.tuesday = day;
break;
case 4:
timetable.timetable.wed = day;
timetable.timetable.wednesday = day;
break;
case 5:
timetable.timetable.thu = day;
timetable.timetable.thursday = day;
break;
case 6:
timetable.timetable.fri = day;
timetable.timetable.friday = day;
break;
case 7:
timetable.timetable.sat = day;
timetable.timetable.saturday = day;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion api-0.14/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ exports.get = function (app, data, callback) {
callback(true, data);
}
};
collection.findOne({campus: data.campus}, keys, onFetch);
collection.findOne({}, keys, onFetch);
};

1 comment on commit 46d2e2f

@aneesh-neelam
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karthikb351: They are Integers now.

Please sign in to comment.