-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from SainsburyWellcomeCentre/json-lines
Support formatting value sequences as JSON strings
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using Bonsai; | ||
using Newtonsoft.Json; | ||
|
||
namespace Aeon.Acquisition | ||
{ | ||
[Combinator] | ||
[Description("Formats a sequence of values into a sequence of JSON strings.")] | ||
[WorkflowElementCategory(ElementCategory.Transform)] | ||
public class FormatJson | ||
{ | ||
public IObservable<string> Process<TSource>(IObservable<TSource> source) | ||
{ | ||
return source.Select(value => JsonConvert.SerializeObject(value)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<WorkflowBuilder Version="2.8.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:aeon="clr-namespace:Aeon.Acquisition;assembly=Aeon.Acquisition" | ||
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core" | ||
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System" | ||
xmlns="https://bonsai-rx.org/2018/workflow"> | ||
<Description>Chunks and logs a generic timestamped data stream into the base data log using JSON lines.</Description> | ||
<Workflow> | ||
<Nodes> | ||
<Expression xsi:type="WorkflowInput"> | ||
<Name>Source1</Name> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="Name" DisplayName="Heartbeats" Description="The source of heartbeat signals used as a timing signal for closing groups." Category="GroupClosing" /> | ||
</Expression> | ||
<Expression xsi:type="SubscribeSubject"> | ||
<Name /> | ||
</Expression> | ||
<Expression xsi:type="SubscribeSubject"> | ||
<Name>ChunkSize</Name> | ||
</Expression> | ||
<Expression xsi:type="PropertyMapping"> | ||
<PropertyMappings> | ||
<Property Name="ChunkSize" /> | ||
</PropertyMappings> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="ClosingDuration" Category="GroupClosing" /> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="aeon:GroupByTime"> | ||
<aeon:ChunkSize>1</aeon:ChunkSize> | ||
</Combinator> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="Name" DisplayName="LogName" Description="The base name of the data log, without extension." /> | ||
</Expression> | ||
<Expression xsi:type="rx:CreateObservable"> | ||
<Name>LogJson</Name> | ||
<Workflow> | ||
<Nodes> | ||
<Expression xsi:type="WorkflowInput"> | ||
<Name>Source1</Name> | ||
</Expression> | ||
<Expression xsi:type="rx:AsyncSubject"> | ||
<Name>Data</Name> | ||
</Expression> | ||
<Expression xsi:type="SubscribeSubject"> | ||
<Name>Data</Name> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="rx:Merge" /> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="aeon:FormatJson" /> | ||
</Expression> | ||
<Expression xsi:type="SubscribeSubject"> | ||
<Name>Data</Name> | ||
</Expression> | ||
<Expression xsi:type="MemberSelector"> | ||
<Selector>Key</Selector> | ||
</Expression> | ||
<Expression xsi:type="ExternalizedMapping"> | ||
<Property Name="Name" /> | ||
</Expression> | ||
<Expression xsi:type="IncludeWorkflow" Path="Aeon.Acquisition:FormatFileName.bonsai"> | ||
<Name>JsonData</Name> | ||
<Extension>jsonl</Extension> | ||
</Expression> | ||
<Expression xsi:type="PropertyMapping"> | ||
<PropertyMappings> | ||
<Property Name="FileName" /> | ||
</PropertyMappings> | ||
</Expression> | ||
<Expression xsi:type="io:CsvWriter"> | ||
<io:Append>false</io:Append> | ||
<io:Overwrite>false</io:Overwrite> | ||
<io:Suffix>None</io:Suffix> | ||
<io:IncludeHeader>false</io:IncludeHeader> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="1" Label="Source1" /> | ||
<Edge From="2" To="3" Label="Source1" /> | ||
<Edge From="3" To="4" Label="Source1" /> | ||
<Edge From="4" To="10" Label="Source1" /> | ||
<Edge From="5" To="6" Label="Source1" /> | ||
<Edge From="6" To="8" Label="Source1" /> | ||
<Edge From="7" To="8" Label="Source2" /> | ||
<Edge From="8" To="9" Label="Source1" /> | ||
<Edge From="9" To="10" Label="Source2" /> | ||
<Edge From="10" To="11" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</Expression> | ||
<Expression xsi:type="Combinator"> | ||
<Combinator xsi:type="rx:Switch" /> | ||
</Expression> | ||
<Expression xsi:type="WorkflowOutput" /> | ||
</Nodes> | ||
<Edges> | ||
<Edge From="0" To="6" Label="Source1" /> | ||
<Edge From="1" To="2" Label="Source1" /> | ||
<Edge From="2" To="6" Label="Source2" /> | ||
<Edge From="3" To="4" Label="Source1" /> | ||
<Edge From="4" To="6" Label="Source3" /> | ||
<Edge From="5" To="6" Label="Source4" /> | ||
<Edge From="6" To="8" Label="Source1" /> | ||
<Edge From="7" To="8" Label="Source2" /> | ||
<Edge From="8" To="9" Label="Source1" /> | ||
<Edge From="9" To="10" Label="Source1" /> | ||
</Edges> | ||
</Workflow> | ||
</WorkflowBuilder> |