Skip to content

Commit f8b6b3e

Browse files
committed
add all_options_ever to serializer and api docs
1 parent 2e496a5 commit f8b6b3e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

docs/openapi.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,18 @@ components:
500500
- "Libertarian"
501501
- "Green"
502502
- "Other"
503+
all_options_ever:
504+
type: array
505+
items:
506+
type: string
507+
description: "List of all options ever for multiple_choice questions"
508+
example:
509+
- "Democratic"
510+
- "Republican"
511+
- "Libertarian"
512+
- "Green"
513+
- "Blue"
514+
- "Other"
503515
options_history:
504516
type: array
505517
description: "List of [timestamp, options] pairs for multiple_choice questions"
@@ -1573,6 +1585,13 @@ paths:
15731585
- "Libertarian"
15741586
- "Green"
15751587
- "Other"
1588+
all_options_ever:
1589+
- "Democratic"
1590+
- "Republican"
1591+
- "Libertarian"
1592+
- "Green"
1593+
- "Blue"
1594+
- "Other"
15761595
options_history:
15771596
- [0, ["Democratic", "Republican", "Libertarian", "Other"]]
15781597
- [1763240000.0, ["Democratic", "Republican", "Libertarian", "Green", "Other"]]

questions/serializers/common.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
AggregateForecast,
1818
Forecast,
1919
)
20-
from questions.serializers.aggregate_forecasts import (
21-
serialize_question_aggregations,
22-
)
20+
from questions.serializers.aggregate_forecasts import serialize_question_aggregations
21+
from questions.services.multiple_choice_handlers import get_all_options_from_history
2322
from questions.types import QuestionMovement
2423
from users.models import User
2524
from utils.the_math.formulas import (
@@ -58,6 +57,7 @@ class Meta:
5857
"type",
5958
# Multiple-choice Questions only
6059
"options",
60+
"all_options_ever",
6161
"options_history",
6262
"group_variable",
6363
# Used for Group Of Questions to determine
@@ -123,6 +123,10 @@ def get_actual_close_time(self, question: Question):
123123
return min(question.scheduled_close_time, question.actual_resolve_time)
124124
return question.scheduled_close_time
125125

126+
def get_all_options_ever(self, question: Question):
127+
if question.options_history:
128+
return get_all_options_from_history(question.options_history)
129+
126130
def get_resolution(self, question: Question):
127131
resolution = question.resolution
128132

0 commit comments

Comments
 (0)