-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93bd14e
commit a6fe88b
Showing
22 changed files
with
5,932 additions
and
180 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
19 changes: 19 additions & 0 deletions
19
consultation_analyser/consultations/management/commands/generate_json_schemas.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
from django.core.management import BaseCommand | ||
|
||
from consultation_analyser.consultations import public_schema | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Generates an Entity Relationship Diagram for the repository’s README" | ||
|
||
def handle(self, *args, **options): | ||
schema_folder = "./consultation_analyser/consultations/public_schema" | ||
|
||
schema = public_schema.Consultation.model_json_schema() | ||
with open(f"{schema_folder}/consultation_schema.json", "w") as f: | ||
json.dump(schema, f) | ||
|
||
schema = public_schema.ConsultationResponseList.model_json_schema() | ||
with open(f"{schema_folder}/consultation_response_list_schema.json", "w") as f: | ||
json.dump(schema, f) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,119 @@ | ||
# generated by datamodel-codegen: | ||
# filename: public_schema.yaml | ||
# timestamp: 2024-03-27T09:03:22+00:00 | ||
# timestamp: 2024-03-28T07:59:40+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import List, Optional | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel, Field | ||
from pydantic import BaseModel, Extra, Field | ||
|
||
|
||
class Question(BaseModel): | ||
id: Optional[UUID] = None | ||
text: Optional[str] = Field( | ||
None, | ||
""" | ||
Questions can be free text, multiple choice or both. The presence of multiple_choice_options implies that the question has a multiple choice part. | ||
""" | ||
|
||
id: UUID = Field(..., description='The ID of this question') | ||
text: str = Field( | ||
..., | ||
description='The question text', | ||
example='Should Kit Kats be banned on Tuesdays', | ||
examples=[ | ||
'Should it happen on Tuesdays?', | ||
'Should it happen in the month of May?', | ||
'Should it happen on a full moon?', | ||
'Should it happen on Fridays?', | ||
'Should it be forbidden on Sunday?', | ||
], | ||
) | ||
has_free_text: Optional[bool] = Field( | ||
None, description='Does this question have a free text component?' | ||
has_free_text: bool = Field( | ||
..., description='Does this question have a free text component?' | ||
) | ||
multiple_choice_options: Optional[List[str]] = Field( | ||
None, | ||
description='The options for the multiple choice part of this question, if it has a multiple choice component', | ||
example=['Yes', 'No', "I don't know"], | ||
) | ||
|
||
|
||
class Answer(BaseModel): | ||
multiple_choice: Optional[List[str]] = Field( | ||
None, | ||
""" | ||
Each Answer is associated with a Question and belongs to a ConsultationResponse. | ||
""" | ||
|
||
question_id: UUID = Field(..., description='The ID of the question') | ||
multiple_choice: List[str] = Field( | ||
..., | ||
description='Responses to the multiple choice part of the question, if any', | ||
example=['No'], | ||
) | ||
free_text: Optional[str] = Field( | ||
None, description='The answer to the free text part of the question, if any' | ||
free_text: str = Field( | ||
..., | ||
description='The answer to the free text part of the question, if any', | ||
examples=[ | ||
"I don't think this is a good idea at all", | ||
'I would like to point out a few things', | ||
'I would like clarification on a few key points', | ||
], | ||
) | ||
|
||
|
||
class ConsultationResponse(BaseModel): | ||
answers: Optional[List[Answer]] = None | ||
""" | ||
A ConsultationResponse groups answers. For now it is also a placeholder for response-level information such as demographics, responding-in-the-capacity-of, etc. | ||
""" | ||
|
||
id: UUID = Field(..., description='The ID of the response') | ||
answers: List[Answer] = Field(..., description='The answers in this response') | ||
|
||
|
||
class ConsultationResponseList(BaseModel): | ||
""" | ||
A list of ConsultationResponses | ||
""" | ||
|
||
consultation_responses: List[ConsultationResponse] = Field( | ||
..., description='The responses' | ||
) | ||
|
||
|
||
class Section(BaseModel): | ||
name: Optional[str] = Field( | ||
None, | ||
""" | ||
A Section contains a group of Questions. Consultations that do not have multiple sections should group all Questions under a single Section. | ||
""" | ||
|
||
id: UUID = Field(..., description='The ID of the section') | ||
name: str = Field( | ||
..., | ||
description='The name of the section', | ||
example='When to enforce a Kit Kat ban', | ||
examples=[ | ||
'When to enforce a Kit Kat ban', | ||
'When to encourage the eating of Kit Kats', | ||
'When Kit Kats are consumed', | ||
], | ||
) | ||
questions: List[Question] = Field( | ||
..., description='The questions in the consultation' | ||
) | ||
questions: Optional[List[Question]] = None | ||
|
||
|
||
class Consultation(BaseModel): | ||
name: Optional[str] = Field( | ||
None, | ||
""" | ||
Consultation is the top-level object describing a consultation. It contains one or more Sections, which in turn contain Questions. | ||
""" | ||
|
||
class Config: | ||
extra = Extra.forbid | ||
|
||
name: str = Field( | ||
..., | ||
description='The name of the consultation', | ||
example='Consultation on Kit Kats', | ||
examples=[ | ||
'Consultation on Kit Kats', | ||
'How should Kit Kats change', | ||
'What shall we do about Kit Kats', | ||
], | ||
) | ||
sections: Optional[List[Section]] = None | ||
sections: List[Section] = Field(..., description='The sections of the consultation') |
1 change: 1 addition & 0 deletions
1
consultation_analyser/consultations/public_schema/consultation_example.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"Consultation on Kit Kats","sections":[{"id":"cf887a0f-c0ed-3cc8-20df-15cac2582f9d","name":"When to encourage the eating of Kit Kats","questions":[{"id":"75d33882-1c6f-f348-2ecb-bb995a0c7772","text":"Should it happen on Tuesdays?","has_free_text":false},{"id":"e54b60ae-a6f5-19ee-6410-6441a9d829bb","text":"Should it happen on a full moon?","has_free_text":false},{"id":"da7af605-fd4e-41ec-b276-54e24aa64081","text":"Should it be forbidden on Sunday?","has_free_text":false},{"id":"680f044d-a417-06a9-648b-e5884353d9f4","text":"Should it happen on Tuesdays?","has_free_text":true},{"id":"efb96cf3-e455-66d5-ae8e-e1f22cd236c3","text":"Should it happen on a full moon?","has_free_text":false}]},{"id":"6c48808e-9198-3fe3-63e9-a8319e5e2ab5","name":"When to encourage the eating of Kit Kats","questions":[{"id":"fa5cd756-92b2-71a9-9584-61da063d48b4","text":"Should it happen in the month of May?","has_free_text":true,"multiple_choice_options":["Yes","No","I don't know"]},{"id":"c511a280-15ea-b963-c482-9d6fb568a31c","text":"Should it happen on Tuesdays?","has_free_text":true},{"id":"843b764e-cfb5-ca99-28c5-9000a266f798","text":"Should it happen on Fridays?","has_free_text":false},{"id":"7c9c063c-2b4c-3e60-7d20-259b51707a63","text":"Should it happen on Fridays?","has_free_text":false},{"id":"32ca1a40-1d44-328c-4e63-025bb97210b2","text":"Should it be forbidden on Sunday?","has_free_text":false}]}]} |
1 change: 1 addition & 0 deletions
1
consultation_analyser/consultations/public_schema/consultation_response_list_example.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"consultation_responses":[{"id":"a0f5cd91-4e2e-0f78-d0e4-f209a15fec70","answers":[{"question_id":"c811d9b9-5ade-5917-515c-d1d7a6d3a3e8","multiple_choice":["No"],"free_text":"I would like to point out a few things"},{"question_id":"6622f17c-48e1-fcc6-6534-c6fcbf345cee","multiple_choice":["No"],"free_text":"I would like to point out a few things"},{"question_id":"e60c8d99-d764-96f1-5311-f6d0fde01f6b","multiple_choice":["No"],"free_text":"I would like to point out a few things"}]},{"id":"775fc2c1-43d5-030a-d3db-bc00676b7211","answers":[{"question_id":"fd29c40a-84d8-0a6e-c102-86046b489591","multiple_choice":["No"],"free_text":"I would like clarification on a few key points"},{"question_id":"57625272-8c49-d966-9a65-13260679e690","multiple_choice":["No"],"free_text":"I would like to point out a few things"},{"question_id":"dabfa87a-6d85-b0d5-c93e-db31223e1e35","multiple_choice":["No"],"free_text":"I would like to point out a few things"},{"question_id":"b2db7f98-066e-bac7-454a-ccaa29d0a4b1","multiple_choice":["No"],"free_text":"I don't think this is a good idea at all"},{"question_id":"60d64eaf-552e-e58d-474c-b417d367bc03","multiple_choice":["No"],"free_text":"I would like to point out a few things"}]}]} |
1 change: 1 addition & 0 deletions
1
consultation_analyser/consultations/public_schema/consultation_response_list_schema.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"$defs": {"Answer": {"description": "Each Answer is associated with a Question and belongs to a ConsultationResponse.", "properties": {"question_id": {"description": "The ID of the question", "format": "uuid", "title": "Question Id", "type": "string"}, "multiple_choice": {"description": "Responses to the multiple choice part of the question, if any", "example": ["No"], "items": {"type": "string"}, "title": "Multiple Choice", "type": "array"}, "free_text": {"description": "The answer to the free text part of the question, if any", "examples": ["I don't think this is a good idea at all", "I would like to point out a few things", "I would like clarification on a few key points"], "title": "Free Text", "type": "string"}}, "required": ["question_id", "multiple_choice", "free_text"], "title": "Answer", "type": "object"}, "ConsultationResponse": {"description": "A ConsultationResponse groups answers. For now it is also a placeholder for response-level information such as demographics, responding-in-the-capacity-of, etc.", "properties": {"id": {"description": "The ID of the response", "format": "uuid", "title": "Id", "type": "string"}, "answers": {"description": "The answers in this response", "items": {"$ref": "#/$defs/Answer"}, "title": "Answers", "type": "array"}}, "required": ["id", "answers"], "title": "ConsultationResponse", "type": "object"}}, "description": "A list of ConsultationResponses", "properties": {"consultation_responses": {"description": "The responses", "items": {"$ref": "#/$defs/ConsultationResponse"}, "title": "Consultation Responses", "type": "array"}}, "required": ["consultation_responses"], "title": "ConsultationResponseList", "type": "object"} |
1 change: 1 addition & 0 deletions
1
consultation_analyser/consultations/public_schema/consultation_schema.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"$defs": {"Question": {"description": "Questions can be free text, multiple choice or both. The presence of multiple_choice_options implies that the question has a multiple choice part.", "properties": {"id": {"description": "The ID of this question", "format": "uuid", "title": "Id", "type": "string"}, "text": {"description": "The question text", "examples": ["Should it happen on Tuesdays?", "Should it happen in the month of May?", "Should it happen on a full moon?", "Should it happen on Fridays?", "Should it be forbidden on Sunday?"], "title": "Text", "type": "string"}, "has_free_text": {"description": "Does this question have a free text component?", "title": "Has Free Text", "type": "boolean"}, "multiple_choice_options": {"anyOf": [{"items": {"type": "string"}, "type": "array"}, {"type": "null"}], "default": null, "description": "The options for the multiple choice part of this question, if it has a multiple choice component", "example": ["Yes", "No", "I don't know"], "title": "Multiple Choice Options"}}, "required": ["id", "text", "has_free_text"], "title": "Question", "type": "object"}, "Section": {"description": "A Section contains a group of Questions. Consultations that do not have multiple sections should group all Questions under a single Section.", "properties": {"id": {"description": "The ID of the section", "format": "uuid", "title": "Id", "type": "string"}, "name": {"description": "The name of the section", "examples": ["When to enforce a Kit Kat ban", "When to encourage the eating of Kit Kats", "When Kit Kats are consumed"], "title": "Name", "type": "string"}, "questions": {"description": "The questions in the consultation", "items": {"$ref": "#/$defs/Question"}, "title": "Questions", "type": "array"}}, "required": ["id", "name", "questions"], "title": "Section", "type": "object"}}, "additionalProperties": false, "description": "Consultation is the top-level object describing a consultation. It contains one or more Sections, which in turn contain Questions.", "properties": {"name": {"description": "The name of the consultation", "examples": ["Consultation on Kit Kats", "How should Kit Kats change", "What shall we do about Kit Kats"], "title": "Name", "type": "string"}, "sections": {"description": "The sections of the consultation", "items": {"$ref": "#/$defs/Section"}, "title": "Sections", "type": "array"}}, "required": ["name", "sections"], "title": "Consultation", "type": "object"} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.