@@ -49,29 +49,40 @@ class Questions:
4949 def extract_answers (cls , values ):
5050 # Some things are available as answers to questions and we can extract
5151 # them here
52- # But using .get since this should be optional for creating objects
53- # manually
52+ # Using .get since this should be optional when creating Submission
53+ # objects manually
5454 for answer in values .get ("answers" , "" ):
55- if answer ["submission" ] is not None and cls .question_is (
56- answer , cls .Questions .level
57- ):
55+ # Submission in the API will include answers to questions asked on
56+ # submission and on the speaker. Let's explicitly filter out only
57+ # submission questions.
58+ is_submission_question = answer ["submission" ] is not None
59+
60+ if is_submission_question and cls .is_answer_to (answer , cls .Questions .level ):
5861 values ["level" ] = answer ["answer" ]
5962
60- if answer [ "submission" ] is not None and cls .question_is (
63+ if is_submission_question and cls .is_answer_to (
6164 answer , cls .Questions .outline
6265 ):
6366 values ["outline" ] = answer ["answer" ]
6467
6568 return values
6669
6770 @staticmethod
68- def question_is (answer : dict , question : str ) -> bool :
71+ def is_answer_to (answer : dict , question : str ) -> bool :
72+ """
73+ Returns True if the answer corresponds to the question passed as the second
74+ argument.
75+
76+ Answers come in a nested structure that includes localised question
77+ text. This function is a small wrapper to encapsulate that behaviour.
78+ """
6979 return answer .get ("question" , {}).get ("question" , {}).get ("en" ) == question
7080
7181
7282def get_latest_submissions_data () -> PretalxData :
73- qs = PretalxData .objects .filter (resource = PretalxData .PretalxResources .submissions )
74- return qs .latest ("created_at" )
83+ return PretalxData .objects .filter (
84+ resource = PretalxData .PretalxResources .submissions
85+ ).latest ("created_at" )
7586
7687
7788def parse_latest_submissions_to_objects (pretalx_data : PretalxData ) -> list [Submission ]:
@@ -102,9 +113,7 @@ def latest_flat_submissions_data() -> pl.DataFrame:
102113
103114
104115def group_submissions_by_state (submissions : pl .DataFrame ) -> pl .DataFrame :
105- by_state = submissions .group_by ("state" ).len ().sort ("len" , descending = True )
106-
107- return by_state
116+ return submissions .group_by ("state" ).len ().sort ("len" , descending = True )
108117
109118
110119def piechart_submissions_by_state (submissions_by_state : pl .DataFrame ):
0 commit comments