@nakafa/aksara-contracts 8.8.0 → 8.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/assessment/answer.d.ts +2 -0
  2. package/dist/assessment/answer.js +5 -3
  3. package/dist/assessment/choice.d.ts +26 -0
  4. package/dist/assessment/closure.js +2 -1
  5. package/dist/assessment/document.d.ts +39 -0
  6. package/dist/assessment/figure.d.ts +13 -0
  7. package/dist/assessment/fit.d.ts +16 -2
  8. package/dist/assessment/fit.js +23 -5
  9. package/dist/assessment/graphic.d.ts +27 -0
  10. package/dist/assessment/graphic.js +17 -1
  11. package/dist/assessment/hash.d.ts +777 -109
  12. package/dist/assessment/inline.d.ts +53 -0
  13. package/dist/assessment/inline.js +1 -0
  14. package/dist/assessment/interaction.d.ts +44 -1
  15. package/dist/assessment/interaction.js +2 -1
  16. package/dist/assessment/item.d.ts +500 -37
  17. package/dist/assessment/item.js +1 -1
  18. package/dist/assessment/joint.d.ts +4 -3
  19. package/dist/assessment/joint.js +4 -3
  20. package/dist/assessment/key.d.ts +138 -0
  21. package/dist/assessment/key.js +6 -0
  22. package/dist/assessment/paper.d.ts +1006 -90
  23. package/dist/assessment/part.d.ts +13 -0
  24. package/dist/assessment/profile.d.ts +3 -3
  25. package/dist/assessment/profile.js +4 -4
  26. package/dist/assessment/rows.d.ts +621 -39
  27. package/dist/assessment/scoring.d.ts +12 -6
  28. package/dist/assessment/scoring.js +25 -8
  29. package/dist/assessment/sketch.d.ts +125 -0
  30. package/dist/assessment/sketch.js +175 -0
  31. package/dist/assessment/snapshot.d.ts +1479 -91
  32. package/dist/assessment/structure.js +4 -4
  33. package/dist/release/snapshot/data.d.ts +114 -2
  34. package/dist/release/snapshot/verify.d.ts +621 -39
  35. package/dist/transport/group.d.ts +342 -6
  36. package/dist/transport/request.d.ts +4032 -316
  37. package/dist/transport/snapshot.d.ts +228 -4
  38. package/dist/visual/base/math.d.ts +56 -6
  39. package/dist/visual/base/media.d.ts +56 -6
  40. package/dist/visual/biology/bacteria.d.ts +224 -24
  41. package/dist/visual/biology/blood.d.ts +56 -6
  42. package/dist/visual/biology/cell.d.ts +168 -18
  43. package/dist/visual/biology/climate.d.ts +168 -18
  44. package/dist/visual/biology/ecology.d.ts +224 -24
  45. package/dist/visual/biology/heart.d.ts +56 -6
  46. package/dist/visual/biology/mitochondrion.d.ts +56 -6
  47. package/dist/visual/biology/muscle.d.ts +56 -6
  48. package/dist/visual/biology/neuron.d.ts +56 -6
  49. package/dist/visual/biology/paddy.d.ts +56 -6
  50. package/dist/visual/biology/physiology.d.ts +168 -18
  51. package/dist/visual/biology/plant.d.ts +280 -30
  52. package/dist/visual/biology/synapse.d.ts +56 -6
  53. package/dist/visual/biology/vessel.d.ts +56 -6
  54. package/dist/visual/biology/yeast.d.ts +56 -6
  55. package/dist/visual/card.d.ts +56 -6
  56. package/dist/visual/catalog.d.ts +16734 -5484
  57. package/dist/visual/chemistry/atom.d.ts +168 -18
  58. package/dist/visual/chemistry/balance.d.ts +280 -30
  59. package/dist/visual/chemistry/bonding.d.ts +280 -30
  60. package/dist/visual/chemistry/discovery.d.ts +392 -42
  61. package/dist/visual/chemistry/electrochemistry.d.ts +112 -12
  62. package/dist/visual/chemistry/electron.d.ts +112 -12
  63. package/dist/visual/chemistry/laws.d.ts +224 -24
  64. package/dist/visual/chemistry/particles.d.ts +280 -30
  65. package/dist/visual/chemistry/periodic.d.ts +112 -12
  66. package/dist/visual/chemistry/rate.d.ts +56 -6
  67. package/dist/visual/chemistry/reaction.d.ts +168 -18
  68. package/dist/visual/chemistry/titration.d.ts +56 -6
  69. package/dist/visual/length.d.ts +56 -6
  70. package/dist/visual/mathematics/chance.d.ts +168 -18
  71. package/dist/visual/mathematics/chart.d.ts +56 -6
  72. package/dist/visual/mathematics/charts.d.ts +280 -30
  73. package/dist/visual/mathematics/function.d.ts +168 -18
  74. package/dist/visual/mathematics/journey.d.ts +56 -6
  75. package/dist/visual/mathematics/logic.d.ts +56 -6
  76. package/dist/visual/mathematics/network.d.ts +56 -6
  77. package/dist/visual/mathematics/numeral.d.ts +168 -18
  78. package/dist/visual/mathematics/sets.d.ts +56 -6
  79. package/dist/visual/physics/braking.d.ts +224 -24
  80. package/dist/visual/physics/circuit.d.ts +224 -24
  81. package/dist/visual/physics/circular.d.ts +112 -12
  82. package/dist/visual/physics/dynamics.d.ts +392 -42
  83. package/dist/visual/physics/efficiency.d.ts +336 -36
  84. package/dist/visual/physics/electronics.d.ts +168 -18
  85. package/dist/visual/physics/falling.d.ts +224 -24
  86. package/dist/visual/physics/field.d.ts +168 -18
  87. package/dist/visual/physics/fluid.d.ts +224 -24
  88. package/dist/visual/physics/force.d.ts +280 -30
  89. package/dist/visual/physics/gravity.d.ts +112 -12
  90. package/dist/visual/physics/heat.d.ts +168 -18
  91. package/dist/visual/physics/instrument.d.ts +392 -42
  92. package/dist/visual/physics/light.d.ts +224 -24
  93. package/dist/visual/physics/measurement.d.ts +224 -24
  94. package/dist/visual/physics/motion.d.ts +336 -36
  95. package/dist/visual/physics/nuclear.d.ts +168 -18
  96. package/dist/visual/physics/parabolic.d.ts +56 -6
  97. package/dist/visual/physics/position.d.ts +336 -36
  98. package/dist/visual/physics/power.d.ts +448 -48
  99. package/dist/visual/physics/precision.d.ts +392 -42
  100. package/dist/visual/physics/product.d.ts +224 -24
  101. package/dist/visual/physics/reading.d.ts +168 -18
  102. package/dist/visual/physics/record.d.ts +112 -12
  103. package/dist/visual/physics/relative.d.ts +168 -18
  104. package/dist/visual/physics/solar.d.ts +336 -36
  105. package/dist/visual/physics/thermodynamics.d.ts +56 -6
  106. package/dist/visual/physics/vector.d.ts +280 -30
  107. package/dist/visual/physics/velocity.d.ts +392 -42
  108. package/dist/visual/physics/wave.d.ts +224 -24
  109. package/dist/visual/politics.d.ts +336 -36
  110. package/package.json +2 -2
@@ -161,14 +161,20 @@ export declare function scoreCeiling(rule: ScoringRule, parts: number): number;
161
161
  * work of Nakafa's engine.
162
162
  */
163
163
  export declare function pointsForWrongParts(rule: WrongPartsRule, wrongParts: number): number;
164
+ /**
165
+ * Checks that an interaction of this kind is scored by a rubric of its own,
166
+ * and never by a default: an extended text, whose criteria a grader reads, and
167
+ * a sketch, whose criteria are features of the drawn graph.
168
+ */
169
+ export declare function takesRubric(kind: InteractionKind): kind is "extendedText" | "sketch";
164
170
  /**
165
171
  * Checks that a rule can score an interaction of this kind. A rubric scores an
166
- * extended text and nothing else, and an extended text takes no other rule. A
167
- * field has one part, worth the points of its rule: one point, or more when
168
- * the item is worth more. The floor of a rule per part is at most those
169
- * points, and a wrong-parts table has one band for no wrong part. Every other
170
- * kind has the parts that its key counts, so the key checks the floor of a rule
171
- * for those.
172
+ * extended text or a sketch and nothing else, and they take no other rule; each
173
+ * criterion of a sketch is missed or earned. A field has one part, worth the
174
+ * points of its rule: one point, or more when the item is worth more. The
175
+ * floor of a rule per part is at most those points, and a wrong-parts table has
176
+ * one band for no wrong part. Every other kind has the parts that its key
177
+ * counts, so the key checks the floor of a rule for those.
172
178
  */
173
179
  export declare function supportsRule(kind: InteractionKind, rule: ScoringRule): boolean;
174
180
  /**
@@ -156,18 +156,35 @@ function fitsField(rule) {
156
156
  }
157
157
  return true;
158
158
  }
159
+ /**
160
+ * Checks that an interaction of this kind is scored by a rubric of its own,
161
+ * and never by a default: an extended text, whose criteria a grader reads, and
162
+ * a sketch, whose criteria are features of the drawn graph.
163
+ */
164
+ export function takesRubric(kind) {
165
+ return kind === "extendedText" || kind === "sketch";
166
+ }
167
+ /**
168
+ * Checks that every criterion of a rubric is missed or earned, as a feature of
169
+ * a sketch is: two levels, the lower one worth no points.
170
+ */
171
+ function isMissedOrEarned(rule) {
172
+ return Arr.every(rule.criteria, ({ levels }) => levels.length === 2 && Arr.some(levels, ({ points }) => points === 0));
173
+ }
159
174
  /**
160
175
  * Checks that a rule can score an interaction of this kind. A rubric scores an
161
- * extended text and nothing else, and an extended text takes no other rule. A
162
- * field has one part, worth the points of its rule: one point, or more when
163
- * the item is worth more. The floor of a rule per part is at most those
164
- * points, and a wrong-parts table has one band for no wrong part. Every other
165
- * kind has the parts that its key counts, so the key checks the floor of a rule
166
- * for those.
176
+ * extended text or a sketch and nothing else, and they take no other rule; each
177
+ * criterion of a sketch is missed or earned. A field has one part, worth the
178
+ * points of its rule: one point, or more when the item is worth more. The
179
+ * floor of a rule per part is at most those points, and a wrong-parts table has
180
+ * one band for no wrong part. Every other kind has the parts that its key
181
+ * counts, so the key checks the floor of a rule for those.
167
182
  */
168
183
  export function supportsRule(kind, rule) {
169
- return ((kind === "extendedText") === (rule.kind === "rubric") &&
170
- (!canSitInText(kind) || fitsField(rule)));
184
+ if (rule.kind === "rubric") {
185
+ return takesRubric(kind) && (kind !== "sketch" || isMissedOrEarned(rule));
186
+ }
187
+ return !takesRubric(kind) && (!canSitInText(kind) || fitsField(rule));
171
188
  }
172
189
  /**
173
190
  * Whole marks that a penalized exam awards for a correct, a wrong, and a blank
@@ -0,0 +1,125 @@
1
+ import { Schema } from "effect";
2
+ /** One key feature of a graph, in the units of the plane. */
3
+ export declare const SketchFeatureSchema: Schema.Union<readonly [Schema.Struct<{
4
+ readonly contact: Schema.Literals<readonly ["cross", "touch"]>;
5
+ readonly kind: Schema.Literal<"zero">;
6
+ readonly x: Schema.String;
7
+ }>, Schema.Struct<{
8
+ readonly kind: Schema.Literal<"yIntercept">;
9
+ readonly y: Schema.String;
10
+ }>, Schema.Struct<{
11
+ readonly kind: Schema.Literal<"extremum">;
12
+ readonly turn: Schema.Literals<readonly ["maximum", "minimum"]>;
13
+ readonly x: Schema.String;
14
+ readonly y: Schema.String;
15
+ }>, Schema.Struct<{
16
+ readonly kind: Schema.Literal<"asymptote">;
17
+ readonly line: Schema.Union<readonly [Schema.Struct<{
18
+ readonly kind: Schema.Literal<"vertical">;
19
+ readonly x: Schema.String;
20
+ }>, Schema.Struct<{
21
+ readonly intercept: Schema.String;
22
+ readonly kind: Schema.Literal<"sloped">;
23
+ readonly slope: Schema.String;
24
+ }>]>;
25
+ }>, Schema.Struct<{
26
+ readonly direction: Schema.Literals<readonly ["falling", "rising"]>;
27
+ readonly from: Schema.NullOr<Schema.String>;
28
+ readonly kind: Schema.Literal<"interval">;
29
+ readonly to: Schema.NullOr<Schema.String>;
30
+ }>, Schema.Struct<{
31
+ readonly kind: Schema.Literal<"end">;
32
+ readonly limit: Schema.Union<readonly [Schema.Literals<readonly ["negativeInfinity", "positiveInfinity"]>, Schema.String]>;
33
+ readonly side: Schema.Literals<readonly ["left", "right"]>;
34
+ }>, Schema.Struct<{
35
+ readonly kind: Schema.Literal<"inflection">;
36
+ readonly x: Schema.String;
37
+ readonly y: Schema.String;
38
+ }>, Schema.Struct<{
39
+ readonly end: Schema.optionalKey<Schema.Literals<readonly ["closed", "open"]>>;
40
+ readonly kind: Schema.Literal<"point">;
41
+ readonly x: Schema.String;
42
+ readonly y: Schema.String;
43
+ }>]>;
44
+ export type SketchFeature = typeof SketchFeatureSchema.Type;
45
+ /**
46
+ * What the learner reads about one criterion of a rubric once it is scored, in
47
+ * a teacher's voice: a line for a criterion earned and one for a criterion
48
+ * missed. It is words of a language, so translations may change it.
49
+ */
50
+ export declare const CriterionFeedbackSchema: Schema.Struct<{
51
+ readonly earned: Schema.Trimmed;
52
+ readonly missed: Schema.Trimmed;
53
+ }>;
54
+ /**
55
+ * The key of a sketch: the features its graph must show, each a criterion of
56
+ * the item's rubric, and the tolerances they are judged with. A grader reads
57
+ * the features of the learner's strokes exactly, never from pixels, and awards
58
+ * a criterion only when every criterion it requires is earned.
59
+ */
60
+ export declare const SketchKeySchema: Schema.Struct<{
61
+ readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
62
+ readonly check: Schema.Struct<{
63
+ readonly feature: Schema.Union<readonly [Schema.Struct<{
64
+ readonly contact: Schema.Literals<readonly ["cross", "touch"]>;
65
+ readonly kind: Schema.Literal<"zero">;
66
+ readonly x: Schema.String;
67
+ }>, Schema.Struct<{
68
+ readonly kind: Schema.Literal<"yIntercept">;
69
+ readonly y: Schema.String;
70
+ }>, Schema.Struct<{
71
+ readonly kind: Schema.Literal<"extremum">;
72
+ readonly turn: Schema.Literals<readonly ["maximum", "minimum"]>;
73
+ readonly x: Schema.String;
74
+ readonly y: Schema.String;
75
+ }>, Schema.Struct<{
76
+ readonly kind: Schema.Literal<"asymptote">;
77
+ readonly line: Schema.Union<readonly [Schema.Struct<{
78
+ readonly kind: Schema.Literal<"vertical">;
79
+ readonly x: Schema.String;
80
+ }>, Schema.Struct<{
81
+ readonly intercept: Schema.String;
82
+ readonly kind: Schema.Literal<"sloped">;
83
+ readonly slope: Schema.String;
84
+ }>]>;
85
+ }>, Schema.Struct<{
86
+ readonly direction: Schema.Literals<readonly ["falling", "rising"]>;
87
+ readonly from: Schema.NullOr<Schema.String>;
88
+ readonly kind: Schema.Literal<"interval">;
89
+ readonly to: Schema.NullOr<Schema.String>;
90
+ }>, Schema.Struct<{
91
+ readonly kind: Schema.Literal<"end">;
92
+ readonly limit: Schema.Union<readonly [Schema.Literals<readonly ["negativeInfinity", "positiveInfinity"]>, Schema.String]>;
93
+ readonly side: Schema.Literals<readonly ["left", "right"]>;
94
+ }>, Schema.Struct<{
95
+ readonly kind: Schema.Literal<"inflection">;
96
+ readonly x: Schema.String;
97
+ readonly y: Schema.String;
98
+ }>, Schema.Struct<{
99
+ readonly end: Schema.optionalKey<Schema.Literals<readonly ["closed", "open"]>>;
100
+ readonly kind: Schema.Literal<"point">;
101
+ readonly x: Schema.String;
102
+ readonly y: Schema.String;
103
+ }>]>;
104
+ readonly kind: Schema.Literal<"feature">;
105
+ }>;
106
+ readonly criterion: Schema.String;
107
+ readonly feedback: Schema.Struct<{
108
+ readonly earned: Schema.Trimmed;
109
+ readonly missed: Schema.Trimmed;
110
+ }>;
111
+ readonly requires: Schema.optionalKey<Schema.NonEmptyArray<Schema.String>>;
112
+ }>>;
113
+ readonly interaction: Schema.String;
114
+ readonly kind: Schema.Literal<"sketch">;
115
+ readonly tolerances: Schema.Struct<{
116
+ readonly asymptote: Schema.optionalKey<Schema.String>;
117
+ readonly end: Schema.optionalKey<Schema.String>;
118
+ readonly extremum: Schema.optionalKey<Schema.String>;
119
+ readonly inflection: Schema.optionalKey<Schema.String>;
120
+ readonly interval: Schema.optionalKey<Schema.String>;
121
+ readonly point: Schema.optionalKey<Schema.String>;
122
+ readonly yIntercept: Schema.optionalKey<Schema.String>;
123
+ readonly zero: Schema.optionalKey<Schema.String>;
124
+ }>;
125
+ }>;
@@ -0,0 +1,175 @@
1
+ import { Array as Arr, BigDecimal, HashSet, Schema } from "effect";
2
+ import { DecimalSchema, PositiveDecimalSchema, } from "#contracts/assessment/answer";
3
+ import { hasDistinctIds, LocalIdSchema } from "#contracts/assessment/identity";
4
+ import { PlainTextSchema } from "#contracts/assessment/scalar";
5
+ /** Where a graph meets the x-axis, and whether it crosses there or touches and turns back. */
6
+ const ZeroFeatureSchema = Schema.Struct({
7
+ contact: Schema.Literals(["cross", "touch"]),
8
+ kind: Schema.Literal("zero"),
9
+ x: DecimalSchema,
10
+ });
11
+ /** Where a graph crosses the y-axis. */
12
+ const InterceptFeatureSchema = Schema.Struct({
13
+ kind: Schema.Literal("yIntercept"),
14
+ y: DecimalSchema,
15
+ });
16
+ /** A turning point: a local maximum or minimum. */
17
+ const ExtremumFeatureSchema = Schema.Struct({
18
+ kind: Schema.Literal("extremum"),
19
+ turn: Schema.Literals(["maximum", "minimum"]),
20
+ x: DecimalSchema,
21
+ y: DecimalSchema,
22
+ });
23
+ /**
24
+ * A line the graph comes ever closer to: vertical at an x, or `y = slope * x +
25
+ * intercept`, which is horizontal when the slope is zero and oblique otherwise.
26
+ */
27
+ const AsymptoteFeatureSchema = Schema.Struct({
28
+ kind: Schema.Literal("asymptote"),
29
+ line: Schema.Union([
30
+ Schema.Struct({ kind: Schema.Literal("vertical"), x: DecimalSchema }),
31
+ Schema.Struct({
32
+ intercept: DecimalSchema,
33
+ kind: Schema.Literal("sloped"),
34
+ slope: DecimalSchema,
35
+ }),
36
+ ]),
37
+ });
38
+ /** Whether `from` lies left of `to`, exactly; an open end, written null, is unbounded. */
39
+ function isOrdered(from, to) {
40
+ return (from === null ||
41
+ to === null ||
42
+ BigDecimal.isLessThan(BigDecimal.fromStringUnsafe(from), BigDecimal.fromStringUnsafe(to)));
43
+ }
44
+ /** A stretch where the graph only rises or only falls; a null end is unbounded. */
45
+ const IntervalFeatureSchema = Schema.Struct({
46
+ direction: Schema.Literals(["falling", "rising"]),
47
+ from: Schema.NullOr(DecimalSchema),
48
+ kind: Schema.Literal("interval"),
49
+ to: Schema.NullOr(DecimalSchema),
50
+ }).check(Schema.makeFilter(({ from, to }) => isOrdered(from, to), {
51
+ message: "Expected an interval whose start lies left of its end.",
52
+ }));
53
+ /**
54
+ * Where the graph goes at one side: up or down without bound, or towards a
55
+ * value. An end without bound is earned when the graph's outermost stretch on
56
+ * that side moves away in the limit's direction as it goes out along that side,
57
+ * up for `positiveInfinity` and down for `negativeInfinity`: on the left that
58
+ * stretch falls from left to right for `positiveInfinity`, on the right it
59
+ * rises. No distance measures it, so it takes no tolerance. An end towards a
60
+ * value is earned when the graph's last point on that side lies within the end
61
+ * tolerance of it.
62
+ */
63
+ const EndFeatureSchema = Schema.Struct({
64
+ kind: Schema.Literal("end"),
65
+ limit: Schema.Union([
66
+ Schema.Literals(["negativeInfinity", "positiveInfinity"]),
67
+ DecimalSchema,
68
+ ]),
69
+ side: Schema.Literals(["left", "right"]),
70
+ });
71
+ /** A point where the graph changes how it bends, from concave up to concave down or back. */
72
+ const InflectionFeatureSchema = Schema.Struct({
73
+ kind: Schema.Literal("inflection"),
74
+ x: DecimalSchema,
75
+ y: DecimalSchema,
76
+ });
77
+ /**
78
+ * A point the graph passes through, such as a given point or an end of its
79
+ * domain. `end`, when present, says that the graph stops there and whether the
80
+ * point belongs to it (`closed`, drawn filled) or not (`open`, drawn hollow).
81
+ */
82
+ const PointFeatureSchema = Schema.Struct({
83
+ end: Schema.optionalKey(Schema.Literals(["closed", "open"])),
84
+ kind: Schema.Literal("point"),
85
+ x: DecimalSchema,
86
+ y: DecimalSchema,
87
+ });
88
+ /** One key feature of a graph, in the units of the plane. */
89
+ export const SketchFeatureSchema = Schema.Union([
90
+ ZeroFeatureSchema,
91
+ InterceptFeatureSchema,
92
+ ExtremumFeatureSchema,
93
+ AsymptoteFeatureSchema,
94
+ IntervalFeatureSchema,
95
+ EndFeatureSchema,
96
+ InflectionFeatureSchema,
97
+ PointFeatureSchema,
98
+ ]);
99
+ /**
100
+ * How far a drawn feature may lie from the key's and still earn its
101
+ * criterion, in the units of the plane, for each kind of feature the key
102
+ * holds. A zero, an intercept and an interval's ends are judged along the
103
+ * axis they lie on; an extremum, an inflection and a point by their distance in
104
+ * each axis; an asymptote by its distance across the frame; an end only when
105
+ * it tends towards a value.
106
+ */
107
+ const SketchTolerancesSchema = Schema.Struct({
108
+ asymptote: Schema.optionalKey(PositiveDecimalSchema),
109
+ end: Schema.optionalKey(PositiveDecimalSchema),
110
+ extremum: Schema.optionalKey(PositiveDecimalSchema),
111
+ inflection: Schema.optionalKey(PositiveDecimalSchema),
112
+ interval: Schema.optionalKey(PositiveDecimalSchema),
113
+ point: Schema.optionalKey(PositiveDecimalSchema),
114
+ yIntercept: Schema.optionalKey(PositiveDecimalSchema),
115
+ zero: Schema.optionalKey(PositiveDecimalSchema),
116
+ });
117
+ /**
118
+ * What the learner reads about one criterion of a rubric once it is scored, in
119
+ * a teacher's voice: a line for a criterion earned and one for a criterion
120
+ * missed. It is words of a language, so translations may change it.
121
+ */
122
+ export const CriterionFeedbackSchema = Schema.Struct({
123
+ earned: PlainTextSchema,
124
+ missed: PlainTextSchema,
125
+ });
126
+ /**
127
+ * One criterion of a sketch's rubric. Its points are the levels of the rubric
128
+ * rule with the same `criterion`; the key says how it is checked and what the
129
+ * learner reads when it is earned or missed, in a teacher's voice. A `feature`
130
+ * check is graded by code from the drawn strokes and marks. `requires` names
131
+ * criteria that must be earned first, written before this one, such as the
132
+ * shape of the graph before any of its points.
133
+ */
134
+ const SketchCriterionSchema = Schema.Struct({
135
+ check: Schema.Struct({
136
+ feature: SketchFeatureSchema,
137
+ kind: Schema.Literal("feature"),
138
+ }),
139
+ criterion: LocalIdSchema,
140
+ feedback: CriterionFeedbackSchema,
141
+ requires: Schema.optionalKey(Schema.NonEmptyArray(LocalIdSchema)),
142
+ });
143
+ /** Checks that each criterion requires only criteria written before it, so no chain of requirements loops. */
144
+ function requiresEarlier(criteria) {
145
+ return Arr.every(criteria, ({ requires }, index) => {
146
+ const earlier = HashSet.fromIterable(Arr.map(Arr.take(criteria, index), ({ criterion }) => criterion));
147
+ return Arr.every(requires ?? [], (id) => HashSet.has(earlier, id));
148
+ });
149
+ }
150
+ /** Checks that the key has a tolerance for every kind of feature that a criterion checks, apart from an end towards infinity. */
151
+ function hasTolerances({ criteria, tolerances, }) {
152
+ return Arr.every(criteria, ({ check: { feature } }) => isUnbounded(feature) || tolerances[feature.kind] !== undefined);
153
+ }
154
+ /** Whether a feature is an end that goes up or down without bound, which no distance measures. */
155
+ function isUnbounded(feature) {
156
+ return (feature.kind === "end" &&
157
+ (feature.limit === "negativeInfinity" ||
158
+ feature.limit === "positiveInfinity"));
159
+ }
160
+ /**
161
+ * The key of a sketch: the features its graph must show, each a criterion of
162
+ * the item's rubric, and the tolerances they are judged with. A grader reads
163
+ * the features of the learner's strokes exactly, never from pixels, and awards
164
+ * a criterion only when every criterion it requires is earned.
165
+ */
166
+ export const SketchKeySchema = Schema.Struct({
167
+ criteria: Schema.NonEmptyArray(SketchCriterionSchema).check(Schema.makeFilter((criteria) => hasDistinctIds(Arr.map(criteria, ({ criterion }) => criterion)), { message: "Expected no criterion to be named twice." }), Schema.makeFilter(requiresEarlier, {
168
+ message: "Expected each criterion to require only criteria before it.",
169
+ })),
170
+ interaction: LocalIdSchema,
171
+ kind: Schema.Literal("sketch"),
172
+ tolerances: SketchTolerancesSchema,
173
+ }).check(Schema.makeFilter(hasTolerances, {
174
+ message: "Expected a tolerance for every kind of feature the key checks.",
175
+ }));