diff --git a/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts b/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts index 9941423e2f5..60156b4fa83 100644 --- a/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts +++ b/src/assets/wise5/classroomMonitor/student-grading/student-grading.component.ts @@ -70,8 +70,7 @@ export class StudentGradingComponent implements OnInit { this.maxScore = maxScore ? maxScore : 0; this.totalScore = this.dataService.getTotalScoreByWorkgroupId(this.workgroupId); this.projectCompletion = this.classroomStatusService.getStudentProjectCompletion( - this.workgroupId, - true + this.workgroupId ); this.nodeIds = this.projectService.getFlattenedProjectAsNodeIds(); this.setNodesById(); diff --git a/src/assets/wise5/classroomMonitor/student-progress/student-progress.component.ts b/src/assets/wise5/classroomMonitor/student-progress/student-progress.component.ts index fd40e0937ad..bbcd180f005 100644 --- a/src/assets/wise5/classroomMonitor/student-progress/student-progress.component.ts +++ b/src/assets/wise5/classroomMonitor/student-progress/student-progress.component.ts @@ -53,7 +53,9 @@ export class StudentProgressComponent implements OnInit { private initializeStudents(): void { this.teams = []; - const workgroups = this.configService.getClassmateUserInfos(); + const workgroups = this.configService + .getClassmateUserInfos() + .filter((workgroup: any) => workgroup.workgroupId != null); for (const workgroup of workgroups) { const workgroupId = workgroup.workgroupId; const displayNames = this.configService.getDisplayUsernamesByWorkgroupId(workgroupId); @@ -71,7 +73,7 @@ export class StudentProgressComponent implements OnInit { private updateTeam(workgroupId: number): void { const location = this.getCurrentNodeForWorkgroupId(workgroupId); - const completion = this.getStudentProjectCompletion(workgroupId); + const completion = this.classroomStatusService.getStudentProjectCompletion(workgroupId); const score = this.getStudentTotalScore(workgroupId); let maxScore = this.classroomStatusService.getMaxScoreForWorkgroupId(workgroupId); maxScore = maxScore ? maxScore : 0; @@ -93,15 +95,6 @@ export class StudentProgressComponent implements OnInit { ); } - /** - * Get project completion data for the given workgroup (only include nodes with student work) - * @param workgroupId the workgroup id - * @return object with completed, total, and percent completed (integer between 0 and 100) - */ - private getStudentProjectCompletion(workgroupId: number): any { - return this.classroomStatusService.getStudentProjectCompletion(workgroupId, true); - } - private getStudentTotalScore(workgroupId: number): number { return this.dataService.getTotalScoreByWorkgroupId(workgroupId); } diff --git a/src/assets/wise5/common/ProjectCompletion.ts b/src/assets/wise5/common/ProjectCompletion.ts new file mode 100644 index 00000000000..6f17890dd54 --- /dev/null +++ b/src/assets/wise5/common/ProjectCompletion.ts @@ -0,0 +1,5 @@ +export class ProjectCompletion { + completedItems: number; + completionPct: number; + totalItems: number; +} diff --git a/src/assets/wise5/services/classroomStatusService.ts b/src/assets/wise5/services/classroomStatusService.ts index 186462e2544..8d7a6eba37c 100644 --- a/src/assets/wise5/services/classroomStatusService.ts +++ b/src/assets/wise5/services/classroomStatusService.ts @@ -4,6 +4,8 @@ import { AnnotationService } from './annotationService'; import { ConfigService } from './configService'; import { ProjectService } from './projectService'; import { Observable, Subject, tap } from 'rxjs'; +import { NodeProgress } from '../common/NodeProgress'; +import { ProjectCompletion } from '../common/ProjectCompletion'; @Injectable() export class ClassroomStatusService { @@ -64,16 +66,11 @@ export class ClassroomStatusService { } getStudentStatusForWorkgroupId(workgroupId: number): any { - const studentStatuses = this.getStudentStatuses(); - for (let tempStudentStatus of studentStatuses) { - if (tempStudentStatus != null) { - const tempWorkgroupId = tempStudentStatus.workgroupId; - if (workgroupId === tempWorkgroupId) { - return tempStudentStatus; - } - } - } - return null; + return ( + this.getStudentStatuses().find( + (studentStatus) => studentStatus.workgroupId === workgroupId + ) || null + ); } hasStudentStatus(workgroupId: number): boolean { @@ -96,79 +93,25 @@ export class ClassroomStatusService { } } - /** - * Get the student project completion data by workgroup id - * @param workgroupId the workgroup id - * @param excludeNonWorkNodes boolean whether to exclude nodes without - * @returns object with completed, total, and percent completed (integer - * between 0 and 100) - */ - getStudentProjectCompletion(workgroupId, excludeNonWorkNodes) { - let completion = { - totalItems: 0, - completedItems: 0, - completionPct: 0 - }; - - // get the student status for the workgroup - let studentStatus = this.getStudentStatusForWorkgroupId(workgroupId); - + getStudentProjectCompletion(workgroupId: number): ProjectCompletion { + let completion: ProjectCompletion = new ProjectCompletion(); + const studentStatus = this.getStudentStatusForWorkgroupId(workgroupId); if (studentStatus) { - let projectCompletion = studentStatus.projectCompletion; - - if (projectCompletion) { - if (excludeNonWorkNodes) { - // we're only looking for completion of nodes with work - let completionPctWithWork = projectCompletion.completionPctWithWork; - - if (completionPctWithWork) { - completion.totalItems = projectCompletion.totalItemsWithWork; - completion.completedItems = projectCompletion.completedItemsWithWork; - completion.completionPct = projectCompletion.completionPctWithWork; - } else { - /* - * we have a legacy projectCompletion object that only includes information for all nodes - * so we need to calculate manually - */ - completion = this.getNodeCompletion('group0', -1, workgroupId, true); - } - } else { - completion = projectCompletion; - } + const projectCompletion = studentStatus.projectCompletion; + const completionPctWithWork = projectCompletion.completionPctWithWork; + if (completionPctWithWork) { + completion.totalItems = projectCompletion.totalItemsWithWork; + completion.completedItems = projectCompletion.completedItemsWithWork; + completion.completionPct = projectCompletion.completionPctWithWork; + } else { + // we have a legacy projectCompletion object that only includes information for all nodes so + // we need to calculate completion manually + completion = this.getNodeCompletion('group0', -1, workgroupId, true); } } return completion; } - /** - * Get the workgroups on a node in the given period - * @param nodeId the node id - * @param periodId the period id. pass in -1 to select all periods. - * @returns an array of workgroup ids on a node in a period - */ - getWorkgroupIdsOnNode(nodeId, periodId) { - let workgroupIds = []; - let studentStatuses = this.studentStatuses; - for (let studentStatus of studentStatuses) { - if (studentStatus != null) { - if (periodId === -1 || periodId === studentStatus.periodId) { - let currentNodeId = studentStatus.currentNodeId; - if (nodeId === currentNodeId) { - workgroupIds.push(studentStatus.workgroupId); - } else if (this.projectService.isGroupNode(nodeId)) { - let currentNode = this.projectService.getNodeById(currentNodeId); - let group = this.projectService.getNodeById(nodeId); - - if (this.projectService.isNodeDescendentOfGroup(currentNode, group)) { - workgroupIds.push(studentStatus.workgroupId); - } - } - } - } - } - return workgroupIds; - } - /** * Get node completion info for the given parameters * @param nodeId the node id