Skip to content

Commit

Permalink
Add first example
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Dec 3, 2024
1 parent 1310074 commit 00d8fcf
Show file tree
Hide file tree
Showing 4 changed files with 472 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,353 @@
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------


namespace Experiment
{
#pragma warning disable // Disable all warnings

[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[Bonsai.CombinatorAttribute()]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)]
public partial class Trial
{

private double _interTrialInterval = 1D;

private int _rewardAmount = 1;

public Trial()
{
}

protected Trial(Trial other)
{
_interTrialInterval = other._interTrialInterval;
_rewardAmount = other._rewardAmount;
}

/// <summary>
/// Interval between trials in seconds
/// </summary>
[Newtonsoft.Json.JsonPropertyAttribute("inter_trial_interval")]
[YamlDotNet.Serialization.YamlMemberAttribute(Alias="inter_trial_interval")]
[System.ComponentModel.DescriptionAttribute("Interval between trials in seconds")]
public double InterTrialInterval
{
get
{
return _interTrialInterval;
}
set
{
_interTrialInterval = value;
}
}

/// <summary>
/// Amount of reward given to the animal
/// </summary>
[Newtonsoft.Json.JsonPropertyAttribute("reward_amount")]
[YamlDotNet.Serialization.YamlMemberAttribute(Alias="reward_amount")]
[System.ComponentModel.DescriptionAttribute("Amount of reward given to the animal")]
public int RewardAmount
{
get
{
return _rewardAmount;
}
set
{
_rewardAmount = value;
}
}

public System.IObservable<Trial> Process()
{
return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new Trial(this)));
}

public System.IObservable<Trial> Process<TSource>(System.IObservable<TSource> source)
{
return System.Reactive.Linq.Observable.Select(source, _ => new Trial(this));
}

protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
{
stringBuilder.Append("inter_trial_interval = " + _interTrialInterval + ", ");
stringBuilder.Append("reward_amount = " + _rewardAmount);
return true;
}

public override string ToString()
{
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
stringBuilder.Append(GetType().Name);
stringBuilder.Append(" { ");
if (PrintMembers(stringBuilder))
{
stringBuilder.Append(" ");
}
stringBuilder.Append("}");
return stringBuilder.ToString();
}
}


[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[Bonsai.CombinatorAttribute()]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)]
public partial class Experiment
{

private string _animalId;

private System.Collections.Generic.List<Trial> _trials = new System.Collections.Generic.List<Trial>();

private int? _rngSeed;

public Experiment()
{
}

protected Experiment(Experiment other)
{
_animalId = other._animalId;
_trials = other._trials;
_rngSeed = other._rngSeed;
}

/// <summary>
/// ID of the animal
/// </summary>
[Newtonsoft.Json.JsonPropertyAttribute("animal_id", Required=Newtonsoft.Json.Required.Always)]
[YamlDotNet.Serialization.YamlMemberAttribute(Alias="animal_id")]
[System.ComponentModel.DescriptionAttribute("ID of the animal")]
public string AnimalId
{
get
{
return _animalId;
}
set
{
_animalId = value;
}
}

/// <summary>
/// List of trials in the experiment
/// </summary>
[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("trials", Required=Newtonsoft.Json.Required.Always)]
[YamlDotNet.Serialization.YamlMemberAttribute(Alias="trials")]
[System.ComponentModel.DescriptionAttribute("List of trials in the experiment")]
public System.Collections.Generic.List<Trial> Trials
{
get
{
return _trials;
}
set
{
_trials = value;
}
}

/// <summary>
/// Seed for the random number generator
/// </summary>
[System.Xml.Serialization.XmlIgnoreAttribute()]
[Newtonsoft.Json.JsonPropertyAttribute("rng_seed")]
[YamlDotNet.Serialization.YamlMemberAttribute(Alias="rng_seed")]
[System.ComponentModel.DescriptionAttribute("Seed for the random number generator")]
public int? RngSeed
{
get
{
return _rngSeed;
}
set
{
_rngSeed = value;
}
}

public System.IObservable<Experiment> Process()
{
return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return(new Experiment(this)));
}

public System.IObservable<Experiment> Process<TSource>(System.IObservable<TSource> source)
{
return System.Reactive.Linq.Observable.Select(source, _ => new Experiment(this));
}

protected virtual bool PrintMembers(System.Text.StringBuilder stringBuilder)
{
stringBuilder.Append("animal_id = " + _animalId + ", ");
stringBuilder.Append("trials = " + _trials + ", ");
stringBuilder.Append("rng_seed = " + _rngSeed);
return true;
}

public override string ToString()
{
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
stringBuilder.Append(GetType().Name);
stringBuilder.Append(" { ");
if (PrintMembers(stringBuilder))
{
stringBuilder.Append(" ");
}
stringBuilder.Append("}");
return stringBuilder.ToString();
}
}


/// <summary>
/// Serializes a sequence of data model objects into JSON strings.
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[System.ComponentModel.DescriptionAttribute("Serializes a sequence of data model objects into JSON strings.")]
[Bonsai.CombinatorAttribute()]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)]
public partial class SerializeToJson
{

private System.IObservable<string> Process<T>(System.IObservable<T> source)
{
return System.Reactive.Linq.Observable.Select(source, value => Newtonsoft.Json.JsonConvert.SerializeObject(value));
}

public System.IObservable<string> Process(System.IObservable<Trial> source)
{
return Process<Trial>(source);
}

public System.IObservable<string> Process(System.IObservable<Experiment> source)
{
return Process<Experiment>(source);
}
}


/// <summary>
/// Deserializes a sequence of JSON strings into data model objects.
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[System.ComponentModel.DescriptionAttribute("Deserializes a sequence of JSON strings into data model objects.")]
[System.ComponentModel.DefaultPropertyAttribute("Type")]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<Trial>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<Experiment>))]
public partial class DeserializeFromJson : Bonsai.Expressions.SingleArgumentExpressionBuilder
{

public DeserializeFromJson()
{
Type = new Bonsai.Expressions.TypeMapping<Experiment>();
}

public Bonsai.Expressions.TypeMapping Type { get; set; }

public override System.Linq.Expressions.Expression Build(System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments)
{
var typeMapping = (Bonsai.Expressions.TypeMapping)Type;
var returnType = typeMapping.GetType().GetGenericArguments()[0];
return System.Linq.Expressions.Expression.Call(
typeof(DeserializeFromJson),
"Process",
new System.Type[] { returnType },
System.Linq.Enumerable.Single(arguments));
}

private static System.IObservable<T> Process<T>(System.IObservable<string> source)
{
return System.Reactive.Linq.Observable.Select(source, value => Newtonsoft.Json.JsonConvert.DeserializeObject<T>(value));
}
}


/// <summary>
/// Serializes a sequence of data model objects into YAML strings.
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[System.ComponentModel.DescriptionAttribute("Serializes a sequence of data model objects into YAML strings.")]
[Bonsai.CombinatorAttribute()]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)]
public partial class SerializeToYaml
{

private System.IObservable<string> Process<T>(System.IObservable<T> source)
{
return System.Reactive.Linq.Observable.Defer(() =>
{
var serializer = new YamlDotNet.Serialization.SerializerBuilder()
.Build();
return System.Reactive.Linq.Observable.Select(source, value => serializer.Serialize(value));
});
}

public System.IObservable<string> Process(System.IObservable<Trial> source)
{
return Process<Trial>(source);
}

public System.IObservable<string> Process(System.IObservable<Experiment> source)
{
return Process<Experiment>(source);
}
}


/// <summary>
/// Deserializes a sequence of YAML strings into data model objects.
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("Bonsai.Sgen", "0.4.0.0 (Newtonsoft.Json v13.0.0.0, YamlDotNet v13.0.0.0)")]
[System.ComponentModel.DescriptionAttribute("Deserializes a sequence of YAML strings into data model objects.")]
[System.ComponentModel.DefaultPropertyAttribute("Type")]
[Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<Trial>))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping<Experiment>))]
public partial class DeserializeFromYaml : Bonsai.Expressions.SingleArgumentExpressionBuilder
{

public DeserializeFromYaml()
{
Type = new Bonsai.Expressions.TypeMapping<Experiment>();
}

public Bonsai.Expressions.TypeMapping Type { get; set; }

public override System.Linq.Expressions.Expression Build(System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments)
{
var typeMapping = (Bonsai.Expressions.TypeMapping)Type;
var returnType = typeMapping.GetType().GetGenericArguments()[0];
return System.Linq.Expressions.Expression.Call(
typeof(DeserializeFromYaml),
"Process",
new System.Type[] { returnType },
System.Linq.Enumerable.Single(arguments));
}

private static System.IObservable<T> Process<T>(System.IObservable<string> source)
{
return System.Reactive.Linq.Observable.Defer(() =>
{
var serializer = new YamlDotNet.Serialization.DeserializerBuilder()
.Build();
return System.Reactive.Linq.Observable.Select(source, value =>
{
var reader = new System.IO.StringReader(value);
var parser = new YamlDotNet.Core.MergingParser(new YamlDotNet.Core.Parser(reader));
return serializer.Deserialize<T>(parser);
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"animal_id": "my_mouse",
"trials": [
{
"inter_trial_interval": 1.0,
"reward_amount": 1
},
{
"inter_trial_interval": 0.5,
"reward_amount": 0
}
],
"rng_seed": null
}
Loading

0 comments on commit 00d8fcf

Please sign in to comment.