Skip to content

Commit

Permalink
refactor(TeacherDataService): Move functions to OneWorkgroupPerRowExp…
Browse files Browse the repository at this point in the history
…ort (#2004)
  • Loading branch information
hirokiterashima authored Nov 26, 2024
1 parent 53912fb commit 1a10293
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
var componentId = component.id;
if (this.exportComponent(selectedNodesMap, nodeId, componentId)) {
var columnIdPrefix = nodeId + '-' + componentId;
var componentState = this.teacherDataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId(
workgroupId,
nodeId,
componentId
);
var componentState =
this.teacherDataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId(
workgroupId,
nodeId,
componentId
);
if (componentState != null) {
if (this.controller.includeStudentWorkIds) {
workgroupRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
Expand All @@ -135,15 +136,15 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
] = formattedDateTime;
}
}
workgroupRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWork']
] = this.getStudentDataString(componentState);
workgroupRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] =
this.getStudentDataString(componentState);
if (this.controller.includeScores || this.controller.includeComments) {
var latestComponentAnnotations = this.annotationService.getLatestComponentAnnotations(
nodeId,
componentId,
workgroupId
);
var latestComponentAnnotations =
this.annotationService.getLatestComponentAnnotations(
nodeId,
componentId,
workgroupId
);
if (latestComponentAnnotations != null) {
var scoreAnnotation = latestComponentAnnotations.score;
var commentAnnotation = latestComponentAnnotations.comment;
Expand All @@ -162,9 +163,8 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
scoreAnnotation.data.value != null
) {
var scoreValue = scoreAnnotation.data.value;
workgroupRow[
columnIdToColumnIndex[columnIdPrefix + '-score']
] = scoreValue;
workgroupRow[columnIdToColumnIndex[columnIdPrefix + '-score']] =
scoreValue;
}
}
}
Expand All @@ -183,9 +183,8 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
commentAnnotation.data.value != null
) {
var commentValue = commentAnnotation.data.value;
workgroupRow[
columnIdToColumnIndex[columnIdPrefix + '-comment']
] = commentValue;
workgroupRow[columnIdToColumnIndex[columnIdPrefix + '-comment']] =
commentValue;
}
}
}
Expand All @@ -200,11 +199,9 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
if (this.projectService.isBranchPoint(nodeId)) {
var toNodeId = null;
var stepTitle = null;
var eventType = 'branchPathTaken';
var latestBranchPathTakenEvent = this.teacherDataService.getLatestEventByWorkgroupIdAndNodeIdAndType(
const latestBranchPathTakenEvent = this.getLatestBranchPathTakenEvent(
workgroupId,
nodeId,
eventType
nodeId
);
if (
latestBranchPathTakenEvent != null &&
Expand All @@ -231,9 +228,8 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
}
if (this.controller.includeBranchPathTakenStepTitle) {
if (stepTitle != null) {
workgroupRow[
columnIdToColumnIndex[nodeId + '-branchPathTakenStepTitle']
] = stepTitle;
workgroupRow[columnIdToColumnIndex[nodeId + '-branchPathTakenStepTitle']] =
stepTitle;
} else {
workgroupRow[columnIdToColumnIndex[nodeId + '-branchPathTakenStepTitle']] = ' ';
}
Expand All @@ -249,6 +245,17 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
});
}

private getLatestBranchPathTakenEvent(workgroupId: number, nodeId: string): any {
const events = this.teacherDataService.getEventsByWorkgroupId(workgroupId);
for (let i = events.length - 1; i >= 0; i--) {
const event = events[i];
if (event.nodeId === nodeId && event.event === 'branchPathTaken') {
return event;
}
}
return null;
}

/**
* Check if we want to export this component
* @param selectedNodesMap a mapping of node id to boolean value of whether
Expand Down Expand Up @@ -434,22 +441,19 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
c + 1;
componentTypeRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
component.type;
componentPromptRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']
] = prompt;
componentPromptRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
prompt;
nodeIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] = nodeId;
componentIdRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']
] = componentId;
componentIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
componentId;
columnIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
columnIdPrefix + '-studentWorkId';
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkId']] =
'Student Work ID';
}
if (this.controller.includeStudentWorkTimestamps) {
stepTitleRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']
] = stepTitle;
stepTitleRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']] =
stepTitle;
componentPartNumberRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']
] = c + 1;
Expand All @@ -459,9 +463,8 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']
] = prompt;
nodeIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']] = nodeId;
componentIdRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']
] = componentId;
componentIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']] =
componentId;
columnIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']] =
columnIdPrefix + '-studentWorkTimestamp';
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-studentWorkTimestamp']] =
Expand All @@ -475,9 +478,8 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
component.type;
componentPromptRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] = prompt;
nodeIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] = nodeId;
componentIdRow[
columnIdToColumnIndex[columnIdPrefix + '-studentWork']
] = componentId;
componentIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] =
componentId;
columnIdRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] =
columnIdPrefix + '-studentWork';
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-studentWork']] =
Expand All @@ -490,13 +492,11 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
c + 1;
componentTypeRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] =
component.type;
componentPromptRow[
columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']
] = prompt;
componentPromptRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] =
prompt;
nodeIdRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] = nodeId;
componentIdRow[
columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']
] = componentId;
componentIdRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] =
componentId;
columnIdRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] =
columnIdPrefix + '-scoreTimestamp';
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-scoreTimestamp']] =
Expand All @@ -514,21 +514,18 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-score']] = 'Score';
}
if (this.controller.includeCommentTimestamps) {
stepTitleRow[
columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']
] = stepTitle;
stepTitleRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
stepTitle;
componentPartNumberRow[
columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']
] = c + 1;
componentTypeRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
component.type;
componentPromptRow[
columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']
] = prompt;
componentPromptRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
prompt;
nodeIdRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] = nodeId;
componentIdRow[
columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']
] = componentId;
componentIdRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
componentId;
columnIdRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
columnIdPrefix + '-commentTimestamp';
descriptionRow[columnIdToColumnIndex[columnIdPrefix + '-commentTimestamp']] =
Expand Down
15 changes: 0 additions & 15 deletions src/assets/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,6 @@ export class TeacherDataService extends DataService {
return this.studentData.eventsByNodeId[nodeId] || [];
}

getLatestEventByWorkgroupIdAndNodeIdAndType(workgroupId, nodeId, eventType) {
const eventsByWorkgroupId = this.getEventsByWorkgroupId(workgroupId);
for (let e = eventsByWorkgroupId.length - 1; e >= 0; e--) {
const event = eventsByWorkgroupId[e];
if (this.isEventMatchingNodeIdEventType(event, nodeId, eventType)) {
return event;
}
}
return null;
}

isEventMatchingNodeIdEventType(event, nodeId, eventType) {
return event.nodeId === nodeId && event.event === eventType;
}

getAnnotationsToWorkgroupId(workgroupId: number) {
return this.studentData.annotationsToWorkgroupId[workgroupId] || [];
}
Expand Down

0 comments on commit 1a10293

Please sign in to comment.