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(StudentWorkDataExportStrategy, TeacherDataService): move and simplify logic for component state retrieval #2013

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
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy {
if (this.exportType === 'allStudentWork') {
componentStates = this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId);
} else if (this.exportType === 'latestStudentWork') {
this.teacherDataService.injectRevisionCounterIntoComponentStates(
this.injectRevisionCounterIntoComponentStates(
this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId)
);
componentStates =
this.teacherDataService.getLatestComponentStatesByWorkgroupId(workgroupId);
componentStates = this.getLatestComponentStatesByWorkgroupId(workgroupId);
}
if (componentStates != null) {
for (var c = 0; c < componentStates.length; c++) {
Expand Down Expand Up @@ -151,6 +150,40 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy {
});
}

private injectRevisionCounterIntoComponentStates(componentStates: any[]): void {
const componentRevisionCounter = {};
componentStates.forEach((componentState) => {
const key = componentState.nodeId + '-' + componentState.componentId;
if (componentRevisionCounter[key] == null) {
componentRevisionCounter[key] = 1;
}
componentState.revisionCounter = componentRevisionCounter[key];
componentRevisionCounter[key]++;
});
}

/**
* @param workgroupId the workgroup id
* @return An array of component states. Each component state will be the latest component state
* for a component.
*/
private getLatestComponentStatesByWorkgroupId(workgroupId: number): any[] {
const componentStates = [];
const componentsFound = {};
const componentStatesForWorkgroup =
this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId);
for (let csb = componentStatesForWorkgroup.length - 1; csb >= 0; csb--) {
const componentState = componentStatesForWorkgroup[csb];
const key = componentState.nodeId + '-' + componentState.componentId;
if (componentsFound[key] == null) {
componentStates.push(componentState);
componentsFound[key] = true;
}
}
componentStates.reverse();
return componentStates;
}

/**
* Create the array that will be used as a row in the student work export
* @param columnNames all the header column name
Expand Down
38 changes: 0 additions & 38 deletions src/assets/wise5/services/teacherDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,44 +430,6 @@ export class TeacherDataService extends DataService {
return getIntersectOfArrays(componentStatesByWorkgroupId, componentStatesByNodeId);
}

/**
* @param workgroupId the workgroup id
* @return An array of component states. Each component state will be the latest component state
* for a component.
*/
getLatestComponentStatesByWorkgroupId(workgroupId) {
const componentStates = [];
const componentsFound = {};
const componentStatesForWorkgroup = this.getComponentStatesByWorkgroupId(workgroupId);
for (let csb = componentStatesForWorkgroup.length - 1; csb >= 0; csb--) {
const componentState = componentStatesForWorkgroup[csb];
const key = this.getComponentStateNodeIdComponentIdKey(componentState);
if (componentsFound[key] == null) {
componentStates.push(componentState);
componentsFound[key] = true;
}
}
componentStates.reverse();
return componentStates;
}

injectRevisionCounterIntoComponentStates(componentStates) {
const componentRevisionCounter = {};
for (const componentState of componentStates) {
const key = this.getComponentStateNodeIdComponentIdKey(componentState);
if (componentRevisionCounter[key] == null) {
componentRevisionCounter[key] = 1;
}
const revisionCounter = componentRevisionCounter[key];
componentState.revisionCounter = revisionCounter;
componentRevisionCounter[key] = revisionCounter + 1;
}
}

getComponentStateNodeIdComponentIdKey(componentState) {
return componentState.nodeId + '-' + componentState.componentId;
}

getComponentStatesByWorkgroupIdAndComponentId(workgroupId, componentId) {
const componentStatesByWorkgroupId = this.getComponentStatesByWorkgroupId(workgroupId);
const componentStatesByComponentId = this.getComponentStatesByComponentId(componentId);
Expand Down
Loading