Skip to content

Commit

Permalink
refactor(Classroom Monitor): Clean up getStudentProjectCompletion() (#…
Browse files Browse the repository at this point in the history
…1490)

* refactor(Classroom Monitor): Clean up getStudentProjectCompletion()

* refactor(Classroom Monitor): Remove function accidentally left in

* refactor(Classroom Monitor): Remove unnecessary function
  • Loading branch information
geoffreykwan authored Oct 26, 2023
1 parent 19829fa commit fe3cf2b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/assets/wise5/common/ProjectCompletion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ProjectCompletion {
completedItems: number;
completionPct: number;
totalItems: number;
}
97 changes: 20 additions & 77 deletions src/assets/wise5/services/classroomStatusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit fe3cf2b

Please sign in to comment.