Skip to content

Commit

Permalink
Add FUSION as resource
Browse files Browse the repository at this point in the history
* Include Fusion tests
* Include Deepnet tests
  • Loading branch information
joseribes committed Jul 18, 2018
1 parent 480ffe9 commit ccea981
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 3 deletions.
7 changes: 7 additions & 0 deletions BigML/BigML.csproj
Expand Up @@ -165,6 +165,13 @@
<Compile Include="DataSet\Filterable.cs" />
<Compile Include="DataSet\Orderable.cs" />
<Compile Include="DataSet\Status.cs" />
<Compile Include="Fusion\Arguments.cs" />
<Compile Include="Fusion\BigMLClientFusion.cs" />
<Compile Include="Fusion\Fusion.cs" />
<Compile Include="Fusion\FusionListing.cs" />
<Compile Include="Fusion\Filterable.cs" />
<Compile Include="Fusion\Orderable.cs" />
<Compile Include="Fusion\Status.cs" />
<Compile Include="Ensemble\Arguments.cs" />
<Compile Include="Ensemble\BigMLClientEnsemble.cs" />
<Compile Include="Ensemble\Ensemble.cs" />
Expand Down
4 changes: 2 additions & 2 deletions BigML/Deepnet/Deepnet.cs
Expand Up @@ -47,8 +47,8 @@ public bool DataSetStatus


/// <summary>
/// A description of the status of the correlation. It includes a code, a message,
/// and some extra information.
/// A description of the status of the deepnet.
/// It includes a code, a message, and some extra information.
/// </summary>
public Status StatusMessage
{
Expand Down
38 changes: 38 additions & 0 deletions BigML/Fusion/Arguments.cs
@@ -0,0 +1,38 @@
using Newtonsoft.Json.Linq;
using System.Linq;
using System.Collections.Generic;

namespace BigML
{
public partial class Fusion
{
public class Arguments : Arguments<Fusion>
{
public Arguments()
{

}

/// <summary>
/// A list of model IDs used to create the fusion or a list of
/// objects including model propperties like the weight
/// </summary>
public List<dynamic> Models
{
get;
set;
}


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

if (Models.Count > 0) {
json.models = new JArray(Models.Select(t => (JValue)t));
}
return json;
}
}
}
}
40 changes: 40 additions & 0 deletions BigML/Fusion/BigMLClientFusion.cs
@@ -0,0 +1,40 @@
using System.Threading.Tasks;
using System.Collections.Generic;

namespace BigML
{
public partial class Client
{
/// <summary>
/// Create a fusion using supplied arguments.
/// </summary>
public Task<Fusion> CreateFusion(Fusion.Arguments arguments)
{
return Create<Fusion>(arguments);
}

/// <summary>
/// Create a Fusion.
/// </summary>
/// <param name="models">A list of Models</param>
/// <param name="name">The name you want to give to the new fusion.</param>
/// <param name="arguments">Other extra parameters.</param>
public Task<Fusion> CreateFusion(List<dynamic> models, string name = null,
Fusion.Arguments arguments = null)
{
arguments = arguments ?? new Fusion.Arguments();
if (!string.IsNullOrWhiteSpace(name))
arguments.Name = name;
arguments.Models = models;
return Create<Fusion>(arguments);
}

/// <summary>
/// List all the Fusion
/// </summary>
public Query<Fusion.Filterable, Fusion.Orderable, Fusion> ListFusion()
{
return new FusionListing(List<Fusion>);
}
}
}
37 changes: 37 additions & 0 deletions BigML/Fusion/Filterable.cs
@@ -0,0 +1,37 @@
using BigML.Meta;

namespace BigML
{
public partial class Fusion
{
/// <summary>
/// Filterable properties for fusions
/// </summary>
public class Filterable : Filterable<Fusion>
{
/// <summary>
/// The current number of batch predictions that use this fusion
/// </summary>
public Int NumberOfBatchpredictions
{
get { return Object.number_of_batchpredictions; }
}

/// <summary>
/// The current number of evaluations that use this fusion
/// </summary>
public Int NumberOfEvaluations
{
get { return Object.number_of_evaluations; }
}

/// <summary>
/// The current number of predictions that use this fusion
/// </summary>
public Int NumberOfPredictions
{
get { return Object.number_of_predictions; }
}
}
}
}
44 changes: 44 additions & 0 deletions BigML/Fusion/Fusion.cs
@@ -0,0 +1,44 @@
using System.Collections.Generic;

namespace BigML
{
/// <summary>
/// Fusions are a special type of composite for which all submodels satisfy
/// the following constraints: they're all either classifications or
/// regressions over the same kind of data or compatible fields, with the
/// same objective field.
/// The complete and updated reference with all available parameters is in
/// our <a href="https://bigml.com/api/fusions"> documentation</a> website.
/// </summary>
public partial class Fusion : Response
{

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


/// <summary>
/// The models that was used to build the fusion.
/// </summary>
public List<dynamic> Models
{
get { return Object.models; }
}


/// <summary>
/// A description of the status of the fusion.
/// It includes a code, a message, and some extra information.
/// </summary>
public Status StatusMessage
{
get { return new Status(Object.status); }
}
}
}
13 changes: 13 additions & 0 deletions BigML/Fusion/FusionListing.cs
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;

namespace BigML
{
public class FusionListing : Query<Fusion.Filterable, Fusion.Orderable, Fusion>
{
public FusionListing(Func<string, Task<Listing<Fusion>>> client)
: base(client)
{
}
}
}
39 changes: 39 additions & 0 deletions BigML/Fusion/Orderable.cs
@@ -0,0 +1,39 @@
using BigML.Meta;

namespace BigML
{
using Meta.Key;

public partial class Fusion
{
/// <summary>
/// Orderable properties for fusions
/// </summary>
public class Orderable : Orderable<Fusion>
{
/// <summary>
/// The current number of batch predictions that use this fusion
/// </summary>
public Int NumberOfBatchpredictions
{
get { return Object.number_of_batchpredictions; }
}

/// <summary>
/// The current number of evaluations that use this fusion
/// </summary>
public Int NumberOfEvaluations
{
get { return Object.number_of_evaluations; }
}

/// <summary>
/// The current number of predictions that use this fusion
/// </summary>
public Int NumberOfPredictions
{
get { return Object.number_of_predictions; }
}
}
}
}
32 changes: 32 additions & 0 deletions BigML/Fusion/Status.cs
@@ -0,0 +1,32 @@
using Newtonsoft.Json.Linq;

namespace BigML
{
public partial class Fusion
{
/// <summary>
/// Creating a Fusion is a process that can take just a few
/// seconds. This time depends on the quantity of models used
/// and on the work load of BigML's systems.
/// The Fusion goes through a number of states until its fully
/// completed.
/// Through the status field in the Fusion you can determine
/// when the Fusion has been fully completed.
/// </summary>
public class Status : Status<Fusion>
{
internal Status(JObject status): base(status)
{
}

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

}
}
}
5 changes: 4 additions & 1 deletion BigML/Response/Arguments.cs
Expand Up @@ -86,9 +86,12 @@ public virtual JObject ToJson()
{
inObjectVal = (JValue) entry.Value;
}
else {
else if (!valType.IsClass) {
inObjectVal = entry.Value;
}
else {
continue;
}
json[entry.Key] = inObjectVal;
}

Expand Down
2 changes: 2 additions & 0 deletions BigMLTest/BigMLTest.csproj
Expand Up @@ -55,6 +55,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="TestConfigurations.cs" />
<Compile Include="TestDeepnets.cs" />
<Compile Include="TestFusions.cs" />
<Compile Include="TestOptiML.cs" />
<Compile Include="TestTopics.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
60 changes: 60 additions & 0 deletions BigMLTest/TestDeepnets.cs
@@ -0,0 +1,60 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using BigML;

namespace BigMLTest
{
/// <summary>
/// Test resources related with Deepnets
/// </summary>
[TestClass]
public class TestDeepnets
{
string userName = "myUser";
string apiKey = "8169dabca34b6ae5612a47b63dd97bead3bfeXXX";

[TestMethod]
public async Task CreateDeepnetFromRemoteSource()
{
// Prepare connection
Client c = new Client(userName, apiKey);

// Create source
Source.Arguments args = new Source.Arguments();
args.Add("remote", "http://static.bigml.com/csv/iris.csv");
Source s = await c.CreateSource(args);
s = await c.Wait<Source>(s.Resource);

Assert.AreEqual(s.StatusMessage.StatusCode, Code.Finished);

// Create dataset
DataSet.Arguments argsDS = new DataSet.Arguments();
argsDS.Add("source", s.Resource);
DataSet ds = await c.CreateDataset(argsDS);
ds = await c.Wait<DataSet>(ds.Resource);

Assert.AreEqual(ds.StatusMessage.StatusCode, Code.Finished);

// Create deepnet
Deepnet.Arguments argsDn = new Deepnet.Arguments();
argsDn.Add("dataset", ds.Resource);
Deepnet dn = await c.CreateDeepnet(argsDn);
dn = await c.Wait<Deepnet>(dn.Resource);

Assert.AreEqual(dn.StatusMessage.StatusCode, Code.Finished);

// test UPDATE method
Newtonsoft.Json.Linq.JObject changes = new Newtonsoft.Json.Linq.JObject();
Newtonsoft.Json.Linq.JArray tags = new Newtonsoft.Json.Linq.JArray();
tags.Add("Bindings C# test");
changes.Add("tags", tags);
dn = await c.Update<Deepnet>(dn.Resource, changes);
Assert.AreEqual(dn.Code, System.Net.HttpStatusCode.Accepted);

// test DELETE method
await c.Delete(s);
await c.Delete(ds);
await c.Delete(dn);
}
}
}

0 comments on commit ccea981

Please sign in to comment.