Skip to content

Commit a6d2264

Browse files
committed
ActivityDefinition InteractionType
ActivityDefinition has been extended to include: interactionType correctResponsesPattern choices scale target step This as been based on the work carried out by Paul Carpenter and is my first GitHub submission.
1 parent c38178a commit a6d2264

File tree

6 files changed

+293
-10
lines changed

6 files changed

+293
-10
lines changed

TinCan.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinCan", "TinCan\TinCan.csproj", "{27D0FCA1-E869-440C-9D16-F62D7A068C53}"
57
EndProject
68
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinCanTests", "TinCanTests\TinCanTests.csproj", "{854413C2-2F81-4A82-9949-DE2868A10078}"

TinCan/ActivityDefinition.cs

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ You may obtain a copy of the License at
1414
limitations under the License.
1515
*/
1616
using System;
17+
using System.Linq;
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
1720
using Newtonsoft.Json.Linq;
1821
using TinCan.Json;
1922

23+
2024
namespace TinCan
2125
{
2226
public class ActivityDefinition : JsonModel
@@ -26,13 +30,13 @@ public class ActivityDefinition : JsonModel
2630
public LanguageMap name { get; set; }
2731
public LanguageMap description { get; set; }
2832
public Extensions extensions { get; set; }
29-
//public InteractionType interactionType { get; set; }
30-
//public List<String> correctResponsesPattern { get; set; }
31-
//public List<InteractionComponent> choices { get; set; }
32-
//public List<InteractionComponent> scale { get; set; }
33-
//public List<InteractionComponent> source { get; set; }
34-
//public List<InteractionComponent> target { get; set; }
35-
//public List<InteractionComponent> steps { get; set; }
33+
public InteractionType interactionType { get; set; }
34+
public List<String> correctResponsesPattern { get; set; }
35+
public List<InteractionComponent> choices { get; set; }
36+
public List<InteractionComponent> scale { get; set; }
37+
public List<InteractionComponent> source { get; set; }
38+
public List<InteractionComponent> target { get; set; }
39+
public List<InteractionComponent> steps { get; set; }
3640

3741
public ActivityDefinition() {}
3842

@@ -60,11 +64,62 @@ public ActivityDefinition(JObject jobj)
6064
{
6165
extensions = (Extensions)jobj.Value<JObject>("extensions");
6266
}
67+
if (jobj["interactionType"] != null)
68+
{
69+
interactionType = InteractionType.FromValue(jobj.Value<String>("interactionType"));
70+
}
71+
if (jobj["correctResponsesPattern"] != null)
72+
{
73+
correctResponsesPattern = ((JArray)jobj["correctResponsesPattern"]).Select(x => x.Value<String>()).ToList<String>();
74+
}
75+
if (jobj["choices"] != null)
76+
{
77+
choices = new List<InteractionComponent>();
78+
foreach (JObject jchoice in jobj["choices"])
79+
{
80+
choices.Add(new InteractionComponent(jchoice));
81+
}
82+
}
83+
if (jobj["scale"] != null)
84+
{
85+
scale = new List<InteractionComponent>();
86+
foreach (JObject jscale in jobj["scale"])
87+
{
88+
scale.Add(new InteractionComponent(jscale));
89+
}
90+
}
91+
if (jobj["source"] != null)
92+
{
93+
source = new List<InteractionComponent>();
94+
foreach (JObject jsource in jobj["source"])
95+
{
96+
source.Add(new InteractionComponent(jsource));
97+
}
98+
}
99+
if (jobj["target"] != null)
100+
{
101+
target = new List<InteractionComponent>();
102+
foreach (JObject jtarget in jobj["target"])
103+
{
104+
target.Add(new InteractionComponent(jtarget));
105+
}
106+
}
107+
if (jobj["steps"] != null)
108+
{
109+
steps = new List<InteractionComponent>();
110+
foreach (JObject jstep in jobj["steps"])
111+
{
112+
steps.Add(new InteractionComponent(jstep));
113+
}
114+
}
115+
116+
117+
63118
}
64119

65120
public override JObject ToJObject(TCAPIVersion version) {
66121
JObject result = new JObject();
67-
122+
68123
if (type != null)
69124
{
70125
result.Add("type", type.ToString());
@@ -85,6 +140,64 @@ public override JObject ToJObject(TCAPIVersion version) {
85140
{
86141
result.Add("extensions", extensions.ToJObject(version));
87142
}
143+
if (interactionType != null)
144+
{
145+
result.Add("interactionType", interactionType.Value);
146+
}
147+
if (correctResponsesPattern != null && correctResponsesPattern.Count > 0)
148+
{
149+
result.Add("correctResponsesPattern", JToken.FromObject(correctResponsesPattern));
150+
}
151+
if (choices != null && choices.Count > 0)
152+
{
153+
var jchoices = new JArray();
154+
result.Add("choices", jchoices);
155+
156+
foreach (InteractionComponent ichoice in choices)
157+
{
158+
jchoices.Add(ichoice.ToJObject(version));
159+
}
160+
}
161+
if (scale != null && scale.Count > 0)
162+
{
163+
var jscale = new JArray();
164+
result.Add("scale", jscale);
165+
166+
foreach (InteractionComponent iscale in scale)
167+
{
168+
jscale.Add(iscale.ToJObject(version));
169+
}
170+
}
171+
if (source != null && source.Count > 0)
172+
{
173+
var jsource = new JArray();
174+
result.Add("source", jsource);
175+
176+
foreach (InteractionComponent isource in source)
177+
{
178+
jsource.Add(isource.ToJObject(version));
179+
}
180+
}
181+
if (target != null && target.Count > 0)
182+
{
183+
var jtarget = new JArray();
184+
result.Add("target", jtarget);
185+
186+
foreach (InteractionComponent itarget in target)
187+
{
188+
jtarget.Add(itarget.ToJObject(version));
189+
}
190+
}
191+
if (steps != null && steps.Count > 0)
192+
{
193+
var jsteps = new JArray();
194+
result.Add("steps", jsteps);
195+
196+
foreach (InteractionComponent istep in steps)
197+
{
198+
jsteps.Add(istep.ToJObject(version));
199+
}
200+
}
88201

89202
return result;
90203
}

TinCan/InteractionComponent.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2014 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
using System;
17+
using System.Collections.Generic;
18+
using Newtonsoft.Json.Linq;
19+
using TinCan.Json;
20+
21+
namespace TinCan
22+
{
23+
public class InteractionComponent : JsonModel
24+
{
25+
public String id;
26+
public LanguageMap description { get; set; }
27+
28+
public InteractionComponent()
29+
{
30+
31+
}
32+
33+
public InteractionComponent(JObject jobj)
34+
{
35+
if (jobj["id"] != null)
36+
{
37+
id = jobj.Value<String>("id");
38+
}
39+
if (jobj["description"] != null)
40+
{
41+
description = (LanguageMap)jobj.Value<JObject>("description");
42+
}
43+
44+
}
45+
46+
public override JObject ToJObject(TCAPIVersion version) {
47+
JObject result = new JObject();
48+
49+
if (id != null)
50+
{
51+
result.Add("id", id);
52+
}
53+
if (description != null && !description.isEmpty())
54+
{
55+
result.Add("description", description.ToJObject(version));
56+
}
57+
58+
return result;
59+
}
60+
61+
public static explicit operator InteractionComponent(JObject jobj)
62+
{
63+
return new InteractionComponent(jobj);
64+
}
65+
66+
}
67+
68+
}

TinCan/InteractionType.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace TinCan
7+
{
8+
public sealed class InteractionType
9+
{
10+
private const string choice = "choice";
11+
private const string sequencing = "sequencing";
12+
private const string likert = "likert";
13+
private const string matching = "matching";
14+
private const string performance = "performance";
15+
private const string truefalse = "true-false";
16+
private const string fillin = "fill-in";
17+
private const string numeric = "numeric";
18+
private const string other = "other";
19+
20+
21+
public static readonly InteractionType Choice = new InteractionType("choice");
22+
public static readonly InteractionType Sequencing = new InteractionType("sequencing");
23+
public static readonly InteractionType Likert = new InteractionType("likert");
24+
public static readonly InteractionType Matching = new InteractionType("matching");
25+
public static readonly InteractionType Performance = new InteractionType("performance");
26+
public static readonly InteractionType TrueFalse = new InteractionType("true-false");
27+
public static readonly InteractionType FillIn = new InteractionType("fill-in");
28+
public static readonly InteractionType Numeric = new InteractionType("numeric");
29+
public static readonly InteractionType Other = new InteractionType("other");
30+
31+
32+
private InteractionType(string value)
33+
{
34+
Value = value;
35+
}
36+
37+
public static InteractionType FromValue(string value)
38+
{
39+
switch (value)
40+
{
41+
case choice:
42+
return Choice;
43+
44+
case sequencing:
45+
return Sequencing;
46+
47+
case likert:
48+
return Likert;
49+
50+
case matching:
51+
return Matching;
52+
53+
case performance:
54+
return Performance;
55+
56+
case truefalse:
57+
return TrueFalse;
58+
59+
case fillin:
60+
return FillIn;
61+
62+
case numeric:
63+
return Numeric;
64+
65+
case other:
66+
return Other;
67+
68+
default:
69+
return null;
70+
71+
}
72+
}
73+
74+
public string Value { get; private set; }
75+
}
76+
}

TinCan/TinCan.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
<Compile Include="ActivityDefinition.cs" />
6161
<Compile Include="Context.cs" />
6262
<Compile Include="ContextActivities.cs" />
63+
<Compile Include="InteractionComponent.cs" />
64+
<Compile Include="InteractionType.cs" />
6365
<Compile Include="StatementsQueryResultFormat.cs" />
6466
<Compile Include="StatementsQuery.cs" />
6567
<Compile Include="SubStatement.cs" />

TinCanTests/Support.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ static Support () {
4848
activity.definition.description = new LanguageMap();
4949
activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");
5050

51+
activity.definition.interactionType = InteractionType.Choice;
52+
activity.definition.choices = new List<InteractionComponent>();
53+
54+
for (int i = 1; i <= 3; i++)
55+
{
56+
InteractionComponent interactionComponent = new InteractionComponent();
57+
58+
interactionComponent.id = "choice-" + i.ToString();
59+
interactionComponent.description = new LanguageMap();
60+
interactionComponent.description.Add("en-US", "Choice " + i.ToString());
61+
62+
activity.definition.choices.Add(interactionComponent);
63+
}
64+
65+
activity.definition.correctResponsesPattern = new List<string>();
66+
67+
for (int i = 1; i <= 2; i++)
68+
{
69+
activity.definition.correctResponsesPattern.Add("choice-" + i.ToString());
70+
}
71+
5172
parent = new Activity();
5273
parent.id = new Uri("http://tincanapi.com/TinCanCSharp/Test");
5374
parent.definition = new ActivityDefinition();
@@ -65,7 +86,7 @@ static Support () {
6586
context.statement = statementRef;
6687
context.contextActivities = new ContextActivities();
6788
context.contextActivities.parent = new List<Activity>();
68-
context.contextActivities.parent.Add(parent);
89+
context.contextActivities.parent.Add(parent);
6990

7091
score = new Score();
7192
score.raw = 97;
@@ -78,6 +99,7 @@ static Support () {
7899
result.success = true;
79100
result.completion = true;
80101
result.duration = new TimeSpan(1, 2, 16, 43);
102+
result.response = "choice-2";
81103

82104
subStatement = new SubStatement();
83105
subStatement.actor = agent;

0 commit comments

Comments
 (0)