Skip to content
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

Adds support for interaction components #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 132 additions & 7 deletions TinCan/ActivityDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ You may obtain a copy of the License at
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
* Modified by Paul Carpenter 2015
*
* Includes support for Activity Interactions
*
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to keep this out of the source, git should be able to track these types of changes easily. If we need new attribution it can go somewhere outside of the source itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check with Oliver about this. It may be that this was just intended to be an internal note so they know what they changed from the library, which becomes unnecessary if/when this is merged anyway.


using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using TinCan.Json;

Expand All @@ -26,13 +35,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 String interactionType { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to make InteractionType its own class, possibly based on an enum or something like it. That would follow the convention from TinCanJava and make matching the types (since there is a set list) easier. See https://github.com/RusticiSoftware/TinCanJava/blob/master/src/main/java/com/rusticisoftware/tincan/InteractionType.java

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() {}

Expand Down Expand Up @@ -60,6 +69,58 @@ public ActivityDefinition(JObject jobj)
{
extensions = (Extensions)jobj.Value<JObject>("extensions");
}
if (jobj["interactionType"] != null)
{
interactionType = jobj.Value<String>("interactionType");
}
if (jobj["correctResponsesPattern"] != null)
{
correctResponsesPattern = new List<String>();
foreach (JValue jcorrectResponsesPattern in jobj["correctResponsesPattern"])
{
correctResponsesPattern.Add(jcorrectResponsesPattern.ToString());
}
}
if (jobj["choices"] != null)
{
choices = new List<InteractionComponent>();
foreach (JObject jchoices in jobj["choices"])
{
choices.Add((InteractionComponent)jchoices);
}
}
if (jobj["scale"] != null)
{
scale = new List<InteractionComponent>();
foreach (JObject jscale in jobj["scale"])
{
scale.Add((InteractionComponent)jscale);
}
}
if (jobj["source"] != null)
{
source = new List<InteractionComponent>();
foreach (JObject jsource in jobj["source"])
{
source.Add((InteractionComponent)jsource);
}
}
if (jobj["target"] != null)
{
target = new List<InteractionComponent>();
foreach (JObject jtarget in jobj["target"])
{
target.Add((InteractionComponent)jtarget);
}
}
if (jobj["steps"] != null)
{
steps = new List<InteractionComponent>();
foreach (JObject jsteps in jobj["steps"])
{
steps.Add((InteractionComponent)jsteps);
}
}
}

public override JObject ToJObject(TCAPIVersion version) {
Expand All @@ -85,6 +146,70 @@ public override JObject ToJObject(TCAPIVersion version) {
{
result.Add("extensions", extensions.ToJObject(version));
}
if (interactionType != null)
{
result.Add("interactionType", interactionType.ToString());
}
if (correctResponsesPattern != null && correctResponsesPattern.Count > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just hit this on the spec, but we need to leave it open to allow for an empty array in 'correctResponsesPattern', see adlnet/xAPI-Spec#698

{
var jcorrectResponsesPattern = new JArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to avoid the use of var. I know this is subjective, AFAIK we aren't using it anywhere else in the code base.

result.Add("correctResponsesPattern", jcorrectResponsesPattern);

foreach (String correctReponse in correctResponsesPattern)
{
jcorrectResponsesPattern.Add(correctReponse.ToString());
}
}
if (choices != null && choices.Count > 0)
{
var jchoices = new JArray();
result.Add("choices", jchoices);

foreach (InteractionComponent c in choices)
{
jchoices.Add(c.ToJObject(version));
}
}
if (scale != null && scale.Count > 0)
{
var jscale = new JArray();
result.Add("scale", jscale);

foreach (InteractionComponent s in scale)
{
jscale.Add(s.ToJObject(version));
}
}
if (source != null && source.Count > 0)
{
var jsource = new JArray();
result.Add("source", jsource);

foreach (InteractionComponent s in source)
{
jsource.Add(s.ToJObject(version));
}
}
if (target != null && target.Count > 0)
{
var jtarget = new JArray();
result.Add("target", jtarget);

foreach (InteractionComponent t in target)
{
jtarget.Add(t.ToJObject(version));
}
}
if (steps != null && steps.Count > 0)
{
var jsteps = new JArray();
result.Add("steps", jsteps);

foreach (InteractionComponent s in steps)
{
jsteps.Add(s.ToJObject(version));
}
}

return result;
}
Expand Down
59 changes: 59 additions & 0 deletions TinCan/InteractionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Created by Paul Carpenter 2015
*
* Includes support for Activity Interaction Components
*
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment about attributions. This file still needs the Apache license header to match the others.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using TinCan.Json;

namespace TinCan
{
public class InteractionComponent : JsonModel
{
public String id { get; set; }
public LanguageMap description { get; set; }

public InteractionComponent() { }

public InteractionComponent(StringOfJSON json): this(json.toJObject()) {}

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);
}
}
}
6 changes: 4 additions & 2 deletions TinCan/TinCan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net35\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these automatically done by VS or intentional? What effect (if any) do they have?

</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -60,6 +61,7 @@
<Compile Include="ActivityDefinition.cs" />
<Compile Include="Context.cs" />
<Compile Include="ContextActivities.cs" />
<Compile Include="InteractionComponent.cs" />
<Compile Include="StatementsQueryResultFormat.cs" />
<Compile Include="StatementsQuery.cs" />
<Compile Include="SubStatement.cs" />
Expand Down
2 changes: 1 addition & 1 deletion TinCan/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net35" />
</packages>