Skip to content

Commit 1a1feaa

Browse files
authored
Merge pull request #68 from Simon-Initiative/AUTHORING-2269-image_hotspot-fix
Authoring 2269 image hotspot fix
2 parents 5dcf9b4 + ce9f469 commit 1a1feaa

5 files changed

Lines changed: 232 additions & 4 deletions

File tree

src/main/java/edu/cmu/oli/assessment/builders/Assessment2Transform.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public Element transformToUnified(Element root) {
7575
select.detach();
7676
element.setAttribute(select);
7777
}
78+
Attribute grading = next.getAttribute("grading");
79+
if (grading != null) {
80+
grading.detach();
81+
element.setAttribute(grading);
82+
}
7883
});
7984
}
8085
if (inputs.hasNext()) {
@@ -87,7 +92,7 @@ public Element transformToUnified(Element root) {
8792
}
8893

8994
});
90-
} else if (inputRefs.hasNext()) {
95+
} else if (inputRefs.hasNext() && !next.getName().equalsIgnoreCase("image_hotspot")) {
9196
List<Element> refs = new ArrayList<>();
9297
inputRefs.forEach(element -> refs.add(element));
9398
for (int i = 0; i < refs.size(); i++) {
@@ -100,7 +105,7 @@ public Element transformToUnified(Element root) {
100105
ty.setAttribute(select);
101106
}
102107
}
103-
} else {
108+
} else if (!next.getName().equalsIgnoreCase("image_hotspot")) {
104109
Element input = next.getChild("input");
105110
if (input == null) {
106111
input = new Element(next.getName());
@@ -190,6 +195,14 @@ public Element transformFromUnified(Element root) {
190195
case "image_hotspot":
191196
questionType.forEach(element -> {
192197
element.setName("image_input");
198+
element.getAttributes().forEach(attribute -> {
199+
if (attribute.getName().equalsIgnoreCase("select") ||
200+
attribute.getName().equalsIgnoreCase("grading")) {
201+
attribute.detach();
202+
((Element) element.getParent()).setAttribute(attribute);
203+
}
204+
});
205+
193206
});
194207
break;
195208
default:

src/main/java/edu/cmu/oli/assessment/evaluators/MatcherByType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* @author Raphael Gachuhi
4343
*/
4444
public class MatcherByType {
45-
4645
JsonObject interaction;
4746

4847
public MatcherByType(JsonObject interaction) {

src/main/java/edu/cmu/oli/content/controllers/LDModelControllerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,12 @@ private void tagPartWithSkill(String skillId, JsonElement part) {
10221022
JsonArray stepArray = partAsJsonObject.getAsJsonArray("#array");
10231023

10241024
boolean skillRefAlreadyExists = false;
1025+
int index = -1;
10251026
try {
10261027
for (JsonElement next : stepArray) {
1028+
if(next.isJsonObject() && next.getAsJsonObject().has("title")){
1029+
index = 0;
1030+
}
10271031
if (next.isJsonObject() && next.getAsJsonObject().has("skillref") && next.getAsJsonObject()
10281032
.get("skillref").getAsJsonObject().get("@idref").getAsString().equals(skillId)) {
10291033
skillRefAlreadyExists = true;
@@ -1034,7 +1038,7 @@ private void tagPartWithSkill(String skillId, JsonElement part) {
10341038
log.error(AppUtils.gsonBuilder().create().toJson(part));
10351039
throw e;
10361040
}
1037-
tagWithSkill(skillId, part, stepArray, -1, skillRefAlreadyExists);
1041+
tagWithSkill(skillId, part, stepArray, index, skillRefAlreadyExists);
10381042
}
10391043

10401044
private void findAllParts(JsonElement content, List<JsonElement> parts) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package edu.cmu.oli.content.resource.builders;
2+
3+
import edu.cmu.oli.assessment.builders.Assessment2Transform;
4+
import edu.cmu.oli.content.contentfiles.utils.ResourceTestPipeline;
5+
import org.jdom2.Document;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
import static org.junit.Assert.assertTrue;
13+
14+
/**
15+
* @author Raphael Gachuhi
16+
*/
17+
public class ImageHotspotTransformTest {
18+
19+
private Assessment2Transform cut;
20+
21+
@Before
22+
public void setUp() {
23+
cut = new Assessment2Transform();
24+
}
25+
26+
@Test
27+
public void transformToUnified() throws Exception {
28+
final List<Boolean> errors = new ArrayList<>();
29+
final ResourceTestPipeline pipeline = new ResourceTestPipeline(
30+
ImageHotspotTransformTest.class.getResource("test-resources/_m4_assess.xml"),
31+
"x-oli-assessment2") {
32+
33+
@Override
34+
public Document afterStringToDoc(final Document doc) {
35+
cut.transformToUnified(doc.getRootElement());
36+
return super.afterStringToDoc(doc);
37+
}
38+
39+
@Override
40+
public Document afterJsonToDoc(Document doc) {
41+
cut.transformFromUnified(doc.getRootElement());
42+
return super.afterJsonToDoc(doc);
43+
}
44+
};
45+
46+
pipeline.execute();
47+
48+
assertTrue(errors.isEmpty());
49+
}
50+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE assessment PUBLIC "-//Carnegie Mellon University//DTD Assessment MathML 2.4//EN" "http://oli.web.cmu.edu/dtd/oli_assessment_mathml_2_4.dtd">
2+
<assessment xmlns:cmd="http://oli.web.cmu.edu/content/metadata/2.1/" id="_m4_assess">
3+
<title>Effects of Multiple Forces</title>
4+
<page>
5+
<numeric id="q1">
6+
<body><p>Two forces are applied to the body via cables. Both forces act through the
7+
point (x,y)=(3,2) and the line of action of the force F<sub>1</sub> passes
8+
through (x,y)=(2,5). You are to replace the two cables by a single cable that is
9+
produces the same effect on the body. </p><image src="../webcontent/statics_quiz4_image1.gif"/><p>First, deter mine the
10+
components of the forces F<sub>1</sub> and F<sub>2</sub>:</p><ul>
11+
<li><p>x-component of F<sub>1</sub> = <input_ref input="i1"/> N</p></li>
12+
<li><p>y-component of F<sub>1</sub> = <input_ref input="i2"/> N</p></li>
13+
<li><p>x-compo nent of F<sub>2</sub> = <input_ref input="i3"/> N</p></li>
14+
<li><p>y-component of F<sub>2</sub> = <input_ref input="i4"/> N</p></li>
15+
</ul></body>
16+
<input id="i1"/>
17+
<input id="i2"/>
18+
<input id="i3"/>
19+
<input id="i4"/>
20+
<part id="p1">
21+
<skillref idref="resolve_into_components"/>
22+
<response name="-1.58" input="i1" match="(-1.659,-1.501)" score="5"/>
23+
<response input="i1" match="*" score="0"/>
24+
<no_response score="0"/>
25+
</part>
26+
<part id="p2">
27+
<skillref idref="resolve_into_components"/>
28+
<response name="4.74" input="i2" match="(4.503,4.977)" score="5"/>
29+
<response input="i2" match="*" score="0"/>
30+
<no_response score="0"/>
31+
</part>
32+
<part id="p3">
33+
<skillref idref="resolve_into_components"/>
34+
<response name="17" input="i3 " match="(16.15,17.85)" score="5"/>
35+
<response input="i3" match="*" score="0"/>
36+
<no_response score="0"/>
37+
</part>
38+
<part id="p4">
39+
<skillref idref="resolve_into_components"/>
40+
<response name="-10" input="i4" match="(-10.5,-9.5)" score="5"/>
41+
<response input="i4" match="*" score="0"/>
42+
<no_response score="0"/>
43+
</part>
44+
</numeric>
45+
<numeric id="q2">
46+
<body><p>What is the tension in the single replacement cable? <input_ref input="i1"/>
47+
N</p></body>
48+
<input id="i1"/>
49+
<part id="p1">
50+
<skillref idref="find_magnitude_given_components"/>
51+
<response name="16.6" input="i1" match="(15.77,17.43)" score="15"/>
52+
<response input="i1" match="*" score="0"/>
53+
<no_response score="0"/>
54+
</part>
55+
</numeric>
56+
<numeric id="q3">
57+
<body><p>What is the angle α that the single replacement cable forms with the x axis?
58+
(enter a positive number) <input_ref input="i1"/> degrees</p></body>
59+
<input id="i1"/>
60+
<part id="p1">
61+
<skillref idref="find_angle_given_components"/>
62+
<response name="18.5" input="i1" match="(17.575,19.425)" score="15"/>
63+
<response name="341.5" input="i1" match="(324.425,358.575)" score="15"/>
64+
<response input="i1" match="*" score="0"/>
65+
<no_response score="0"/>
66+
</part>
67+
</numeric>
68+
<image_hotspot id="q4" select="single">
69+
<body><p>Indicate the direction of the single replacement cable by clicking on the
70+
appropriate quadrant:</p><input_ref input="direction"/></body>
71+
<image_input id="direction" src="../webcontent/statics_ quiz4_image2.gif" width="107"
72+
height="108">
73+
<hotspot shape="rect" value="up_and_left" coords="0,0,53,52">Up and Left</hotspot>
74+
<hotspot shape="rect" value="up_and_right" coords="54,0,107,52">Up and
75+
Right</hotspot>
76+
<hotspot shape="rect" value="down_and_left" coords="0,53,53,105">Down and
77+
Left</hotspot>
78+
<hotspot shape="rect" value="down_and_right" coords="54,53,107,105">Down and
79+
Right</hotspot>
80+
</image_input>
81+
<part id="p1">
82+
<skillref idref="find_angle_given_components"/>
83+
<response name="up and left" input="direction" match="up_and_left" score="0"/>
84+
<response name="up and right" input="direction" match="up_and_right" score="0"/>
85+
<response name="down and left" input="direction" match="dow n_and_left" score="0"/>
86+
<response name="down and right" input="direction" match="down_and_right" score="5"/>
87+
<no_response score="0"/>
88+
</part>
89+
</image_hotspot>
90+
</page>
91+
<page>
92+
<content>
93+
<p>Determine the moment created by the two forces about the point O.</p>
94+
<image src="../webcontent/statics_quiz4_image3.gif"/>
95+
</content>
96+
<numeric id="q5">
97+
<body><p>Magnitude of moment (enter positive number) = <input_ref input="i1"/>
98+
lb-in</p></body>
99+
<input id="i1"/>
100+
<part id="p1">
101+
<skillref idref="determine_moment"/>
102+
<response name="10" input="i1" match="(9.5, 10.5)" score="10"/>
103+
<response input="i1" match="*" score="0"/>
104+
<no_response score="0"/>
105+
</part>
106+
</numeric>
107+
<fill_in_the_blank id="q6">
108+
<body><p>Sense of moment = <input_ref input="i1"/></p></body>
109+
<input id="i1" shuffle="false">
110+
<choice value="cw">CW</choice>
111+
<choice value="ccw">CCW</choice>
112+
</input>
113+
<part id="p1">
114+
<skillref idref="moment_sign_sense_relation"/>
115+
<response name="CW" input="i1" match="cw " score="5"/>
116+
<response name="CCW" input="i1" match="ccw" score="0"/>
117+
<no_response score="0"/>
118+
</part>
119+
</fill_in_the_blank>
120+
</page>
121+
<page>
122+
<content>
123+
<p>Determine the moment of the force about the point O.</p>
124+
<image src="../webcontent/stati cs_quiz4_image4.gif"/>
125+
</content>
126+
<numeric id="q7">
127+
<body><p>Component of F perpendicular to OP = <input_ref input="i1"/> N</p></body>
128+
<input id="i1"/>
129+
<part id="p1">
130+
<skillref idref="resolve_into_components"/>
131+
<response name="15.32" input="i1" match="(14.554, 16.086)" score="15"/>
132+
<response input="i1" match="*" score="0"/>
133+
<no_response score="0"/>
134+
</part>
135+
</numeric>
136+
<numeric id="q8">
137+
<body><p>Magnitude of moment (enter positive number; pay attention to units) =
138+
<input_ref input="i1"/> N-m</p></body>
139+
<input id="i1"/>
140+
<part id="p1">
141+
<skillref idref="find_moment_arm"/>
142+
<response name="7.66" input="i1" match="(7.277, 8.043)" score="15"/>
143+
<response input="i1" match="*" score="0"/>
144+
<no_response score="0"/>
145+
</part>
146+
</numeric>
147+
<fill_in_the_blank id="q9">
148+
<body><p>Sense of moment = <input_ref input="i1"/></p></body>
149+
<input id="i1" shuffle="false">
150+
<choice value="cw">CW</choice>
151+
<choice value="ccw">CCW</choice>
152+
</input>
153+
<part id="p1">
154+
<skillref idref="moment_sign_sense_relation"/>
155+
<skillref idref="rotation_sense_of_force"/>
156+
<response name="CW" input="i1" match="cw" score="0"/>
157+
<response name="CCW" input="i1" match="ccw" score="5"/>
158+
<no_response score="0"/>
159+
</part>
160+
</fill_in_the_blank>
161+
</page>
162+
</assessment>

0 commit comments

Comments
 (0)