@@ -49,29 +49,40 @@ class Questions:
49
49
def extract_answers (cls , values ):
50
50
# Some things are available as answers to questions and we can extract
51
51
# 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
54
54
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 ):
58
61
values ["level" ] = answer ["answer" ]
59
62
60
- if answer [ "submission" ] is not None and cls .question_is (
63
+ if is_submission_question and cls .is_answer_to (
61
64
answer , cls .Questions .outline
62
65
):
63
66
values ["outline" ] = answer ["answer" ]
64
67
65
68
return values
66
69
67
70
@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
+ """
69
79
return answer .get ("question" , {}).get ("question" , {}).get ("en" ) == question
70
80
71
81
72
82
def 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" )
75
86
76
87
77
88
def parse_latest_submissions_to_objects (pretalx_data : PretalxData ) -> list [Submission ]:
@@ -102,9 +113,7 @@ def latest_flat_submissions_data() -> pl.DataFrame:
102
113
103
114
104
115
def 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 )
108
117
109
118
110
119
def piechart_submissions_by_state (submissions_by_state : pl .DataFrame ):
0 commit comments