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

feat(Export): Include Question Used column in Peer Chat export #1483

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Changes from 3 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 @@ -25,7 +25,6 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat
'Component Part Number',
'Step Title',
'Component Type',
'Component Prompt',
'Response'
];

Expand All @@ -52,46 +51,68 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat
private generateComponentHeaderRow(component: any, columnNameToNumber: any): string[] {
const headerRow = this.defaultColumnNames.map((columnName: string) => columnName);
const componentStates = this.teacherDataService.getComponentStatesByComponentId(component.id);
this.insertPromptColumnIfNecessary(headerRow, component);
this.insertPrePromptColumnIfNecessary(headerRow, component);
this.insertDynamicPromptColumnIfNecessary(headerRow, componentStates);
this.insertDynamicPromptColumnIfNecessary(headerRow, component);
this.insertPostPromptColumnIfNecessary(headerRow, component);
this.insertQuestionColumnsIfNecessary(headerRow, componentStates);
this.insertQuestionUsedColumnIfNecessary(headerRow, component);
this.populateColumnNameMappings(headerRow, columnNameToNumber);
return headerRow;
}

private insertPromptColumnIfNecessary(headerRow: string[], component: any): void {
if (!this.hasDynamicPrompt(component)) {
this.insertBeforeResponseColumn(headerRow, 'Prompt');
}
}

private insertPrePromptColumnIfNecessary(headerRow: string[], component: any): void {
if (this.hasPrePrompt(component)) {
headerRow.splice(headerRow.indexOf('Response'), 0, 'Pre Prompt');
this.insertBeforeResponseColumn(headerRow, 'Pre Prompt');
}
}

private insertDynamicPromptColumnIfNecessary(headerRow: string[], componentStates: any[]): void {
if (this.hasDynamicPrompt(componentStates)) {
headerRow.splice(headerRow.indexOf('Response'), 0, 'Dynamic Prompt');
private insertDynamicPromptColumnIfNecessary(headerRow: string[], component: any): void {
if (this.hasDynamicPrompt(component)) {
this.insertBeforeResponseColumn(headerRow, 'Dynamic Prompt');
}
}

private insertPostPromptColumnIfNecessary(headerRow: string[], component: any): void {
if (this.hasPostPrompt(component)) {
headerRow.splice(headerRow.indexOf('Response'), 0, 'Post Prompt');
this.insertBeforeResponseColumn(headerRow, 'Post Prompt');
}
}

private insertQuestionUsedColumnIfNecessary(headerRow: string[], component: any): void {
if (this.isClickToAddEnabled(component)) {
this.insertBeforeResponseColumn(headerRow, 'Question Used');
}
}

private insertBeforeResponseColumn(headerRow: string[], columnName: string): void {
headerRow.splice(headerRow.indexOf('Response'), 0, columnName);
}

private hasPrePrompt(component: any): boolean {
const prePrompt = component.dynamicPrompt?.prePrompt;
return prePrompt != null && prePrompt !== '';
return this.hasDynamicPrompt(component) && this.hasValue(component.dynamicPrompt?.prePrompt);
}

private hasDynamicPrompt(componentStates: any[]): boolean {
return componentStates.some(
(componentState: any) => componentState.studentData.dynamicPrompt?.prompt != null
);
private hasDynamicPrompt(component: any): boolean {
return component.dynamicPrompt?.enabled;
}

private hasPostPrompt(component: any): boolean {
const postPrompt = component.dynamicPrompt?.postPrompt;
return postPrompt != null && postPrompt !== '';
return this.hasDynamicPrompt(component) && this.hasValue(component.dynamicPrompt?.postPrompt);
}

private hasValue(value: any): boolean {
return value != null && value !== '';
}

private isClickToAddEnabled(component: any): boolean {
return component.questionBank?.clickToAddEnabled;
}

private insertQuestionColumnsIfNecessary(headerRow: string[], componentStates: any[]): void {
Expand Down Expand Up @@ -218,7 +239,7 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat
this.projectService.getNodePositionAndTitle(nodeId)
);
this.setColumnValue(row, columnNameToNumber, 'Component Type', component.type);
this.setColumnValue(row, columnNameToNumber, 'Component Prompt', component.prompt);
this.setColumnValue(row, columnNameToNumber, 'Prompt', component.prompt);
}

private setStudentWork(
Expand All @@ -239,25 +260,53 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat
'Client Timestamp',
millisecondsToDateTime(componentState.clientSaveTime)
);
this.setColumnValue(row, columnNameToNumber, 'Pre Prompt', component.dynamicPrompt?.prePrompt);
this.setColumnValue(
row,
columnNameToNumber,
'Dynamic Prompt',
componentState.studentData.dynamicPrompt?.prompt
);
this.setColumnValue(
row,
columnNameToNumber,
'Post Prompt',
component.dynamicPrompt?.postPrompt
);
this.setDynamicPrompts(row, columnNameToNumber, component, componentState);
if (componentState.studentData.questionBank != null) {
this.setQuestions(row, columnNameToNumber, componentState);
}
if (this.isClickToAddEnabled(component)) {
this.setColumnValue(
row,
columnNameToNumber,
'Question Used',
this.getQuestionText(component, componentState.studentData.questionId)
);
}
this.setColumnValue(row, columnNameToNumber, 'Response', componentState.studentData.response);
}

private setDynamicPrompts(
row: any,
columnNameToNumber: any,
component: any,
componentState: any
): void {
if (this.hasPrePrompt(component)) {
this.setColumnValue(
row,
columnNameToNumber,
'Pre Prompt',
component.dynamicPrompt?.prePrompt
);
}
if (this.hasDynamicPrompt(component)) {
this.setColumnValue(
row,
columnNameToNumber,
'Dynamic Prompt',
componentState.studentData.dynamicPrompt?.prompt
);
}
if (this.hasPostPrompt(component)) {
this.setColumnValue(
row,
columnNameToNumber,
'Post Prompt',
component.dynamicPrompt?.postPrompt
);
}
}

private setQuestions(row: any[], columnNameToNumber: any, componentState: any): void {
let questionCounter = 1;
for (const questionBank of componentState.studentData.questionBank) {
Expand All @@ -272,6 +321,17 @@ export class PeerChatComponentDataExportStrategy extends AbstractDataExportStrat
}
}

private getQuestionText(component: any, questionId: string): string {
for (const rule of component.questionBank.rules) {
for (const question of rule.questions) {
if (question.id === questionId) {
return question.text;
}
}
}
return null;
}

private setColumnValue(
row: any[],
columnNameToNumber: any,
Expand Down
Loading