-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActivityDefinition InteractionType #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,13 @@ You may obtain a copy of the License at | |
limitations under the License. | ||
*/ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using TinCan.Json; | ||
|
||
|
||
namespace TinCan | ||
{ | ||
public class ActivityDefinition : JsonModel | ||
|
@@ -26,13 +30,13 @@ public class ActivityDefinition : JsonModel | |
public LanguageMap name { get; set; } | ||
public LanguageMap description { get; set; } | ||
public Extensions extensions { get; set; } | ||
//public InteractionType interactionType { get; set; } | ||
//public List<String> correctResponsesPattern { get; set; } | ||
//public List<InteractionComponent> choices { get; set; } | ||
//public List<InteractionComponent> scale { get; set; } | ||
//public List<InteractionComponent> source { get; set; } | ||
//public List<InteractionComponent> target { get; set; } | ||
//public List<InteractionComponent> steps { get; set; } | ||
public InteractionType interactionType { get; set; } | ||
public List<String> correctResponsesPattern { get; set; } | ||
public List<InteractionComponent> choices { get; set; } | ||
public List<InteractionComponent> scale { get; set; } | ||
public List<InteractionComponent> source { get; set; } | ||
public List<InteractionComponent> target { get; set; } | ||
public List<InteractionComponent> steps { get; set; } | ||
|
||
public ActivityDefinition() {} | ||
|
||
|
@@ -60,11 +64,62 @@ public ActivityDefinition(JObject jobj) | |
{ | ||
extensions = (Extensions)jobj.Value<JObject>("extensions"); | ||
} | ||
if (jobj["interactionType"] != null) | ||
{ | ||
interactionType = InteractionType.FromValue(jobj.Value<String>("interactionType")); | ||
} | ||
if (jobj["correctResponsesPattern"] != null) | ||
{ | ||
correctResponsesPattern = ((JArray)jobj["correctResponsesPattern"]).Select(x => x.Value<String>()).ToList<String>(); | ||
} | ||
if (jobj["choices"] != null) | ||
{ | ||
choices = new List<InteractionComponent>(); | ||
foreach (JObject jchoice in jobj["choices"]) | ||
{ | ||
choices.Add(new InteractionComponent(jchoice)); | ||
} | ||
} | ||
if (jobj["scale"] != null) | ||
{ | ||
scale = new List<InteractionComponent>(); | ||
foreach (JObject jscale in jobj["scale"]) | ||
{ | ||
scale.Add(new InteractionComponent(jscale)); | ||
} | ||
} | ||
if (jobj["source"] != null) | ||
{ | ||
source = new List<InteractionComponent>(); | ||
foreach (JObject jsource in jobj["source"]) | ||
{ | ||
source.Add(new InteractionComponent(jsource)); | ||
} | ||
} | ||
if (jobj["target"] != null) | ||
{ | ||
target = new List<InteractionComponent>(); | ||
foreach (JObject jtarget in jobj["target"]) | ||
{ | ||
target.Add(new InteractionComponent(jtarget)); | ||
} | ||
} | ||
if (jobj["steps"] != null) | ||
{ | ||
steps = new List<InteractionComponent>(); | ||
foreach (JObject jstep in jobj["steps"]) | ||
{ | ||
steps.Add(new InteractionComponent(jstep)); | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
public override JObject ToJObject(TCAPIVersion version) { | ||
JObject result = new JObject(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please watch these kinds of changes and revert. |
||
if (type != null) | ||
{ | ||
result.Add("type", type.ToString()); | ||
|
@@ -85,6 +140,64 @@ public override JObject ToJObject(TCAPIVersion version) { | |
{ | ||
result.Add("extensions", extensions.ToJObject(version)); | ||
} | ||
if (interactionType != null) | ||
{ | ||
result.Add("interactionType", interactionType.Value); | ||
} | ||
if (correctResponsesPattern != null && correctResponsesPattern.Count > 0) | ||
{ | ||
result.Add("correctResponsesPattern", JToken.FromObject(correctResponsesPattern)); | ||
} | ||
if (choices != null && choices.Count > 0) | ||
{ | ||
var jchoices = new JArray(); | ||
result.Add("choices", jchoices); | ||
|
||
foreach (InteractionComponent ichoice in choices) | ||
{ | ||
jchoices.Add(ichoice.ToJObject(version)); | ||
} | ||
} | ||
if (scale != null && scale.Count > 0) | ||
{ | ||
var jscale = new JArray(); | ||
result.Add("scale", jscale); | ||
|
||
foreach (InteractionComponent iscale in scale) | ||
{ | ||
jscale.Add(iscale.ToJObject(version)); | ||
} | ||
} | ||
if (source != null && source.Count > 0) | ||
{ | ||
var jsource = new JArray(); | ||
result.Add("source", jsource); | ||
|
||
foreach (InteractionComponent isource in source) | ||
{ | ||
jsource.Add(isource.ToJObject(version)); | ||
} | ||
} | ||
if (target != null && target.Count > 0) | ||
{ | ||
var jtarget = new JArray(); | ||
result.Add("target", jtarget); | ||
|
||
foreach (InteractionComponent itarget in target) | ||
{ | ||
jtarget.Add(itarget.ToJObject(version)); | ||
} | ||
} | ||
if (steps != null && steps.Count > 0) | ||
{ | ||
var jsteps = new JArray(); | ||
result.Add("steps", jsteps); | ||
|
||
foreach (InteractionComponent istep in steps) | ||
{ | ||
jsteps.Add(istep.ToJObject(version)); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2014 Rustici Software | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyrights on new files should be the current year when they were created. |
||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
using TinCan.Json; | ||
|
||
namespace TinCan | ||
{ | ||
public class InteractionComponent : JsonModel | ||
{ | ||
public String id; | ||
public LanguageMap description { get; set; } | ||
|
||
public InteractionComponent() | ||
{ | ||
|
||
} | ||
|
||
public InteractionComponent(JObject jobj) | ||
{ | ||
if (jobj["id"] != null) | ||
{ | ||
id = jobj.Value<String>("id"); | ||
} | ||
if (jobj["description"] != null) | ||
{ | ||
description = (LanguageMap)jobj.Value<JObject>("description"); | ||
} | ||
|
||
} | ||
|
||
public override JObject ToJObject(TCAPIVersion version) { | ||
JObject result = new JObject(); | ||
|
||
if (id != null) | ||
{ | ||
result.Add("id", id); | ||
} | ||
if (description != null && !description.isEmpty()) | ||
{ | ||
result.Add("description", description.ToJObject(version)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static explicit operator InteractionComponent(JObject jobj) | ||
{ | ||
return new InteractionComponent(jobj); | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace TinCan | ||
{ | ||
public sealed class InteractionType | ||
{ | ||
private const string choice = "choice"; | ||
private const string sequencing = "sequencing"; | ||
private const string likert = "likert"; | ||
private const string matching = "matching"; | ||
private const string performance = "performance"; | ||
private const string truefalse = "true-false"; | ||
private const string fillin = "fill-in"; | ||
private const string numeric = "numeric"; | ||
private const string other = "other"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For constants would like to use an all uppercase convention. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "long-fill-in" is missing. It is required according to xAPI Data |
||
|
||
|
||
public static readonly InteractionType Choice = new InteractionType("choice"); | ||
public static readonly InteractionType Sequencing = new InteractionType("sequencing"); | ||
public static readonly InteractionType Likert = new InteractionType("likert"); | ||
public static readonly InteractionType Matching = new InteractionType("matching"); | ||
public static readonly InteractionType Performance = new InteractionType("performance"); | ||
public static readonly InteractionType TrueFalse = new InteractionType("true-false"); | ||
public static readonly InteractionType FillIn = new InteractionType("fill-in"); | ||
public static readonly InteractionType Numeric = new InteractionType("numeric"); | ||
public static readonly InteractionType Other = new InteractionType("other"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should probably use the constants if that is something that is possible? |
||
|
||
|
||
private InteractionType(string value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static InteractionType FromValue(string value) | ||
{ | ||
switch (value) | ||
{ | ||
case choice: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can cases use a constant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can, because a const's value is known at compile time. |
||
return Choice; | ||
|
||
case sequencing: | ||
return Sequencing; | ||
|
||
case likert: | ||
return Likert; | ||
|
||
case matching: | ||
return Matching; | ||
|
||
case performance: | ||
return Performance; | ||
|
||
case truefalse: | ||
return TrueFalse; | ||
|
||
case fillin: | ||
return FillIn; | ||
|
||
case numeric: | ||
return Numeric; | ||
|
||
case other: | ||
return Other; | ||
|
||
default: | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the default be null or to throw an exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An exception as the domain is defined by the xAPI specification. I suggest throwing an ArgumentOutOfRangeException. |
||
|
||
} | ||
} | ||
|
||
public string Value { get; private set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,27 @@ static Support () { | |
activity.definition.description = new LanguageMap(); | ||
activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library."); | ||
|
||
activity.definition.interactionType = InteractionType.Choice; | ||
activity.definition.choices = new List<InteractionComponent>(); | ||
|
||
for (int i = 1; i <= 3; i++) | ||
{ | ||
InteractionComponent interactionComponent = new InteractionComponent(); | ||
|
||
interactionComponent.id = "choice-" + i.ToString(); | ||
interactionComponent.description = new LanguageMap(); | ||
interactionComponent.description.Add("en-US", "Choice " + i.ToString()); | ||
|
||
activity.definition.choices.Add(interactionComponent); | ||
} | ||
|
||
activity.definition.correctResponsesPattern = new List<string>(); | ||
|
||
for (int i = 1; i <= 2; i++) | ||
{ | ||
activity.definition.correctResponsesPattern.Add("choice-" + i.ToString()); | ||
} | ||
|
||
parent = new Activity(); | ||
parent.id = new Uri("http://tincanapi.com/TinCanCSharp/Test"); | ||
parent.definition = new ActivityDefinition(); | ||
|
@@ -65,7 +86,7 @@ static Support () { | |
context.statement = statementRef; | ||
context.contextActivities = new ContextActivities(); | ||
context.contextActivities.parent = new List<Activity>(); | ||
context.contextActivities.parent.Add(parent); | ||
context.contextActivities.parent.Add(parent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space on line ending. |
||
|
||
score = new Score(); | ||
score.raw = 97; | ||
|
@@ -78,6 +99,7 @@ static Support () { | |
result.success = true; | ||
result.completion = true; | ||
result.duration = new TimeSpan(1, 2, 16, 43); | ||
result.response = "choice-2"; | ||
|
||
subStatement = new SubStatement(); | ||
subStatement.actor = agent; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we revert these changes, at least the change from VS 2012 to VS2013. Though I don't really know what they are for. Any explanation or just the IDE doing automatic things? In general we should avoid making these kinds of changes if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neither VS2017 nor Rider require the lines VisualStudioVersion... and MinimumVisualStudioVersion...
In some projects it makes sense to keep such constraints in the sln files, such as those which depend on the UML-to-Code transformations which were included in previous VS versions but were removed in VS 2017.
I suggest the additions to be discarded while the deletion to be kept.