Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(AnnotationService): Move getAllLatestScoreAnnotations() to MilestoneReportService #1497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading