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

update addEngagementByBlock method to store reliableByBlock attribute for block-scoped assessments #83

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/firestore/app/appkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ export class RoarAppkit {
}
}

/**
* Update the engagement flags for the current run in a block-based administration.
*
* @param {string[]} flagNames - The names of the engagement flags to add.
* @param {boolean} markAsReliable - Whether or not to mark the run as reliable, defaults to false
* @param {Object} reliableByBlock - Stores the reliability of the run by block
* For Example: {DEL: false, FSM: true, LSM: false}
* @method
* @async
*
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async updateEngagementFlagsByBlock(flagNames: string[], markAsReliable = false, reliableByBlock = {}) {
if (this._started) {
return this.run!.addEngagementFlagsByBlock(flagNames, markAsReliable, reliableByBlock);
} else {
throw new Error('This run has not started. Use the startRun method first.');
}
}

/**
* Finish the ROAR run by marking it as finished in Firestore.
* Call this method after the jsPsych experiment finishes. For example:
Expand Down
29 changes: 29 additions & 0 deletions src/firestore/app/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,35 @@ export class RoarRun {
}
}

/**
* Add engagement flags to a run.
* @method
* @async
* @param {string[]} engagementFlags - Engagement flags to add to the run
* @param {boolean} markAsReliable - Whether or not to mark the run as reliable, defaults to false
* @param {Object} reliableByBlock - Stores the reliability of the run by block
* For Example: {DEL: false, FSM: true, LSM: false}
*
* Please note that calling this function with a new set of engagement flags will
* overwrite the previous set.
*/
async addEngagementFlagsByBlock(engagementFlags: string[], markAsReliable = false, reliableByBlock = {}) {
if (!this.started) {
throw new Error('Run has not been started yet. Use the startRun method first.');
}

const engagementObj = engagementFlags.reduce((acc: { [x: string]: unknown }, flag) => {
acc[flag] = true;
return acc;
}, {});

if (!this.aborted) {
return updateDoc(this.runRef, { engagementFlags: engagementObj, reliable: markAsReliable, reliableByBlock: reliableByBlock });
} else {
throw new Error('Run has already been aborted.');
}
}

/**
* Mark this run as complete on Firestore
* @method
Expand Down
Loading