diff --git a/BigML/BigML.csproj b/BigML/BigML.csproj index 8c57c7b..b95b2f2 100644 --- a/BigML/BigML.csproj +++ b/BigML/BigML.csproj @@ -165,6 +165,13 @@ + + + + + + + diff --git a/BigML/Deepnet/Deepnet.cs b/BigML/Deepnet/Deepnet.cs index 6b7f98b..26aaab1 100644 --- a/BigML/Deepnet/Deepnet.cs +++ b/BigML/Deepnet/Deepnet.cs @@ -47,8 +47,8 @@ public bool DataSetStatus /// - /// 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. /// public Status StatusMessage { diff --git a/BigML/Fusion/Arguments.cs b/BigML/Fusion/Arguments.cs new file mode 100644 index 0000000..2fe4b41 --- /dev/null +++ b/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 + { + public Arguments() + { + + } + + /// + /// A list of model IDs used to create the fusion or a list of + /// objects including model propperties like the weight + /// + public List 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; + } + } + } +} \ No newline at end of file diff --git a/BigML/Fusion/BigMLClientFusion.cs b/BigML/Fusion/BigMLClientFusion.cs new file mode 100644 index 0000000..58f631e --- /dev/null +++ b/BigML/Fusion/BigMLClientFusion.cs @@ -0,0 +1,40 @@ +using System.Threading.Tasks; +using System.Collections.Generic; + +namespace BigML +{ + public partial class Client + { + /// + /// Create a fusion using supplied arguments. + /// + public Task CreateFusion(Fusion.Arguments arguments) + { + return Create(arguments); + } + + /// + /// Create a Fusion. + /// + /// A list of Models + /// The name you want to give to the new fusion. + /// Other extra parameters. + public Task CreateFusion(List 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(arguments); + } + + /// + /// List all the Fusion + /// + public Query ListFusion() + { + return new FusionListing(List); + } + } +} \ No newline at end of file diff --git a/BigML/Fusion/Filterable.cs b/BigML/Fusion/Filterable.cs new file mode 100644 index 0000000..a941d02 --- /dev/null +++ b/BigML/Fusion/Filterable.cs @@ -0,0 +1,37 @@ +using BigML.Meta; + +namespace BigML +{ + public partial class Fusion + { + /// + /// Filterable properties for fusions + /// + public class Filterable : Filterable + { + /// + /// The current number of batch predictions that use this fusion + /// + public Int NumberOfBatchpredictions + { + get { return Object.number_of_batchpredictions; } + } + + /// + /// The current number of evaluations that use this fusion + /// + public Int NumberOfEvaluations + { + get { return Object.number_of_evaluations; } + } + + /// + /// The current number of predictions that use this fusion + /// + public Int NumberOfPredictions + { + get { return Object.number_of_predictions; } + } + } + } +} diff --git a/BigML/Fusion/Fusion.cs b/BigML/Fusion/Fusion.cs new file mode 100644 index 0000000..04aab78 --- /dev/null +++ b/BigML/Fusion/Fusion.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; + +namespace BigML +{ + /// + /// 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 documentation website. + /// + public partial class Fusion : Response + { + + /// + /// The name of the Fusion as your provided or based on the name + /// of the dataset by default. + /// + public string Name + { + get { return Object.name; } + } + + + /// + /// The models that was used to build the fusion. + /// + public List Models + { + get { return Object.models; } + } + + + /// + /// A description of the status of the fusion. + /// It includes a code, a message, and some extra information. + /// + public Status StatusMessage + { + get { return new Status(Object.status); } + } + } +} diff --git a/BigML/Fusion/FusionListing.cs b/BigML/Fusion/FusionListing.cs new file mode 100644 index 0000000..a2cf4d0 --- /dev/null +++ b/BigML/Fusion/FusionListing.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; + +namespace BigML +{ + public class FusionListing : Query + { + public FusionListing(Func>> client) + : base(client) + { + } + } +} diff --git a/BigML/Fusion/Orderable.cs b/BigML/Fusion/Orderable.cs new file mode 100644 index 0000000..2f14ef6 --- /dev/null +++ b/BigML/Fusion/Orderable.cs @@ -0,0 +1,39 @@ +using BigML.Meta; + +namespace BigML +{ + using Meta.Key; + + public partial class Fusion + { + /// + /// Orderable properties for fusions + /// + public class Orderable : Orderable + { + /// + /// The current number of batch predictions that use this fusion + /// + public Int NumberOfBatchpredictions + { + get { return Object.number_of_batchpredictions; } + } + + /// + /// The current number of evaluations that use this fusion + /// + public Int NumberOfEvaluations + { + get { return Object.number_of_evaluations; } + } + + /// + /// The current number of predictions that use this fusion + /// + public Int NumberOfPredictions + { + get { return Object.number_of_predictions; } + } + } + } +} \ No newline at end of file diff --git a/BigML/Fusion/Status.cs b/BigML/Fusion/Status.cs new file mode 100644 index 0000000..63afff4 --- /dev/null +++ b/BigML/Fusion/Status.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json.Linq; + +namespace BigML +{ + public partial class Fusion + { + /// + /// 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. + /// + public class Status : Status + { + internal Status(JObject status): base(status) + { + } + + /// + /// How far BigML.io has progressed processing the fusion. + /// + public double Progress + { + get { return _status.progress; } + } + + } + } +} \ No newline at end of file diff --git a/BigML/Response/Arguments.cs b/BigML/Response/Arguments.cs index 52b0684..1f87c48 100644 --- a/BigML/Response/Arguments.cs +++ b/BigML/Response/Arguments.cs @@ -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; } diff --git a/BigMLTest/BigMLTest.csproj b/BigMLTest/BigMLTest.csproj index eb2bf42..54491c7 100644 --- a/BigMLTest/BigMLTest.csproj +++ b/BigMLTest/BigMLTest.csproj @@ -55,6 +55,8 @@ + + diff --git a/BigMLTest/TestDeepnets.cs b/BigMLTest/TestDeepnets.cs new file mode 100644 index 0000000..119fb0d --- /dev/null +++ b/BigMLTest/TestDeepnets.cs @@ -0,0 +1,60 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; +using BigML; + +namespace BigMLTest +{ + /// + /// Test resources related with Deepnets + /// + [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(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(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(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(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); + } + } +} diff --git a/BigMLTest/TestFusions.cs b/BigMLTest/TestFusions.cs new file mode 100644 index 0000000..aafb96d --- /dev/null +++ b/BigMLTest/TestFusions.cs @@ -0,0 +1,76 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; +using System.Collections.Generic; +using BigML; + +namespace BigMLTest +{ + /// + /// Test resources related with Fusions + /// + [TestClass] + public class TestFusions + { + string userName = "myUser"; + string apiKey = "8169dabca34b6ae5612a47b63dd97bead3bfeXXX"; + + [TestMethod] + public async Task CreateFusionFromRemoteSource() + { + // 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(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(ds.Resource); + + Assert.AreEqual(ds.StatusMessage.StatusCode, Code.Finished); + + // Create Logistic Regression + LogisticRegression.Arguments argsLR = new LogisticRegression.Arguments(); + argsLR.Add("dataset", ds.Resource); + LogisticRegression lr = await c.CreateLogisticRegression(argsLR); + lr = await c.Wait(lr.Resource); + + // Create Tree model + Model.Arguments argsMd = new Model.Arguments(); + argsMd.Add("dataset", ds.Resource); + Model md = await c.CreateModel(argsMd); + md = await c.Wait(md.Resource); + + // Create Fusion + Fusion.Arguments argsFs = new Fusion.Arguments(); + List modelIDs = new List(); + modelIDs.Add(lr.Resource); + modelIDs.Add(md.Resource); + argsFs.Models = modelIDs; + Fusion fs = await c.CreateFusion(argsFs); + fs = await c.Wait(fs.Resource); + + Assert.AreEqual(fs.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); + fs = await c.Update(fs.Resource, changes); + Assert.AreEqual(fs.Code, System.Net.HttpStatusCode.Accepted); + + // test DELETE method + await c.Delete(s); + await c.Delete(ds); + await c.Delete(fs); + } + } +}