Skip to content

Commit

Permalink
Add AssociationSet as resource
Browse files Browse the repository at this point in the history
  • Loading branch information
joseribes committed Feb 8, 2017
1 parent f2fd1d3 commit 27645b6
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 0 deletions.
54 changes: 54 additions & 0 deletions BigML/AssociationSet/Arguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Json;
using System.Linq;

namespace BigML
{
public partial class AssociationSet
{
public class Arguments : Arguments<AssociationSet>
{
public Arguments()
{
InputData = new Dictionary<string, object>();
}

/// <summary>
/// A valid anomaly/id.
/// </summary>
public string Association
{
get;
set;
}

/// <summary>
/// A group of values in a dictionary: "fieldId": value
/// </summary>
public IDictionary<string, object> InputData
{
get;
set;
}

public override JsonValue ToJson()
{
dynamic json = base.ToJson();

if(!string.IsNullOrWhiteSpace(Association)) json.anomaly = Association;
if (InputData.Count > 0)
{
var input_data = new JsonObject();
foreach (var kv in InputData)
{
JsonPrimitive value;
JsonPrimitive.TryCreate(kv.Value, out value);
input_data[kv.Key] = value;
}
json.input_data = input_data;
}
return json;
}
}
}
}
59 changes: 59 additions & 0 deletions BigML/AssociationSet/AssociationSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BigML
{
/// <summary>
/// An association set is created from an association and the input_data
/// for which you wish to create an association set.
/// Association Sets are useful to know which items have stronger
/// associations with a given set of values for your fields.
/// The complete and updated reference with all available parameters is in
/// our <a href="https://bigml.com/api/associationsets">documentation</a>
/// website.
/// </summary>
public partial class AssociationSet : Response
{

/// <summary>
/// The name of the association set as your provided or based on the name
/// of the association by default.
/// </summary>
public string Name
{
get { return Object.name; }
}


/// <summary>
/// The association/id that was used to build the score.
/// </summary>
public string Association
{
get { return Object.association; }
}



/// <summary>
/// Whether the association is still available or has been deleted.
/// </summary>
public bool AssociationStatus
{
get { return Object.association_status; }
}


/// <summary>
/// A description of the status of the association set. It includes a
/// code, a message, and some extra information.
/// </summary>
public Status<AssociationSet> StatusMessage
{
get { return new Status(Object.status); }
}
}
}
13 changes: 13 additions & 0 deletions BigML/AssociationSet/AssociationSetListing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;

namespace BigML
{
public class AssociationSetListing : Query<AssociationSet.Filterable, AssociationSet.Orderable, AssociationSet>
{
public AssociationSetListing(Func<string, Task<Listing<AssociationSet>>> client)
: base(client)
{
}
}
}
39 changes: 39 additions & 0 deletions BigML/AssociationSet/BigMLClientAssociationSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Threading.Tasks;

namespace BigML
{
public partial class Client
{
/// <summary>
/// Create an association set using supplied arguments.
/// </summary>
public Task<AssociationSet> CreateAssociationSet(AssociationSet.Arguments arguments)
{
return Create<AssociationSet>(arguments);
}

/// <summary>
/// Create an Association Set.
/// </summary>
/// <param name="association">An Association discovery instance</param>
/// <param name="name">The name you want to give to the new association set. </param>
/// <param name="arguments">Specifies the values of the fields that you want to use.</param>
public Task<AssociationSet> CreateAssociationSet(Association association, string name = null,
AssociationSet.Arguments arguments = null)
{
arguments = arguments ?? new AssociationSet.Arguments();
if (!string.IsNullOrWhiteSpace(name))
arguments.Name = name;
arguments.Association = association.Resource;
return Create<AssociationSet>(arguments);
}

/// <summary>
/// List all the associations sets
/// </summary>
public Query<AssociationSet.Filterable, AssociationSet.Orderable, AssociationSet> ListAssociationSets()
{
return new AssociationSetListing(List<AssociationSet>);
}
}
}
29 changes: 29 additions & 0 deletions BigML/AssociationSet/Filterable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using BigML.Meta;

namespace BigML
{
public partial class AssociationSet
{
/// <summary>
/// Filterable properties for Association sets
/// </summary>
public class Filterable : Filterable<AssociationSet>
{
/// <summary>
/// The dataset/id that was used to build the association.
/// </summary>
public String Dataset
{
get { return Object.dataset; }
}

/// <summary>
/// Whether the dataset is still available or has been deleted.
/// </summary>
public Bool DatasetStatus
{
get { return Object.dataset_status; }
}
}
}
}
31 changes: 31 additions & 0 deletions BigML/AssociationSet/Orderable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using BigML.Meta;

namespace BigML
{
using Meta.Key;

public partial class AssociationSet
{
/// <summary>
/// Orderable properties for Association Sets
/// </summary>
public class Orderable : Orderable<AssociationSet>
{
/// <summary>
/// The dataset/id that was used to build the association discovery.
/// </summary>
public String Dataset
{
get { return Object.dataset; }
}

/// <summary>
/// Whether the dataset is still available or has been deleted.
/// </summary>
public Bool DatasetStatus
{
get { return Object.dataset_status; }
}
}
}
}
28 changes: 28 additions & 0 deletions BigML/AssociationSet/Status.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Json;

namespace BigML
{
public partial class AssociationSet
{
/// <summary>
/// The association set goes through a number of states until its fully completed.
/// Through the status field in the resource you can determine when the set has
/// been fully processed and ready.
/// </summary>
public class Status : Status<AssociationSet>
{
internal Status(JsonValue status): base(status)
{
}

/// <summary>
/// How far BigML.io has progressed processing the anomaly score.
/// </summary>
public double Progress
{
get { return _status.progress; }
}

}
}
}
7 changes: 7 additions & 0 deletions BigML/BigML.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssociationSet\Arguments.cs" />
<Compile Include="AssociationSet\AssociationSet.cs" />
<Compile Include="AssociationSet\AssociationSetListing.cs" />
<Compile Include="AssociationSet\BigMLClientAssociationSet.cs" />
<Compile Include="AssociationSet\Filterable.cs" />
<Compile Include="AssociationSet\Orderable.cs" />
<Compile Include="AssociationSet\Status.cs" />
<Compile Include="BatchTopicDistribution\Arguments.cs" />
<Compile Include="BatchTopicDistribution\BatchTopicDistribution.cs" />
<Compile Include="BatchTopicDistribution\BatchTopicDistributionListing.cs" />
Expand Down

0 comments on commit 27645b6

Please sign in to comment.