quizcomp.model.config

  1import typing
  2
  3import edq.util.serial
  4
  5class Option:
  6    """
  7    This class makes it easier to access configuration values in core types for known options (attributes, hints, or style).
  8    These values are always keyed by strings, making them resistant to version changes.
  9    All information for accessing the known configuration are stored in this class.
 10    """
 11
 12    def __init__(self,
 13            value_type: str,
 14            key: str,
 15            default_value: typing.Union[edq.util.serial.PODType, None] = None,
 16            ) -> None:
 17        self.value_type: str = value_type
 18        """ Where to look within the core object for the configuration. """
 19
 20        self.key: str = key
 21        """ The key for the value. """
 22
 23        self.default_value = default_value
 24        """ The default value to use if the key is not present. """
 25
 26        if (self.value_type not in _known_options):
 27            _known_options[self.value_type] = {}
 28
 29        _known_options[self.value_type][self.key] = self
 30
 31_known_options: typing.Dict[str, typing.Dict[str, Option]] = {}
 32""" Keep track of all seen options, keyed by value type and then key. """
 33
 34def get_known_option(key: str, value_type: typing.Union[str, None] = None) -> typing.Union[Option, None]:
 35    """
 36    Get a known option (if it exists).
 37    If no value type is provided, then search all types and return the first matching option.
 38    """
 39
 40    if (value_type is not None):
 41        return _known_options.get(value_type, {}).get(key, None)
 42
 43    for options in _known_options.values():
 44        if (key in options):
 45            return options[key]
 46
 47    return None
 48
 49OPTION_CUSTOM_HEADER: Option = Option('attributes', 'custom_header', None)
 50"""
 51A custom header for some object like a question, this would be used instead of something generic like "Question 4".
 52
 53Defaults to nothing.
 54"""
 55
 56OPTION_PICK_WITH_REPLACEMENT: Option = Option('attributes', 'pick_with_replacement', True)
 57"""
 58Whether or not questions are chosen with replacement between variants.
 59True means that different variants can have the same questions.
 60False means that they cannot, but can also cause a warning if not enough questions are available in a group.
 61
 62Defaults to true.
 63"""
 64
 65OPTION_POINT_PRECISION: Option = Option('attributes', 'point_precision', 2)
 66"""
 67The number of decimal places to use when displaying points.
 68The point value will first be rounded to this precision, and then formatted.
 69
 70Defaults to 2.
 71"""
 72
 73OPTION_SHUFFLE_ANSWERS: Option = Option('attributes', 'shuffle_answers', True)
 74"""
 75If the answers in a question should be shuffled.
 76
 77Defaults to true.
 78"""
 79
 80OPTION_SKIP_NUMBERING_KEY: Option = Option('attributes', 'skip_numbering', False)
 81"""
 82If numbering for questions should be skipped.
 83
 84Defaults to false.
 85"""
 86
 87OPTION_HINT_HEIGHT: Option = Option('hints', 'height', '4em')
 88"""
 89The height to use for this object.
 90
 91Defaults to '4em'.
 92"""
 93
 94OPTION_HINT_INLINE: Option = Option('hints', 'inline', False)
 95"""
 96If an object should try to render its content on the same line.
 97
 98Defaults to false.
 99"""
100
101OPTION_HINT_NOCENTER: Option = Option('hints', 'nocenter', False)
102"""
103Do not try to center for this object.
104
105Defaults to false.
106"""
107
108OPTION_HINT_PAGEBREAK_AFTER: Option = Option('hints', 'pagebreak_after', False)
109"""
110If an object (usually a question) should insert a pagebreak after itself.
111
112Defaults to false.
113"""
114
115OPTION_HINT_PAGEBREAK_BEFORE: Option = Option('hints', 'pagebreak_before', False)
116"""
117If an object (usually a question) should insert a pagebreak before itself.
118
119Defaults to false.
120"""
121
122OPTION_HINT_WIDTH: Option = Option('hints', 'width', 1.0)
123"""
124The width to use for this object.
125
126Defaults to 1,0.
127"""
128
129OPTION_LMS_ASSIGNMENT_GROUP: Option = Option('attributes', 'custom_header', None)
130"""
131A custom header for some object like a question, this would be used instead of something generic like "Question 4".
132
133Defaults to nothing.
134"""
class Option:
 6class Option:
 7    """
 8    This class makes it easier to access configuration values in core types for known options (attributes, hints, or style).
 9    These values are always keyed by strings, making them resistant to version changes.
10    All information for accessing the known configuration are stored in this class.
11    """
12
13    def __init__(self,
14            value_type: str,
15            key: str,
16            default_value: typing.Union[edq.util.serial.PODType, None] = None,
17            ) -> None:
18        self.value_type: str = value_type
19        """ Where to look within the core object for the configuration. """
20
21        self.key: str = key
22        """ The key for the value. """
23
24        self.default_value = default_value
25        """ The default value to use if the key is not present. """
26
27        if (self.value_type not in _known_options):
28            _known_options[self.value_type] = {}
29
30        _known_options[self.value_type][self.key] = self

This class makes it easier to access configuration values in core types for known options (attributes, hints, or style). These values are always keyed by strings, making them resistant to version changes. All information for accessing the known configuration are stored in this class.

Option( value_type: str, key: str, default_value: Union[bool, float, int, str, List[ForwardRef('PODType')], Dict[str, ForwardRef('PODType')], NoneType] = None)
13    def __init__(self,
14            value_type: str,
15            key: str,
16            default_value: typing.Union[edq.util.serial.PODType, None] = None,
17            ) -> None:
18        self.value_type: str = value_type
19        """ Where to look within the core object for the configuration. """
20
21        self.key: str = key
22        """ The key for the value. """
23
24        self.default_value = default_value
25        """ The default value to use if the key is not present. """
26
27        if (self.value_type not in _known_options):
28            _known_options[self.value_type] = {}
29
30        _known_options[self.value_type][self.key] = self
value_type: str

Where to look within the core object for the configuration.

key: str

The key for the value.

default_value

The default value to use if the key is not present.

def get_known_option( key: str, value_type: Optional[str] = None) -> Optional[Option]:
35def get_known_option(key: str, value_type: typing.Union[str, None] = None) -> typing.Union[Option, None]:
36    """
37    Get a known option (if it exists).
38    If no value type is provided, then search all types and return the first matching option.
39    """
40
41    if (value_type is not None):
42        return _known_options.get(value_type, {}).get(key, None)
43
44    for options in _known_options.values():
45        if (key in options):
46            return options[key]
47
48    return None

Get a known option (if it exists). If no value type is provided, then search all types and return the first matching option.

OPTION_CUSTOM_HEADER: Option = <Option object>

A custom header for some object like a question, this would be used instead of something generic like "Question 4".

Defaults to nothing.

OPTION_PICK_WITH_REPLACEMENT: Option = <Option object>

Whether or not questions are chosen with replacement between variants. True means that different variants can have the same questions. False means that they cannot, but can also cause a warning if not enough questions are available in a group.

Defaults to true.

OPTION_POINT_PRECISION: Option = <Option object>

The number of decimal places to use when displaying points. The point value will first be rounded to this precision, and then formatted.

Defaults to 2.

OPTION_SHUFFLE_ANSWERS: Option = <Option object>

If the answers in a question should be shuffled.

Defaults to true.

OPTION_SKIP_NUMBERING_KEY: Option = <Option object>

If numbering for questions should be skipped.

Defaults to false.

OPTION_HINT_HEIGHT: Option = <Option object>

The height to use for this object.

Defaults to '4em'.

OPTION_HINT_INLINE: Option = <Option object>

If an object should try to render its content on the same line.

Defaults to false.

OPTION_HINT_NOCENTER: Option = <Option object>

Do not try to center for this object.

Defaults to false.

OPTION_HINT_PAGEBREAK_AFTER: Option = <Option object>

If an object (usually a question) should insert a pagebreak after itself.

Defaults to false.

OPTION_HINT_PAGEBREAK_BEFORE: Option = <Option object>

If an object (usually a question) should insert a pagebreak before itself.

Defaults to false.

OPTION_HINT_WIDTH: Option = <Option object>

The width to use for this object.

Defaults to 1,0.

OPTION_LMS_ASSIGNMENT_GROUP: Option = <Option object>

A custom header for some object like a question, this would be used instead of something generic like "Question 4".

Defaults to nothing.