Skip to content

Commit

Permalink
Add extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Dec 3, 2024
1 parent 943b595 commit a401ce5
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

namespace Experimentgonogo
{
public partial class Trial
{
public virtual TimeSpan ToInterTrialInterval()
{
throw new NotImplementedException();
}
}

public partial class NoGoTrial
{
public override TimeSpan ToInterTrialInterval()
{
return TimeSpan.FromSeconds(this.InterTrialInterval);
}
}

public partial class GoTrial
{
public override TimeSpan ToInterTrialInterval()
{
if (this.Cue == "Foo")
{
return TimeSpan.FromSeconds(this.InterTrialInterval + 1);
}
else
{
return TimeSpan.FromSeconds(this.InterTrialInterval);
}
}
}

}
176 changes: 176 additions & 0 deletions _topics/_08_reproducible_research_practices/src/bonsai/demo2.bonsai
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System"
xmlns:p1="clr-namespace:Experimentgonogo;assembly=Extensions"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="io:ReadAllText">
<io:Path>..\json\experimentgonogo-example.json</io:Path>
</Combinator>
</Expression>
<Expression xsi:type="p1:DeserializeFromJson">
<p1:Type xsi:type="TypeMapping" TypeArguments="p1:ExperimentGoNoGo" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Take">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="rx:AsyncSubject">
<Name>ThisSession</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>ThisSession</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Trials</Selector>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Merge" />
</Expression>
<Expression xsi:type="p1:MatchTrial">
<p1:Type xsi:type="TypeMapping" TypeArguments="p1:NoGoTrial" />
</Expression>
<Expression xsi:type="rx:CreateObservable">
<Name>NoGoTrial</Name>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Take">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="rx:AsyncSubject">
<Name>ThisTrial</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>ThisTrial</Name>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>it.ToInterTrialInterval()</scr:Expression>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="DueTime" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Timer">
<rx:DueTime>PT0.5S</rx:DueTime>
<rx:Period>PT0S</rx:Period>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="StringProperty">
<Value>NoGo!!!</Value>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="p1:MatchTrial">
<p1:Type xsi:type="TypeMapping" TypeArguments="p1:GoTrial" />
</Expression>
<Expression xsi:type="rx:CreateObservable">
<Name>GoTrial</Name>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Take">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="rx:AsyncSubject">
<Name>ThisTrial</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>ThisTrial</Name>
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>it.ToInterTrialInterval()</scr:Expression>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="DueTime" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Timer">
<rx:DueTime>PT1S</rx:DueTime>
<rx:Period>PT0S</rx:Period>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="StringProperty">
<Value>Go!!!</Value>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
</Edges>
</Workflow>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Merge" />
</Expression>
<Expression xsi:type="rx:ReplaySubject">
<Name>TrialInfo</Name>
<rx:BufferSize xsi:nil="true" />
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>TrialInfo</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Merge" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="io:WriteLine" />
</Expression>
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="6" To="9" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
<Edge From="8" To="11" Label="Source1" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="10" To="11" Label="Source2" />
<Edge From="11" To="12" Label="Source1" />
<Edge From="13" To="14" Label="Source1" />
<Edge From="14" To="15" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>

0 comments on commit a401ce5

Please sign in to comment.