-
Notifications
You must be signed in to change notification settings - Fork 34
Range surveys: require integers and improve validation #1102
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
base: main
Are you sure you want to change the base?
Changes from all commits
50fb7fa
8a94f91
81d9f5a
5b68480
cf7e55a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ import { | |
| requiresValues, | ||
| STAGE_MANAGER, | ||
| checkApiKeyExists, | ||
| SurveyQuestion, | ||
| MultipleChoiceItem, | ||
| createAgentMediatorPersonaConfig, | ||
| createAgentParticipantPersonaConfig, | ||
| createExperimentConfig, | ||
|
|
@@ -118,17 +120,70 @@ export class ExperimentEditor extends Service { | |
| renderApiErrorMessage(ApiKeyType.OLLAMA_CUSTOM_URL); | ||
|
|
||
| for (const stage of this.stages) { | ||
| switch (stage.kind) { | ||
| case StageKind.SURVEY: | ||
| // Ensure all questions have a non-empty title | ||
| stage.questions.forEach((question, index) => { | ||
| if (question.questionTitle === '') { | ||
| if ( | ||
| stage.kind === StageKind.SURVEY || | ||
| stage.kind === StageKind.SURVEY_PER_PARTICIPANT | ||
| ) { | ||
| if (!stage.questions || stage.questions.length === 0) { | ||
| errors.push(`${stage.name} must contain at least one question`); | ||
| } | ||
| stage.questions.forEach((question: SurveyQuestion, index: number) => { | ||
| if (question.questionTitle === '') { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} is missing a title`, | ||
| ); | ||
| } | ||
| if (question.kind === 'scale') { | ||
| if ( | ||
| !Number.isInteger(question.lowerValue) || | ||
| !Number.isInteger(question.upperValue) || | ||
| (question.stepSize !== undefined && | ||
| !Number.isInteger(question.stepSize)) | ||
| ) { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): values must be integers`, | ||
| ); | ||
| } | ||
| if (question.lowerValue >= question.upperValue) { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} is missing a title`, | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): lower value must be less than upper value`, | ||
| ); | ||
| } | ||
| const range = question.upperValue - question.lowerValue; | ||
| const step = question.stepSize ?? 1; | ||
| if (step <= 0) { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): step size must be greater than 0`, | ||
| ); | ||
| } | ||
| if (range % step !== 0) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Above we check that |
||
| errors.push( | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): step size must divide max-min (${range}) exactly`, | ||
| ); | ||
| } | ||
| } | ||
| if (question.kind === 'mc') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Is there a static variable for the string |
||
| if (!question.options || question.options.length === 0) { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): must have at least one option`, | ||
| ); | ||
| } | ||
| if ( | ||
| question.correctAnswerId != null && | ||
| question.correctAnswerId !== '' | ||
| ) { | ||
| const hasOption = question.options.some( | ||
| (opt: MultipleChoiceItem) => | ||
| opt.id === question.correctAnswerId, | ||
| ); | ||
| if (!hasOption) { | ||
| errors.push( | ||
| `${stage.name} question ${index + 1} ("${question.questionTitle}"): correct answer ID doesn't match any option ID`, | ||
| ); | ||
| } | ||
| } | ||
| }); | ||
| break; | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main nit is that here and elsewhere, you assert a condition that would make the comparison potentially unspecified.
For example, earlier, you check
!Number.isInteger(question.lowerValue)and if so, you append to theerrorsarray. This is good. But in that case, when we get to this line, there are several possibilities, only some of which make sense. E.g., it could be thatlowerValueis, say a float like3.5, or even a string like"456". Those are legal values for this JavaScript>=comparison againstupperValue, but they would have been flagged already as being illegal (non-integer).Anyway, if the code works and the tests pass, it's good enough for me. Just flagging that it's strange to me to see later comparisons using potentially bad values that were checked earlier.