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

Add cli register #517

Merged
merged 13 commits into from
Aug 15, 2024
Merged

Add cli register #517

merged 13 commits into from
Aug 15, 2024

Conversation

YUUU23
Copy link
Contributor

@YUUU23 YUUU23 commented Jul 27, 2024

  • Add register to commander, permitting script to be optionally ran with register (i.e. npm run cli register [studyID][partipantID] , skipping prompt first, second, and third prompt when those relative arguments are provided

  • main() :

    • Set-Up Prompts (when ACTION == "register"):
      • actionPrompt() : Add choice for registering new study & participants
      • studyIDPrompt() : Directly set STUDY_ID to the input read in and return
      • participantIDPrompt() : Directly set PARTICIPANT_ID to the input read in and return, modify prompt to ask for "Enter a new participant:"
      • experimentIDPrompt(): Skip this prompt, directly return
    • add new switch case for register , calling function registerDataFirebase(studyID, participantID) to register the new study in Firestore
  • confirmRegisterPrompt(): prints out current participant IDs under study if there are any (else print message saying there are none) and ask user to confirm that they want to add the new IDs in

  • Add new variable const REG_STUDY_COL = "registered_studies"; for the top-level collection we want to access when registering

  • registerDataFirebase(studyID, participantID):

    • if the study is not yet initiated, initiate it in Firestore; add the new participantID to that study
  • Helper Functions:

    • getRegisteredfStudyRef(studyID): get reference to the study in "registered_studies"
    • getRegisteredParticipantArr(studyID): return empty array if the current study is not initiated yet; else return array of all participant IDs under given study
    • registerNewParticipant(studyID, participantID): if there's a registered_participants array started under the registered study, add the new participantID to the array and update in Firestore
      • logs the current participants under this registered study afterwards

Now, direct firestore editing instructions outlined here: https://honeycomb.ccv.brown.edu/docs/firebase#registering-studies may be completed through CLI

Copy link

github-actions bot commented Jul 27, 2024

Visit the preview URL for this PR (updated for commit 58fceba):

https://ccv-honeycomb--pr517-add-cli-register-10x1mzbw.web.app

(expires Thu, 22 Aug 2024 01:39:15 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4ace1dcea913a952d2a1af84b94a4421bf36e610

@YUUU23 YUUU23 self-assigned this Jul 27, 2024
@YUUU23 YUUU23 linked an issue Jul 27, 2024 that may be closed by this pull request
@RobertGemmaJr
Copy link
Member

This is great! Could you create a new study and add some participants using the CLI and then send a few screenshots here? Just to confirm everything is looking good

@RobertGemmaJr
Copy link
Member

RobertGemmaJr commented Jul 31, 2024

Also, @YUUU23 could you set the base of this to be add-commander? It looks like it'll rebase fairly smoothly

Copy link
Member

@RobertGemmaJr RobertGemmaJr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Things are looking really really good here. It's going to take a little bit to bring the changes from the PRs above it into it but I think that would be worth it here. The prompts themselves look fantastic!

cli.mjs Outdated Show resolved Hide resolved
cli.mjs Outdated Show resolved Hide resolved
@@ -152,6 +249,10 @@ async function actionPrompt() {
name: "Download data",
value: "download",
},
{
name: "Register new participant under study",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can they register to new participants AND new studies or just new participants on an existing study?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should automatically register the new study if the study is not found! I will update this description to make it more clear.

cli.mjs Outdated Show resolved Hide resolved
@YUUU23 YUUU23 changed the base branch from feat-v4 to add-commander August 1, 2024 18:18
@YUUU23
Copy link
Contributor Author

YUUU23 commented Aug 1, 2024

This is great! Could you create a new study and add some participants using the CLI and then send a few screenshots here? Just to confirm everything is looking good

  • Adding new study / participant under that study
(base) happy2na@TheHappy2Na-229 honeycomb % npm run cli register test p3 

> honeycomb@4.0.0 cli
> node cli.mjs register test p3

register data from Firebase given study ID: test and participant ID: p3
? Currently, there are no participants under this study
Continue? adding study with studyID: test and participant ID: p3 yes
Successfully added study and participant. Current participantIDs under study test: 
p3
image
  • Adding new participant under existing study
(base) happy2na@TheHappy2Na-229 honeycomb % npm run cli register test p4

> honeycomb@4.0.0 cli
> node cli.mjs register test p4

register data from Firebase given study ID: test and participant ID: p4
? Currently, the participants under this study include: 
p3
Continue? adding study with studyID: test and participant ID: p4 yes
Successfully added study and participant. Current participantIDs under study test: 
p3
p4
image
  • Without providing optional participant

(base) happy2na@TheHappy2Na-229 honeycomb % npm run cli register test2  

> honeycomb@4.0.0 cli
> node cli.mjs register test2

register data from Firebase given study ID: test2 
? Enter a new participant: p1
? Currently, there are no participants under this study
Continue? adding study with studyID: test2 and participant ID: p1 yes
Successfully added study and participant. Current participantIDs under study test2: 
p1
image
  • Entirely through prompt
(base) happy2na@TheHappy2Na-229 honeycomb % npm run cli               

> honeycomb@4.0.0 cli
> node cli.mjs

? What would you like to do? Register new participant under study
? Select a study: test2
? Enter a new participant: p0
? Currently, the participants under this study include: 
p1
Continue? adding study with studyID: test2 and participant ID: p0 yes
Successfully added study and participant. Current participantIDs under study test2: 
p1
p0
image

We will not have cases where the study is not found, since it will register the new study if not found.

cli.mjs Outdated Show resolved Hide resolved
add commander.parse() to main function

Co-authored-by: Robert Gemma <38439940+RobertGemmaJr@users.noreply.github.com>
Copy link
Contributor

@eldu eldu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you resolve the merge conflicts?

@YUUU23 YUUU23 requested a review from eldu August 8, 2024 20:51
Copy link
Contributor

@eldu eldu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Question about async functions though

cli.mjs Show resolved Hide resolved
cli.mjs Outdated
const getRegisteredfStudyRef = (studyID) => FIRESTORE.collection(REG_STUDY_COL).doc(studyID);

// Get current registered participant array under the StudyID
const getRegisteredParticipantArr = (studyID) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an async function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just updated this too!

Base automatically changed from add-commander to feat-v4 August 14, 2024 06:49
@YUUU23 YUUU23 requested a review from eldu August 14, 2024 20:23
fix: logical expression to change back to casting to bool for prompt …
Copy link
Contributor

@eldu eldu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, amazing work Megan !! Thank you !

@YUUU23 YUUU23 merged commit 524fa8a into feat-v4 Aug 15, 2024
8 checks passed
@YUUU23 YUUU23 deleted the add-CLI-register branch August 15, 2024 13:52
@RobertGemmaJr RobertGemmaJr added the 4.0 Versioning: Issue in regards to version 4.0.0 release label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 Versioning: Issue in regards to version 4.0.0 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to register studies and participants with the CLI script
3 participants