Skip to content

Commit

Permalink
refactor(AnnotationService): ove getAllLatestScoreAnnotations to
Browse files Browse the repository at this point in the history
MilestoneReportService

Also rewrite function using filter() and reduceRight()
  • Loading branch information
hirokiterashima committed Oct 27, 2023
1 parent 1335466 commit fa16f6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
20 changes: 0 additions & 20 deletions src/assets/wise5/services/annotationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,26 +640,6 @@ export class AnnotationService {
return this.annotations.filter((annotation) => annotation.studentWorkId === studentWorkId);
}

getAllLatestScoreAnnotations(nodeId, componentId, periodId) {
const workgroupIdsFound = {};
const latestScoreAnnotations = [];
for (let a = this.annotations.length - 1; a >= 0; a--) {
const annotation = this.annotations[a];
const workgroupId = annotation.toWorkgroupId;
if (
workgroupIdsFound[workgroupId] == null &&
nodeId === annotation.nodeId &&
componentId === annotation.componentId &&
(periodId === -1 || periodId === annotation.periodId) &&
('score' === annotation.type || 'autoScore' === annotation.type)
) {
workgroupIdsFound[workgroupId] = annotation;
latestScoreAnnotations.push(annotation);
}
}
return latestScoreAnnotations;
}

broadcastAnnotationSavedToServer(annotation: Annotation): void {
this.annotationSavedToServerSource.next(annotation);
}
Expand Down
31 changes: 26 additions & 5 deletions src/assets/wise5/services/milestoneReportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
import { AnnotationService } from './annotationService';
import { ProjectService } from './projectService';
import { MilestoneCriteriaEvaluator } from '../classroomMonitor/milestones/milestoneCriteriaEvaluator';
import { Annotation } from '../common/Annotation';
import { isMatchingPeriods } from '../common/period/period';

@Injectable()
export class MilestoneReportService {
Expand Down Expand Up @@ -72,11 +74,7 @@ export class MilestoneReportService {
reportSettings: any
) {
const aggregate = {};
const scoreAnnotations = this.annotationService.getAllLatestScoreAnnotations(
nodeId,
componentId,
periodId
);
const scoreAnnotations = this.getAllLatestScoreAnnotations(nodeId, componentId, periodId);
for (const scoreAnnotation of scoreAnnotations) {
if (scoreAnnotation.type === 'autoScore') {
this.addDataToAggregate(aggregate, scoreAnnotation, reportSettings);
Expand All @@ -100,6 +98,29 @@ export class MilestoneReportService {
return aggregate;
}

private getAllLatestScoreAnnotations(
nodeId: string,
componentId: string,
periodId: number
): Annotation[] {
return this.annotationService
.getAnnotationsByNodeIdComponentId(nodeId, componentId)
.filter(
(annotation) =>
isMatchingPeriods(annotation.periodId, periodId) &&
['autoScore', 'score'].includes(annotation.type)
)
.reduceRight(
(latestAnnotations, annotation) =>
latestAnnotations.some(
(latestAnnotation) => latestAnnotation.toWorkgroupId === annotation.toWorkgroupId
)
? latestAnnotations
: latestAnnotations.concat(annotation),
[]
);
}

private mergeAutoScoreAndTeacherScore(
autoScoreAnnotation: any,
teacherScoreAnnotation: any,
Expand Down

0 comments on commit fa16f6e

Please sign in to comment.