Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
[#1022] Dynamic mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0chin committed Oct 3, 2017
1 parent e1129ca commit fdecd78
Showing 1 changed file with 146 additions and 174 deletions.
320 changes: 146 additions & 174 deletions tests/course_mock_data
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,82 @@ function start() {

// Increase Limits so couchapp push works correctly
function increaseLimits() {
exec('sudo launchctl limit maxfiles 150056 150056', function doneWithLaunchCtl() {
exec('sudo ulimit -n 150056', function doneWithUlimit() {
return createDummyCourses()
})
})
return createDummyCourses()

}

var n_courses = 2 ; //Number of Iteration to run for courses
var n_members = 5;
var n_courses = 2; //Number of Iteration to run for courses
var n_steps = 5;
var defaultCourses = []; //Contains only CourseID and MemberList
var defaultCoursestep = [];
var defaultCoursequestion = [];
var defaultResources = [];
var defaultMembers = [];
var defaultCourseanswer = [];

function createDummyCourses() {
var courses = nano.db.use('courses');
var coursestep = nano.db.use('coursestep');
var coursequestion = nano.db.use('coursequestion');
var courses = nano.db.use('courses');
var coursestep = nano.db.use('coursestep');
var coursequestion = nano.db.use('coursequestion');
var members = nano.db.use('members');
var courseanswer = nano.db.use('courseanswer');

/***************Members***************/
//First you need to create Member:

for(course = 0; course < n_courses; course++){
for(var member = 0; member < n_members; member++){
participation = member + 1;
if(member< parseInt(n_members/2)){
defaultMembers.push({
"login": "member" + participation,
"kind": "Member",
"roles": ["Manager"],
"firstName": "Member " + participation,
"lastName": "Member " + participation,
"password": "password",
"Gender": "Male",
"status": "active",
"email": "member" + participation + "[email protected]",
"visits": 0,
"BirthDate": "01/01/1985"
});
}else{
defaultMembers.push({
"login": "member" + participation,
"kind": "Member",
"roles": ["Learner"],
"firstName": "Member " + participation,
"lastName": "Member " + participation,
"password": "password",
"Gender": "Male",
"status": "active",
"email": "member" + participation + "[email protected]",
"visits": 0,
"BirthDate": "01/01/1985"
});
}
}
members.bulk({"docs":defaultMembers}, function(err, res) {
if (err)
return console.log(err);
else {
var memberarr = [];
for(var course = 0; course < res.length; course++){
memberarr.push(res[course].id);
course_number = course + 1;
var subjectLevel;
var gradelevel;
if (course <=3){
subjectLevel = "Amateur";
gradelevel = "Higher"
}else if(course>=4 && course<=8){
subjectLevel = "Mid";
gradelevel="10"
}else{
subjectLevel = "Beginner";
gradelevel="5"
}

defaultCourses.push({
"CourseTitle": "Course " +course_number,
"Day": "0",
Expand All @@ -53,187 +101,111 @@ function createDummyCourses() {
"endDate": "12/12/2017",
"endTime": "17:00",
"foregroundColor": "",
"gradeLevel": "1",
"gradeLevel": gradelevel,
"kind": "Course",
"languageOfInstruction": "English",
"location": "Alberta",
"memberLimit": "20",
"members": [],
"members": memberarr,
"method": "Theory and Practical",
"name": "Course " +course_number,
"startDate": "01/01/2017",
"startTime": "10:00",
"subjectLevel": subjectLevel
});
}

//insert into courses
courses.bulk({"docs":defaultCourses}, function(err, res) {
}
//insert into courses

courses.bulk({"docs":defaultCourses}, function(err, res) {
if (err)
return console.log(err);
else {
course_id = [];
console.log(res.length);
for(var i=0;i<res.length;i++){
course_id.push(res[i].id);
}
for(var i = 0; i < 1; i++){
defaultCoursestep.push({
"courseId": course_id[i],
"description": "This is course step "+ (parseInt(i)+1),
"kind": "Course Step",
"passingPercentage": "30",
"resourceTitles":[],
"resourceId":[],
"questionslist":[],
"step": i+1,
"stepGoals": "Knowledge",
"stepMethod": "Theory",
"title": "Course Step "+ (parseInt(i)+1),
"totalMarks": "100"
});
}
for(var i = 0; i < 1; i++){
defaultResources.push({
"kind": "Resource",
"status": "accepted",
"title": "a",
"author": "a",
"Publisher": "",
"language": "Arabic",
"Year": "a",
"linkToLicense": "",
"subject": [
"Agriculture",
"Arts",
"Business and Finance",
"Environment",
"Food and Nutrition",
"Geography",
"Health and Medicine",
"History",
"Human Development",
"Languages",
"Law",
"Learning",
"Literature",
"Math",
"Music",
"Politics and Government",
"Reference",
"Religion",
"Science",
"Social Sciences",
"Sports",
"Technology"
],
"Level": [
"Early Education",
"Lower Primary",
"Upper Primary",
"Lower Secondary",
"Upper Secondary",
"Undergraduate",
"Graduate",
"Professional"
],
"Tag": null,
"Medium": "Text",
"openWith": "Just download",
"resourceFor": "Default",
"resourceType": "Textbook",
"uploadDate": "2017-09-12T18:15:00.000Z",
"averageRating": "",
"articleDate": "2017-09-12T18:15:00.000Z",
"addedBy": "admin",
"openUrl": "",
"openWhichFile": "",
"sum": 0,
"timesRated": 0
});
}
var resources = nano.db.use('resources');
resources.bulk({"docs":defaultResources}, function(err, body) {
if (err){
return console.log(err);
}else{
defaultCoursestep[0].resourceId.push(body[0].id);
//insert into coursestep
coursestep.insert({"docs":defaultCoursestep[0]},function(err,res){
if(err){
console.log(err);
}else{
defaultCoursestep[0]._id = res.id;
defaultCoursestep[0]._rev = res.rev;
//insert into coursequestion
defaultCoursequestion.push({
"CorrectAnswer": [
"Charles Babbages",
],
"Options": [
"Sachin Maharjan",
"Rupesh Manandhar",
"Charles Babbage",
"Stefan Unchester"
],
"Statement": "What is father of computer" +" ?",
"Type": "Multiple Choice",
"courseId": course_id,
"kind": "coursequestion",
"stepId" : defaultCoursestep[0]._id,
"Marks" : 10
});
defaultCoursequestion.push({
"Statement": "What is programming language"+" ?",
"Type": "Comment/Essay Box",
"courseId": course_id,
"kind": "coursequestion",
"stepId" : defaultCoursestep[0]._id,
"Marks" : 10
});
else{
for(var steps = 0; steps < n_steps; steps++){
for(var courselist = 0; courselist < res.length; courselist++){

defaultCoursequestion.push({
"Statement": "Attach Summer Project" +".",
"Type": "Attachment",
"courseId": course_id,
"kind": "coursequestion",
"stepId" : defaultCoursestep[0]._id,
"Marks" : 10
});
defaultCoursestep.push({
"courseId": res[courselist].id,
"description": "This is course step "+ (steps+1),
"kind": "Course Step",
"passingPercentage": "30",
"resourceTitles":[],
"resourceId":[],
"questionslist":[],
"step": steps+1,
"stepGoals": "Knowledge",
"stepMethod": "Theory",
"title": "Course Step "+ (steps+1),
"totalMarks": "100"
});
}
}
//insert into coursestep
coursestep.bulk({"docs":defaultCoursestep},function(err,res){
if(err){
console.log(err);
}else{
for(var steplist = 0; steplist<res.length; steplist++){
//insert into coursequestion
defaultCoursequestion.push({
"CorrectAnswer": [
"Charles Babbages",
],
"Options": [
"Sachin Maharjan",
"Rupesh Manandhar",
"Charles Babbage",
"Stefan Unchester"
],
"Statement": "What is father of computer" +" ?",
"Type": "Multiple Choice",
"courseId": defaultCoursestep[steplist].courseId,
"kind": "coursequestion",
"stepId" : res[steplist].id,
"Marks" : 10
});
defaultCoursequestion.push({
"Statement": "What is programming language"+" ?",
"Type": "Comment/Essay Box",
"courseId": defaultCoursestep[steplist].courseId,
"kind": "coursequestion",
"stepId" : res[steplist].id,
"Marks" : 10
});

defaultCoursequestion.push({
"Statement": "Attach Summer Project" +".",
"Type": "Attachment",
"courseId": defaultCoursestep[steplist].courseId,
"kind": "coursequestion",
"stepId" : res[steplist].id,
"Marks" : 10
});

defaultCoursequestion.push({
"Statement": "Full form of IDE" +".",
"Type": "Single Textbox",
"courseId": course_id,
"kind": "coursequestion",
"stepId" : defaultCoursestep[0]._id,
"Marks" : 10
});

coursequestion.bulk({"docs":defaultCoursequestion}, function(err, res) {
if (err)
return console.log(err);
else {
//need to update questionlist in coursestep
for(var i = 0; i < defaultCoursequestion.length; i++){
defaultCoursestep[0].questionslist.push(res[i].id)
}
//update coursestep[0]
coursestep.insert(defaultCoursestep[0], function(err, res) {
if (err)
return console.log(err);
else
done();
});
}
});
}
});
defaultCoursequestion.push({
"Statement": "Full form of IDE" +".",
"Type": "Single Textbox",
"courseId": defaultCoursestep[steplist].courseId,
"kind": "coursequestion",
"stepId" : res[steplist].id,
"Marks" : 10
});
}
console.log(defaultCoursequestion)
coursequestion.bulk({"docs":defaultCoursequestion}, function(err, res) {
if (err)
return console.log(err);
else {
done();
}
});
}
});
}
});
});
}
});
}

function done(){
console.log("done");
}
Expand Down

0 comments on commit fdecd78

Please sign in to comment.