xapi_rs/data/interaction_type.rs
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3use core::fmt;
4use serde::{Deserialize, Serialize};
5
6/// Enumeration used in [ActivityDefinition][1]s.
7///
8/// Based on the variant used, the data formatting and purpose of other fields
9/// in an [ActivityDefinition][1] instance are implied.
10///
11/// [1]: crate::ActivityDefinition
12#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
13pub enum InteractionType {
14 /// An _interaction_ with two possible responses: `true` or `false`.
15 ///
16 /// Format: Either `true` or `false`.
17 #[default]
18 #[serde(rename = "true-false")]
19 TrueFalse,
20
21 /// An _interaction_ with a number of possible choices from which the
22 /// learner can select. This includes interactions in which the learner can
23 /// select only one answer from the list and those where the learner can
24 /// select multiple items.
25 ///
26 /// Format: A list of item `id`s delimited by \[,\]. If the response contains
27 /// only one item, the delimiter shall not be used.
28 #[serde(rename = "choice")]
29 Choice,
30
31 /// An _interaction_ which requires the learner to supply a short response
32 /// in the form of one or more strings of characters. Typically, the correct
33 /// response consists of part of a word, one word or a few words. "Short"
34 /// means that the correct responses pattern and learner response strings
35 /// are normally 250 characters or less.
36 ///
37 /// Format: A list of responses delimited by \[,\]. If the response contains
38 /// only one item, the delimiter shall not be used.
39 #[serde(rename = "fill-in")]
40 FillIn,
41
42 /// An _interaction_ which requires the learner to supply a response in the
43 /// form of a long string of characters. "Long" means that the correct
44 /// responses pattern and learner response strings are normally more than
45 /// 250 characters.
46 ///
47 /// Format: A list of responses delimited by \[,\]. If the response contains
48 /// only one item, the delimiter shall not be used.
49 #[serde(rename = "long-fill-in")]
50 LongFillIn,
51
52 /// An _interaction_ where the learner is asked to match items in one set
53 /// (the _source_ set) to items in another set (the _target_ set). Items do
54 /// not have to pair off exactly and it is possible for multiple or zero
55 /// _source_ items to be matched to a given _target_ and vice versa.
56 ///
57 /// Format: A list of matching pairs, where each pair consists of a _source_
58 /// item `id` followed by a _target_ item `id`. Items can appear in multiple
59 /// (or zero) pairs. Items within a pair are delimited by \[.\]. Pairs are
60 /// delimited by \[,\].
61 #[serde(rename = "matching")]
62 Matching,
63
64 /// An _interaction_ that requires the learner to perform a task that
65 /// requires multiple steps.
66 ///
67 /// Format: A list of steps containing a step `id`s and the response to that
68 /// step. Step ids are separated from responses by \[.\]. Steps are
69 /// delimited by \[,\]. The response can be a String as in a fill-in
70 /// interaction or a number range as in a numeric interaction.
71 #[serde(rename = "performance")]
72 Performance,
73
74 /// An _interaction_ where the learner is asked to order items in a set.
75 ///
76 /// Format: An ordered list of item `id`s delimited by \[,\].
77 #[serde(rename = "sequencing")]
78 Sequencing,
79
80 /// An _interaction_ which asks the learner to select from a discrete set
81 /// of choices on a scale.
82 ///
83 /// Format: A single item `id`.
84 #[serde(rename = "likert")]
85 Likert,
86
87 /// Any _interaction_ which requires a numeric response from the learner.
88 ///
89 /// Format: A range of numbers represented by a minimum and a maximum
90 /// delimited by \[:\]. Where the range does not have a maximum or does
91 /// not have a minimum, that number is omitted but the delimiter is
92 /// still used. E.g. \[:\]4 indicates a maximum for 4 and no minimum.
93 /// Where the correct response or learner's response is a single number
94 /// rather than a range, the single number with no delimiter may be used.
95 #[serde(rename = "numeric")]
96 Numeric,
97
98 /// Another type of _interaction_ that does not fit into the other variants.
99 ///
100 /// Format: Any format is valid within this string as appropriate for the
101 /// type of interaction.
102 #[serde(rename = "other")]
103 Other,
104}
105
106impl fmt::Display for InteractionType {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 match self {
109 InteractionType::TrueFalse => write!(f, "true-false"),
110 InteractionType::Choice => write!(f, "choice"),
111 InteractionType::FillIn => write!(f, "fill-in"),
112 InteractionType::LongFillIn => write!(f, "long-fill-in"),
113 InteractionType::Matching => write!(f, "matching"),
114 InteractionType::Performance => write!(f, "performance"),
115 InteractionType::Sequencing => write!(f, "sequencing"),
116 InteractionType::Likert => write!(f, "likert"),
117 InteractionType::Numeric => write!(f, "numeric"),
118 InteractionType::Other => write!(f, "other"),
119 }
120 }
121}