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

Consolidating open PRs #40

Merged
merged 6 commits into from
Sep 13, 2018
Merged
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
124 changes: 117 additions & 7 deletions TinCan/ActivityDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
Copy link
Member

Choose a reason for hiding this comment

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

It will probably become a need pretty quickly to allow for individual additions of a single InteractionComponent to each of these lists. The public interface of the class requires you to set the whole list. That's been an issue elsewhere in the library in the past. Not something that has to hold up this PR, but it is something to be aware of for the future.


public ActivityDefinition() {}

Expand Down Expand Up @@ -60,6 +64,54 @@ 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) {
Expand All @@ -85,6 +137,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;
}
Expand Down
68 changes: 68 additions & 0 deletions TinCan/InteractionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2018 Rustici Software

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);
}

}

}
76 changes: 76 additions & 0 deletions TinCan/InteractionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;

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 LONGFILLIN = "long-fill-in";
private const string NUMERIC = "numeric";
private const string OTHER = "other";

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(TRUEFALSE);
public static readonly InteractionType FillIn = new InteractionType(FILLIN);
public static readonly InteractionType LongFillIn = new InteractionType(LONGFILLIN);
public static readonly InteractionType Numeric = new InteractionType(NUMERIC);
public static readonly InteractionType Other = new InteractionType(OTHER);

private InteractionType(string value)
{
Value = value;
}

public static InteractionType FromValue(string value)
{
switch (value)
{
case CHOICE:
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 LONGFILLIN:
return LongFillIn;

case NUMERIC:
return Numeric;

case OTHER:
return Other;

default:
throw new ArgumentOutOfRangeException(nameof(value),
$"'{value}' is not a valid interactionType.");
}
}

public string Value { get; private set; }
}
}
5 changes: 4 additions & 1 deletion TinCan/TCAPIVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace TinCan
{
public sealed class TCAPIVersion
{
public static readonly TCAPIVersion V103 = new TCAPIVersion("1.0.3");
public static readonly TCAPIVersion V102 = new TCAPIVersion("1.0.2");
public static readonly TCAPIVersion V101 = new TCAPIVersion("1.0.1");
public static readonly TCAPIVersion V100 = new TCAPIVersion("1.0.0");
Expand All @@ -28,7 +29,7 @@ public sealed class TCAPIVersion

public static TCAPIVersion latest()
{
return V101;
return V103;
}

private static Dictionary<String, TCAPIVersion> known;
Expand All @@ -41,6 +42,7 @@ public static Dictionary<String, TCAPIVersion> GetKnown()
}

known = new Dictionary<String, TCAPIVersion>();
known.Add("1.0.3", V103);
known.Add("1.0.2", V102);
known.Add("1.0.1", V101);
known.Add("1.0.0", V100);
Expand All @@ -57,6 +59,7 @@ public static Dictionary<String, TCAPIVersion> GetSupported()
}

supported = new Dictionary<String, TCAPIVersion>();
supported.Add("1.0.3", V103);
supported.Add("1.0.2", V102);
supported.Add("1.0.1", V101);
supported.Add("1.0.0", V100);
Expand Down
2 changes: 2 additions & 0 deletions TinCan/TinCan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
<Compile Include="ActivityDefinition.cs" />
<Compile Include="Context.cs" />
<Compile Include="ContextActivities.cs" />
<Compile Include="InteractionComponent.cs" />
<Compile Include="InteractionType.cs" />
<Compile Include="StatementsQueryResultFormat.cs" />
<Compile Include="StatementsQuery.cs" />
<Compile Include="SubStatement.cs" />
Expand Down
Loading