Skip to content

Commit

Permalink
refactor(DataService): add modifiers and remove unused code (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Dec 20, 2024
1 parent 867d8a2 commit f4e35e2
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent {
protected annotationService: AnnotationService,
protected classroomStatusService: ClassroomStatusService,
protected configService: ConfigService,
protected dataService: TeacherDataService,
protected dialog: MatDialog,
protected milestoneService: MilestoneService,
protected notificationService: NotificationService,
protected peerGroupService: TeacherPeerGroupService,
protected projectService: TeacherProjectService,
protected teacherDataService: TeacherDataService
protected projectService: TeacherProjectService
) {
super(
annotationService,
classroomStatusService,
configService,
dataService,
dialog,
milestoneService,
notificationService,
peerGroupService,
projectService,
teacherDataService
projectService
);
}

Expand All @@ -57,9 +57,8 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent {
this.node = this.projectService.getNode(this.nodeId);
if (this.milestone.report.locations.length > 1) {
this.firstNodeId = this.milestone.report.locations[0].nodeId;
this.lastNodeId = this.milestone.report.locations[
this.milestone.report.locations.length - 1
].nodeId;
this.lastNodeId =
this.milestone.report.locations[this.milestone.report.locations.length - 1].nodeId;
}
this.componentId = this.milestone.componentId;
this.retrieveStudentData();
Expand Down Expand Up @@ -131,15 +130,7 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent {
componentType = null,
category = 'Navigation',
data = { milestoneId: this.milestone.id };
this.teacherDataService.saveEvent(
context,
nodeId,
componentId,
componentType,
category,
event,
data
);
this.dataService.saveEvent(context, nodeId, componentId, componentType, category, event, data);
}

onUpdateExpand({ workgroupId, value }): void {
Expand Down Expand Up @@ -185,15 +176,7 @@ export class MilestoneGradingViewComponent extends NodeGradingViewComponent {
componentType = null,
category = 'Navigation',
data = { milestoneId: this.milestone.id, workgroupId: workgroupId };
this.teacherDataService.saveEvent(
context,
nodeId,
componentId,
componentType,
category,
event,
data
);
this.dataService.saveEvent(context, nodeId, componentId, componentType, category, event, data);
}

protected sortWorkgroups(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export class NodeGradingViewComponent implements OnInit {
protected annotationService: AnnotationService,
protected classroomStatusService: ClassroomStatusService,
protected configService: ConfigService,
protected dataService: TeacherDataService,
protected dialog: MatDialog,
protected milestoneService: MilestoneService,
protected notificationService: NotificationService,
protected peerGroupService: TeacherPeerGroupService,
protected projectService: TeacherProjectService,
protected teacherDataService: TeacherDataService
protected projectService: TeacherProjectService
) {}

ngOnInit(): void {
Expand All @@ -66,7 +66,7 @@ export class NodeGradingViewComponent implements OnInit {
this.maxScore = this.getMaxScore();
this.node = this.projectService.getNode(this.nodeId);
this.nodeHasWork = this.projectService.nodeHasWork(this.nodeId);
this.sort = this.teacherDataService.nodeGradingSort;
this.sort = this.dataService.nodeGradingSort;
this.nodeContent = this.projectService.getNodeById(this.nodeId);
this.milestoneReport = this.milestoneService.getMilestoneReportByNodeId(this.nodeId);
this.peerGroupingTags = Array.from(this.peerGroupService.getPeerGroupingTags(this.node));
Expand Down Expand Up @@ -113,7 +113,7 @@ export class NodeGradingViewComponent implements OnInit {
);

this.subscriptions.add(
this.teacherDataService.studentWorkReceived$.subscribe(({ studentWork }) => {
this.dataService.studentWorkReceived$.subscribe(({ studentWork }) => {
const workgroupId = studentWork.workgroupId;
if (studentWork.nodeId === this.nodeId && this.workgroupsById[workgroupId]) {
this.updateWorkgroup(workgroupId);
Expand All @@ -122,14 +122,14 @@ export class NodeGradingViewComponent implements OnInit {
);

this.subscriptions.add(
this.teacherDataService.currentPeriodChanged$.subscribe(() => {
this.dataService.currentPeriodChanged$.subscribe(() => {
this.milestoneReport = this.milestoneService.getMilestoneReportByNodeId(this.nodeId);
})
);
}

protected retrieveStudentData(node: Node = this.node): void {
this.teacherDataService.retrieveStudentDataForNode(node).subscribe(() => {
this.dataService.retrieveStudentDataForNode(node).subscribe(() => {
this.teacherWorkgroupId = this.configService.getWorkgroupId();
this.workgroups = copy(this.configService.getClassmateUserInfos()).filter(
(workgroup) =>
Expand Down Expand Up @@ -298,7 +298,7 @@ export class NodeGradingViewComponent implements OnInit {
}

private getLatestWorkTimeByWorkgroupId(workgroupId: number): string {
const componentStates = this.teacherDataService.getComponentStatesByNodeId(this.nodeId);
const componentStates = this.dataService.getComponentStatesByNodeId(this.nodeId);
for (const componentState of componentStates.reverse()) {
if (componentState.workgroupId === workgroupId) {
return componentState.serverSaveTime;
Expand All @@ -308,7 +308,7 @@ export class NodeGradingViewComponent implements OnInit {
}

private getLatestAnnotationTimeByWorkgroupId(workgroupId: number): string {
const annotations = this.teacherDataService.getAnnotationsByNodeId(this.nodeId);
const annotations = this.dataService.getAnnotationsByNodeId(this.nodeId);
for (const annotation of annotations.reverse()) {
// TODO: support checking for annotations from shared teachers
if (
Expand Down Expand Up @@ -346,14 +346,14 @@ export class NodeGradingViewComponent implements OnInit {
getNodeCompletion(nodeId: string): number {
return this.classroomStatusService.getNodeCompletion(
nodeId,
this.teacherDataService.getCurrentPeriodId()
this.dataService.getCurrentPeriodId()
).completionPct;
}

getNodeAverageScore(): any {
const averageScore = this.classroomStatusService.getNodeAverageScore(
this.nodeId,
this.teacherDataService.getCurrentPeriodId()
this.dataService.getCurrentPeriodId()
);
if (averageScore === null) {
return 'N/A';
Expand All @@ -363,7 +363,7 @@ export class NodeGradingViewComponent implements OnInit {
}

isWorkgroupShown(workgroup: any): boolean {
return this.teacherDataService.isWorkgroupShown(workgroup);
return this.dataService.isWorkgroupShown(workgroup);
}

protected showRubric(): void {
Expand All @@ -379,7 +379,7 @@ export class NodeGradingViewComponent implements OnInit {
} else {
this.sort = value;
}
this.teacherDataService.nodeGradingSort = this.sort;
this.dataService.nodeGradingSort = this.sort;
this.sortWorkgroups();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export abstract class AbstractComponentDataExportStrategy extends AbstractDataEx
protected abstract getComponentTypeWithUnderscore(): string;

protected getComponentStates(component: any): ComponentState[] {
let componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
let componentStates = this.dataService.getComponentStatesByComponentId(component.id);
this.sortByWorkgroupIdAndTimestamp(componentStates);
this.calculateRevisionNumbers(componentStates);
if (this.allOrLatest === 'latest') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class AbstractDataExportStrategy implements DataExportStrategy {
dataExportService: DataExportService;
projectService: TeacherProjectService;
protected allOrLatest: 'all' | 'latest' = 'all';
teacherDataService: TeacherDataService;
dataService: TeacherDataService;

setDataExportContext(context: DataExportContext) {
this.context = context;
Expand All @@ -26,7 +26,7 @@ export abstract class AbstractDataExportStrategy implements DataExportStrategy {
this.configService = context.controller.configService;
this.dataExportService = context.controller.dataExportService;
this.projectService = context.controller.projectService;
this.teacherDataService = context.controller.dataService;
this.dataService = context.controller.dataService;
}

abstract export();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DialogGuidanceComponentDataExportStrategy extends AbstractComponent

private addDialogGuidanceSpecificHeaderColumns(component: any, headerRow: string[]): void {
headerRow.push(this.itemIdLabel);
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
const componentStates = this.dataService.getComponentStatesByComponentId(component.id);
const ideaNames = this.getIdeaNames(componentStates);
const scoreNames = this.getScoreNames(componentStates);
for (let i = 1; i <= this.getMaxNumberOfStudentResponses(componentStates); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class DiscussionComponentDataExportStrategy extends AbstractComponentData
nodeId: string
) {
const rows = [];
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
const componentStates = this.dataService.getComponentStatesByComponentId(component.id);
const structuredPosts = this.getStructuredPosts(componentStates);
let rowCounter = 1;
for (let threadId of Object.keys(structuredPosts)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ExportStrategyTester {
studentWorkTimestamp2 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds2);
studentWorkTimestamp3 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds3);
studentWorkTimestamp4 = millisecondsToDateTime(this.studentWorkTimestampMilliseconds4);
teacherDataService: TeacherDataService;
dataService: TeacherDataService;
teacherProjectService: TeacherProjectService;
teacherWebSocketService: TeacherWebSocketService = new TeacherWebSocketService(
null,
Expand Down Expand Up @@ -117,10 +117,10 @@ export class ExportStrategyTester {
}

setUpTeacherDataService(): void {
this.teacherDataService = new TeacherDataService(
null,
this.dataService = new TeacherDataService(
this.annotationService,
this.configService,
null,
this.teacherProjectService,
this.teacherWebSocketService
);
Expand All @@ -138,15 +138,15 @@ export class ExportStrategyTester {
this.componentExportStrategy.configService = this.configService;
this.componentExportStrategy.dataExportService = this.dataExportService;
this.componentExportStrategy.projectService = this.teacherProjectService;
this.componentExportStrategy.teacherDataService = this.teacherDataService;
this.componentExportStrategy.dataService = this.dataService;
}

createDataExportComponent(): any {
const controller = new ExportItemComponent(
this.annotationService,
this.configService,
this.dataExportService,
this.teacherDataService,
this.dataService,
null,
this.teacherProjectService,
null,
Expand All @@ -159,7 +159,7 @@ export class ExportStrategyTester {
}

setStudentData(componentStates: any[]): void {
this.teacherDataService.processComponentStates(componentStates);
this.dataService.processComponentStates(componentStates);
}

setAnnotations(annotations: any[]): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class LabelComponentDataExportStrategy extends AbstractComponentDataExpor

protected generateComponentHeaderRow(component: any): string[] {
const headerRow = [...this.defaultColumnNames];
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
const componentStates = this.dataService.getComponentStatesByComponentId(component.id);
const maxCountLabel = this.getMaxLabelCount(componentStates);
for (let i = 1; i <= maxCountLabel; i++) {
headerRow.push(`Label ${i}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra
if (this.exportComponent(selectedNodesMap, nodeId, componentId)) {
var columnIdPrefix = nodeId + '-' + componentId;
var componentState =
this.teacherDataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId(
this.dataService.getLatestComponentStateByWorkgroupIdNodeIdAndComponentId(
workgroupId,
nodeId,
componentId
Expand Down Expand Up @@ -247,7 +247,7 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra

private getLatestBranchPathTakenEvent(workgroupId: number, nodeId: string): any {
return (
this.teacherDataService
this.dataService
.getEventsByWorkgroupId(workgroupId)
.findLast((event) => event.nodeId === nodeId && event.event === 'branchPathTaken') ?? null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PeerChatComponentDataExportStrategy extends AbstractComponentDataEx

protected generateComponentHeaderRow(component: any): string[] {
const headerRow = [...this.defaultColumnNames];
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
const componentStates = this.dataService.getComponentStatesByComponentId(component.id);
this.insertPromptColumns(headerRow, component);
this.insertQuestionColumns(headerRow, component, componentStates);
return headerRow;
Expand Down Expand Up @@ -110,7 +110,7 @@ export class PeerChatComponentDataExportStrategy extends AbstractComponentDataEx
columnNameToNumber: any,
nodeId: string
): any[] {
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
const componentStates = this.dataService.getComponentStatesByComponentId(component.id);
const sortedComponentStates = this.sortByPeerGroupIdAndTimestamp(componentStates);
const workRows = [];
for (let r = 0; r < sortedComponentStates.length; r++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy {
var workgroupId = workgroup.workgroupId;
if (this.controller.includeStudentWork) {
workgroup.studentWork = [];
var componentStates = this.teacherDataService.getComponentStatesByWorkgroupId(
workgroupId
);
var componentStates = this.dataService.getComponentStatesByWorkgroupId(workgroupId);
if (componentStates != null) {
for (var c = 0; c < componentStates.length; c++) {
var componentState = componentStates[c];
Expand All @@ -59,7 +57,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy {
}
if (this.controller.includeAnnotations) {
workgroup.annotations = [];
var annotations = this.teacherDataService.getAnnotationsToWorkgroupId(workgroupId);
var annotations = this.dataService.getAnnotationsToWorkgroupId(workgroupId);
if (annotations != null) {
for (var a = 0; a < annotations.length; a++) {
var annotation = annotations[a];
Expand All @@ -77,7 +75,7 @@ export class RawDataExportStrategy extends AbstractDataExportStrategy {
}
if (this.controller.includeEvents) {
workgroup.events = [];
var events = this.teacherDataService.getEventsByWorkgroupId(workgroupId);
var events = this.dataService.getEventsByWorkgroupId(workgroupId);
if (events != null) {
for (var e = 0; e < events.length; e++) {
var event = events[e];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy {
var componentRevisionCounter = {};
let componentStates = [];
if (this.exportType === 'allStudentWork') {
componentStates = this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId);
componentStates = this.dataService.getComponentStatesByWorkgroupId(workgroupId);
} else if (this.exportType === 'latestStudentWork') {
this.injectRevisionCounterIntoComponentStates(
this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId)
this.dataService.getComponentStatesByWorkgroupId(workgroupId)
);
componentStates = this.getLatestComponentStatesByWorkgroupId(workgroupId);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ export class StudentWorkDataExportStrategy extends AbstractDataExportStrategy {
const componentStates = [];
const componentsFound = {};
const componentStatesForWorkgroup =
this.teacherDataService.getComponentStatesByWorkgroupId(workgroupId);
this.dataService.getComponentStatesByWorkgroupId(workgroupId);
for (let csb = componentStatesForWorkgroup.length - 1; csb >= 0; csb--) {
const componentState = componentStatesForWorkgroup[csb];
const key = componentState.nodeId + '-' + componentState.componentId;
Expand Down
Loading

0 comments on commit f4e35e2

Please sign in to comment.