-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: creating suggestions and responses (#4627)
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description This PR adds response and suggestion method helpers to simplify and unify how users may work with responses and suggestions. Instead of using response and suggestion schemas init methods, users may use `*.with_question_value` method to create responses and suggestions given a question and a response value. This way will introduce some extra data validation which is not available using init methods directly. For example, given the following dataset: ```python dataset = rg.FeedbackDataset( fields =[rg.TextField(name="text")], question=[ rg.TextQuestion(name="question-1", required=True), rg.RatingQuestion(name="question-2", values=[1, 2], required=True), rg.LabelQuestion(name="question-3", labels=["a", "b", "c"], required=True), rg.MultiLabelQuestion(name="question-4", labels=["a", "b", "c"], required=True), rg.RankingQuestion(name="question-5", values=["a", "b"], required=True), ] ) ``` users could create responses and suggestions as follows: ```python question_1 = dataset.question_by_name("question-1") question_2 = dataset.question_by_name("question-2") question_3 = dataset.question_by_name("question-3") question_4 = dataset.question_by_name("question-4") question_5 = dataset.question_by_name("question-5") record = rg.FeedbackRecord( fields={ "text": "This is a text value for field"}, responses=[ ResponseSchema(status="submitted") .with_question_value(question_1, value="answer") .with_question_value(question_2, value=0) .with_question_value(question_3, value="a") .with_question_value(question_4, value=["a", "b"]) .with_question_value(question_5, value=[{"rank": 1, "value": "a"}, {"rank": 2, "value": "b"}]) ], suggestions=[ SuggestionSchema.with_question_value(question_1, value="answer"), SuggestionSchema.with_question_value(question_2, value=0), SuggestionSchema.with_question_value(question_3, value="a"), SuggestionSchema.with_question_value(question_4, value=["a", "b"]), SuggestionSchema.with_question_value(question_5, value=[{"rank": 1, "value": "a"}, {"rank":2, "value": "b"}]) ] ) ``` **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Refactor (change restructuring the codebase without changing functionality) - [ ] Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** (Please describe the tests that you ran to verify your changes. And ideally, reference `tests`) - [ ] Test A - [ ] Test B **Checklist** - [ ] I added relevant documentation - [ ] I followed the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the `CHANGELOG.md` file (See https://keepachangelog.com/) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a3def08
commit ae329fc
Showing
9 changed files
with
162 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.