Skip to content

Commit

Permalink
fix Grading For Groupmates logic
Browse files Browse the repository at this point in the history
  • Loading branch information
khengyun committed May 17, 2023
1 parent 896f4d3 commit 1a15a93
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 122 deletions.
147 changes: 68 additions & 79 deletions background_script/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ console.log("background.js");
importScripts("api.js");
importScripts("helpui.js");
update_api();
function grade_teammates(params, privateCqId, classroomSessionId, groupId) {

function grade_teammates(groups, privateCqId, classroomSessionId, groupId) {
console.log('groupsooo: ', groups)
// console.log(params);
const ans = post_api({
url: `${API.grade_teammates}`,
body: {
gradeTeammatesList: format_grade_teammates(
params,
groups,
privateCqId,
classroomSessionId,
groupId
Expand All @@ -20,113 +22,96 @@ function grade_teammates(params, privateCqId, classroomSessionId, groupId) {
// console.log(data);
})
.catch((e) => {
console.log("catch: ",{
gradeTeammatesList: format_grade_teammates(
groups,
privateCqId,
classroomSessionId,
groupId
),
});
console.log({
error: `${e}`,
message: `${API.grade_teammates}`,
});
});
}

function get_grade(params) {
function get_grade(params,groups) {
// param = {"privateCqId":privateCqId,"sessionId":sessionId,"groupId":groupID}

const ans = post_api({
url: `${API.get_grade}`,
body: {
privateCqId: params.privateCqId,
groupId: params.groupId,
},
});
ans
.then((data) => {
if (data.data.gradeResponseList.length != 0) {
// console.log(params.privateCqId, params.sessionId, params.groupId);
// console.log(data.data);

privateCqId = params.privateCqId;
sessionId = params.sessionId;
groupId = params.groupId;
grade_teammates(
data.data.gradeResponseList,
privateCqId,
sessionId,
groupId
);
}
})
.catch((e) => {
console.log({
error: `${e}`,
message: `${API.get_grade}`,
});
});
privateCqId = params.privateCqId;
sessionId = params.sessionId;
groupId = params.groupId;
console.log("get_grade: ",groups,params)
grade_teammates(
groups,
privateCqId,
sessionId,
groupId
);

}

// This function lists all the groups in a classroom.
// Iterate over all the courses in the USER_COURSE array.
function list_group() {
for (let i = 0; i < USER_COURSE.length; i++) {
function list_group(params) {
console.log("some thing here")
// Get the current course.
const element = USER_COURSE[i];
const element = params;

// Iterate over all the courses in the current course.
for (let j = 0; j < element.courseList.length; j++) {
// Get the current course.
const element2 = element.courseList[j];
var course = element.courseList[j];

// Get the classroom session ID for the current course.
classroomSessionId = element2.classroomSessionId;
classroomSessionId = course.classroomSessionId;

// Iterate over all the questions in the current course.
for (let k = 0; k < element2.questions.length; k++) {
for (let k = 0; k < course.questions.length; k++) {
// console.log(element2.questions[k]);
const privateCqId = element2.questions[k].privateCqId;
const sessionId = element2.questions[k].sessionId;
const privateCqId = course.questions[k].privateCqId;
const sessionId = course.questions[k].sessionId;

// Post a request to the API to get the list of groups for the current course.
const ans = post_api({
url: `${API.list_group}${element2.classroomSessionId}`,
url: `${API.list_group}${course.classroomSessionId}`,
});

// Handle the response from the API.
ans
.then((data) => {
.then((groups) => {



get_grade({
privateCqId: privateCqId,
sessionId: sessionId,
groupId: 12345678,
},groups);





// Iterate over the groups in the response.
for (let k = 0; k < data.length; k++) {
// Get the current group.
const element3 = data[k];
const groupID = element3.id;
// console.log(groupID)
if (check_group_user(element3)) {
// console.log(element3);

get_grade({
privateCqId: privateCqId,
sessionId: sessionId,
groupId: groupID,
});
}

}

}).then(()=>{

})
.catch((e) => {
console.log({
error: `${e}`,
message: `${API.list_group}${element2.classroomSessionId}`,
message: `${API.list_group}${course.classroomSessionId}`,
});
});
}
}
}

}

function course_detail(params) {
//load course detail

if (USER_CLASS.length == USER_COURSE.length) {
// question_detail()
list_group();
} else {
for (let i = 0; i < USER_CLASS.length; i++) {
const element = USER_CLASS[i];
const ans = get_api({
Expand All @@ -135,8 +120,9 @@ function course_detail(params) {
ans
.then((data) => {
// console.log(data.data)
console.log(USER_CLASS.length >= USER_COURSE.length , check_course_list(USER_CLASS[i].id) )
if (
USER_CLASS.length > USER_COURSE.length &&
USER_CLASS.length >= USER_COURSE.length &&
check_course_list(USER_CLASS[i].id) == false
) {
let format = {
Expand All @@ -147,26 +133,26 @@ function course_detail(params) {
courseId: USER_CLASS[i].courseId,
courseList: question_format(data.data),
};
USER_COURSE.push(format);
if (USER_CLASS.length == USER_COURSE.length) {
// question_detail()
list_group();
}
}
if (USER_CLASS.length == USER_COURSE.length) {
// question_detail()
list_group();
USER_COURSE.push(format);
}
// console.log(USER_COURSE);
})
.then(() => {
// question_detail()
console.log("log here")
console.log(USER_COURSE)
list_group(USER_COURSE[i]);
console.log("haha")
})
.catch((e) => {
console.log({
error: `${e}`,
message: `${API.course_detail[0]}${element.id}${API.course_detail[1]}`,
});
});
}) ;
}
}


}

function class_infor() {
Expand All @@ -178,8 +164,10 @@ function class_infor() {
ans
.then((data) => {
// console.log(data.data)
if (USER_CLASS.length <= 2) {
USER_CLASS.push(data.data);
course_detail();
}
})
.catch((e) => {
console.log({
Expand Down Expand Up @@ -225,6 +213,7 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
console.log(USER_INFOR);

subjects_in_the_semester("DEFAULT");
//background

// send mess from background script to popup script
messtopopup({ type: "background", message: USER_INFOR });
Expand Down
Loading

0 comments on commit 1a15a93

Please sign in to comment.