From 5392cf6f6fa08d666ee58a2a57757192d9a50398 Mon Sep 17 00:00:00 2001 From: kumar Date: Mon, 18 Jul 2016 18:45:59 -0400 Subject: .idea removed --- .idea/vcs.xml | 6 - .idea/workspace.xml | 403 ---------------------------------------------------- 2 files changed, 409 deletions(-) delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index dff2e41..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,403 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - - - - - - - - - - - - - - project - - - true - - bdd - - DIRECTORY - - false - - - - - - - - - - - - 1468029982798 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- cgit v1.2.3 From daefddd8dc45e7044e83bd40706cfdca36471fe9 Mon Sep 17 00:00:00 2001 From: Waref Haque Date: Tue, 19 Jul 2016 00:21:17 -0400 Subject: proper exams rendering --- .idea/jsLibraryMappings.xml | 7 + .idea/libraries/solutions_repo_node_modules.xml | 14 ++ .idea/modules.xml | 8 + .idea/solutions_repo.iml | 9 + .idea/vcs.xml | 6 + .idea/workspace.xml | 248 ++++++++++++++++++++++++ app.js | 48 ----- routes/index.js | 45 ++++- 8 files changed, 335 insertions(+), 50 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/libraries/solutions_repo_node_modules.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/solutions_repo.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..ddeb853 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/solutions_repo_node_modules.xml b/.idea/libraries/solutions_repo_node_modules.xml new file mode 100644 index 0000000..fd48a42 --- /dev/null +++ b/.idea/libraries/solutions_repo_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3d57a3a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/solutions_repo.iml b/.idea/solutions_repo.iml new file mode 100644 index 0000000..004ef7c --- /dev/null +++ b/.idea/solutions_repo.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..a15a1d8 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1468901747117 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app.js b/app.js index e4d0843..ba7c014 100644 --- a/app.js +++ b/app.js @@ -32,51 +32,3 @@ app.use(express.static(__dirname)); app.use('/', routes); module.exports = app; - -app.listen(3000, function() { - console.log('listening on http://localhost:3000/'); -}); - -//to fetch exams given a course code and populate the exams page -app.get('/exams',function (req,res) { - console.log(req.query.search); - var courseName = req.query.search; - courseName = sanitizer.escape(courseName); - courseName = courseName.toUpperCase(); - console.log(courseName); - var result = getExamsForCourseCode(courseName); - console.log(result); - res.write(JSON.stringify(result)); -}); - -function getExamsForCourseCode(courseCode) { - var minExamInfoArray = []; - dbFile.get_all_exams(courseCode, function (exams) { - if (exams.length == 0){ - console.log("Nothing was found"); - } - else { - //console.log(exams); - //only pass over the information that is necessary for the exams page - for (var i = 0; i Date: Tue, 19 Jul 2016 19:21:20 -0400 Subject: added the id to exams passed --- .idea/workspace.xml | 167 ++++++++++++++++++++++++++++++++++++++++++++-------- routes/index.js | 15 +---- 2 files changed, 145 insertions(+), 37 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a15a1d8..98b079d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -24,31 +24,41 @@ - + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + @@ -62,8 +72,8 @@ @@ -154,6 +164,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + true + + bdd + + DIRECTORY + + false + + - @@ -198,18 +285,18 @@ + - + + - - @@ -220,10 +307,10 @@ - + - - + + @@ -236,10 +323,42 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/routes/index.js b/routes/index.js index 1406143..72e6c5b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -59,7 +59,8 @@ router.get('/exams/:id', function(req, res, next) { term:toProperCase(exams[i].term), instructors:exams[i].instructors, type:toProperCase(exams[i].type) + " Examination", - title:exams[i].title + title:exams[i].title, + id:exams[i]._id }; //console.log(minExamInfo); minExamInfoArray.push(minExamInfo); @@ -91,18 +92,6 @@ app.get('/exams.html', function (req,res) { res.sendFile(__dirname+'/exams.html'); });*/ - -function getExamsForCourseCode(courseCode) { - dbFile.get_all_exams(courseCode, function (exams) { - if (exams.length == 0){ - console.log("Nothing was found"); - } - else { - console.log(exams); - } - }); -} - module.exports = router; function toProperCase(string) { -- cgit v1.2.3 From ac00f848b0c971abb8d944f1cead430baa834b06 Mon Sep 17 00:00:00 2001 From: Damani Pradyumn Date: Tue, 19 Jul 2016 23:03:38 -0400 Subject: working on queries --- node_simple.js | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- testImports.js | 19 +++++++-- 2 files changed, 137 insertions(+), 8 deletions(-) diff --git a/node_simple.js b/node_simple.js index 5542c40..894d63b 100644 --- a/node_simple.js +++ b/node_simple.js @@ -13,6 +13,8 @@ * */ +/* I pass in exam id and you give me the number of questions and the comments and solutions associated with each question?*/ + /* Tables SO FAR: * 1. exams * 2. courses @@ -36,10 +38,10 @@ // |..........| -// |================================solutions===================================| -// |_________ _id_____________|exam_id_____________________|q_id_|text____|votes| -// |==========================|============================|=====|========|=====| -// |"354ff71ed078933079d6467e"|"578a44ff71ed097fc3079d6e" |1 |"answer"| 1 | +// |================================solutions============================================| +// |_________ _id_____________|exam_id_____________________|q_id_|text____|votes|comments| +// |==========================|============================|=====|========|=====|========| +// |"354ff71ed078933079d6467e"|"578a44ff71ed097fc3079d6e" |1 |"answer"| 1 |[{},{}] | // |..........| var exports = module.exports = {}; @@ -64,6 +66,119 @@ var uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo' + + +exports.get_exam_info_by_ID = function (exam_id) { + + //first get this exam; + // var exam = exports.get_exam_byID(exam_id); + // var num_questions = exam[0].questions_count; + + //get how many solutions there are for each question + + + + mongoFactory.getConnection(uri) + .then(function (db) { + + var solutions = db.collection('solutions'); + + var cursor = solutions.find({ exam_id: exam_id}), i = 0; + + var count = []; + cursor.forEach(function (x) { + + console.log(x); + }); + + +/* var q_count = []; + + for (var i = 1; i <= 2; i++) { + solutions.count( + { + exam_id: exam_id, + q_id: i + } + ,function (err, result) { + q_count.push(result); + console.log(q_count); + + // console.log("found "+ result + " solutions"); + } + ); + }*/ + + + }) + .catch(function (err) { + console.err(err); + }) + +} + + + + + + + + + +exports.add_comment = function (sol_id, fields) { + var Data = { + text: fields[0], + date: fields[1], + by: fields[2] + }; + + mongoFactory.getConnection(uri) + .then(function (db) { + + // find the solutions table + var solutions = db.collection('solutions'); + // insert data into table + solutions.updateOne( {_id: ObjectId(sol_id)}, {$push: {comments: Data}} , function (err, result) { + if (err) throw err; + else { + console.log("comment added"); + } + }); + + }) + .catch(function (err) { + console.error(err); + }) +} + +// get all solutions given an exam_id and the question number +exports.get_all_solutions = function (exam_id, q_num) { + mongoFactory.getConnection(uri) + .then(function (db) { + + var solutions = db.collection('solutions'); + + solutions.find( + { + exam_id: exam_id, + q_id: q_num + } + ).toArray( function (err, docs) { + if (err) throw err; + else { + console.log(docs); + } + }); + + + }) + .catch(function () { + console.error(err); + }) + + +} + /* * This function will add a solution to the solutions table in the database . * Params: fields - [exam_id , question_id, solution text] @@ -76,7 +191,8 @@ exports.add_solution = function (fields) { exam_id: fields[0], q_id: fields[1], text: fields[2], - votes: 0 + votes: 0, + comments: [] }; // establish a connection diff --git a/testImports.js b/testImports.js index fc128eb..f64f984 100644 --- a/testImports.js +++ b/testImports.js @@ -17,17 +17,30 @@ var questions_array = ["this is q1", "this is q2"]; //test getting all exams database functionality -- USE FOR THE EXAMS PAGES maybe? -dbFile.get_all_exams("CSC240", function (exams) { +/*dbFile.get_all_exams("CSC240", function (exams) { if (exams.length == 0){ console.log("Nothing was found"); } else { console.log(exams); } -}); +});*/ //test adding course // dbFile.add_course("CSC148", "Intro to Programming"); //test adding solution -//dbFile.add_solution(["578a44ff71ed097fc3079d6e", 1, "this is another solution to q1"]); +//dbFile.add_solution(["578a44ff71ed097fc3079d6e", 1, "this is yet another solution to q1"]); + + + +// dbFile.get_exam_byID("578a44ff71ed097fc3079d6e"); + +//test getting all solutions of a given exam and question number +//dbFile.get_all_solutions("578a44ff71ed097fc3079d6e", 1); + + +//test adding of comments given a solution_id, and the comment information as an array +// dbFile.add_comment("578edba3e5611f0d4e23c65f", ["this is the 2nd comment", "this is the date", "this is the author"]); + +dbFile.get_exam_info_by_ID("578a44ff71ed097fc3079d6e"); \ No newline at end of file -- cgit v1.2.3 From ace9594db4a798dc638d6ee2e50935b912bdaaea Mon Sep 17 00:00:00 2001 From: HumairAK Date: Tue, 19 Jul 2016 23:37:36 -0400 Subject: deleted unnecessary files --- .idea/jsLibraryMappings.xml | 7 - .idea/libraries/solutions_repo_node_modules.xml | 14 - .idea/modules.xml | 8 - .idea/solutions_repo.iml | 9 - .idea/vcs.xml | 6 - .idea/workspace.xml | 367 ------------------------ 6 files changed, 411 deletions(-) delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/libraries/solutions_repo_node_modules.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/solutions_repo.iml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index ddeb853..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/solutions_repo_node_modules.xml b/.idea/libraries/solutions_repo_node_modules.xml deleted file mode 100644 index fd48a42..0000000 --- a/.idea/libraries/solutions_repo_node_modules.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3d57a3a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/solutions_repo.iml b/.idea/solutions_repo.iml deleted file mode 100644 index 004ef7c..0000000 --- a/.idea/solutions_repo.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 98b079d..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,367 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - project - - - true - - bdd - - DIRECTORY - - false - - - - - - - - - 1468901747117 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- cgit v1.2.3 From 26a31332f980dd89fd9016e950c8ef05948a0886 Mon Sep 17 00:00:00 2001 From: kumar Date: Wed, 20 Jul 2016 01:28:17 -0400 Subject: added getting number of solutions and comments --- node_simple.js | 68 ++++++++++++++++++++++++++-------------------------------- testImports.js | 16 ++++++++++---- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/node_simple.js b/node_simple.js index 894d63b..33e9862 100644 --- a/node_simple.js +++ b/node_simple.js @@ -67,49 +67,45 @@ var uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo' - -exports.get_exam_info_by_ID = function (exam_id) { - - //first get this exam; - // var exam = exports.get_exam_byID(exam_id); - // var num_questions = exam[0].questions_count; - - //get how many solutions there are for each question - - +// this function returns an array where is element contains info for a particular question +// such as the question number (_id), number of solutions (count), and number of comments +// (comments). [ {_id,count,comments}, {} ...] +exports.get_exam_info_by_ID = function (exam_id, callback) { mongoFactory.getConnection(uri) .then(function (db) { var solutions = db.collection('solutions'); - var cursor = solutions.find({ exam_id: exam_id}), i = 0; + solutions.aggregate( + [ - var count = []; - cursor.forEach(function (x) { - - console.log(x); - }); - - -/* var q_count = []; - - for (var i = 1; i <= 2; i++) { - solutions.count( + // {$unwind: "$comments"}, + { $match: { exam_id: exam_id }}, { - exam_id: exam_id, - q_id: i - } - ,function (err, result) { - q_count.push(result); - console.log(q_count); + $project: + { + num_comments: { $size: "$comments" }, + _id: "$exam_id", + q_id: "$q_id" + } + }, + { + $group : { + _id : "$q_id", + count: { $sum: 1 }, + comments: {$sum: "$num_comments"} + // num_comments: { $size: "$comments" } - // console.log("found "+ result + " solutions"); + } } - ); - }*/ + ]).toArray(function (err, result) { + // console.log(result); + callback(result); + + }); }) .catch(function (err) { console.err(err); @@ -119,12 +115,6 @@ exports.get_exam_info_by_ID = function (exam_id) { - - - - - - exports.add_comment = function (sol_id, fields) { var Data = { text: fields[0], @@ -152,7 +142,7 @@ exports.add_comment = function (sol_id, fields) { } // get all solutions given an exam_id and the question number -exports.get_all_solutions = function (exam_id, q_num) { +exports.get_all_solutions = function (exam_id, q_num, callback) { mongoFactory.getConnection(uri) .then(function (db) { @@ -167,6 +157,8 @@ exports.get_all_solutions = function (exam_id, q_num) { if (err) throw err; else { console.log(docs); + + callback(docs); } }); diff --git a/testImports.js b/testImports.js index f64f984..c9f0bb2 100644 --- a/testImports.js +++ b/testImports.js @@ -30,10 +30,10 @@ var questions_array = ["this is q1", "this is q2"]; // dbFile.add_course("CSC148", "Intro to Programming"); //test adding solution -//dbFile.add_solution(["578a44ff71ed097fc3079d6e", 1, "this is yet another solution to q1"]); - +//dbFile.add_solution(["578a44ff71ed097fc3079d6e", 2, "this is a solution to q2"]); +// the following just prints the exam to console // dbFile.get_exam_byID("578a44ff71ed097fc3079d6e"); //test getting all solutions of a given exam and question number @@ -41,6 +41,14 @@ var questions_array = ["this is q1", "this is q2"]; //test adding of comments given a solution_id, and the comment information as an array -// dbFile.add_comment("578edba3e5611f0d4e23c65f", ["this is the 2nd comment", "this is the date", "this is the author"]); +// dbFile.add_comment("578f08e43bba452ee98da444", ["this is asdfasdf", "this is the date", "this is the author"]); + -dbFile.get_exam_info_by_ID("578a44ff71ed097fc3079d6e"); \ No newline at end of file +dbFile.get_exam_info_by_ID("578a44ff71ed097fc3079d6e", function (result) { + if (result.length == 0) { + console.log("some error occured"); + } + else { + console.log(result); + } +}); \ No newline at end of file -- cgit v1.2.3