Skip to content

Commit f33f14c

Browse files
authored
Merge pull request #1711 from AllenNeuralDynamics/feat-settings-csv-parse
Feat settings csv parse
2 parents bfd049d + 3e1552f commit f33f14c

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

bonsai/Bonsai.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<Package id="Bonsai.VR" version="0.6.0" />
5151
<Package id="Bonsai.Windows.Input" version="2.7.0" />
5252
<Package id="BonVision" version="0.11.0" />
53+
<Package id="CsvHelper" version="33.1.0" />
5354
<Package id="Harp.AnalogInput" version="0.2.0" />
5455
<Package id="Harp.Behavior" version="0.1.0" />
5556
<Package id="Harp.LoadCells" version="0.2.0" />
@@ -65,6 +66,9 @@
6566
<Package id="jacobslusser.ScintillaNET" version="3.6.3" />
6667
<Package id="Markdig" version="0.18.1" />
6768
<Package id="MathNet.Numerics" version="4.15.0" />
69+
<Package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" />
70+
<Package id="Microsoft.Bcl.HashCode" version="1.1.1" />
71+
<Package id="Microsoft.CSharp" version="4.7.0" />
6872
<Package id="Microsoft.Web.WebView2" version="1.0.1823.32" />
6973
<Package id="Newtonsoft.Json" version="13.0.3" />
7074
<Package id="openal.redist" version="2.0.7" />
@@ -82,6 +86,7 @@
8286
<Package id="System.Memory" version="4.6.0" />
8387
<Package id="System.Numerics.Vectors" version="4.6.0" />
8488
<Package id="System.Runtime.CompilerServices.Unsafe" version="6.1.0" />
89+
<Package id="System.Threading.Tasks.Extensions" version="4.5.4" />
8590
<Package id="YamlDotNet" version="16.3.0" />
8691
<Package id="ZedGraph" version="5.1.7" />
8792
</Packages>
@@ -187,6 +192,7 @@
187192
<AssemblyLocation assemblyName="Bonsai.VR" processorArchitecture="MSIL" location="Packages\Bonsai.VR.0.6.0\lib\net45\Bonsai.VR.dll" />
188193
<AssemblyLocation assemblyName="Bonsai.Windows.Input" processorArchitecture="MSIL" location="Packages\Bonsai.Windows.Input.2.7.0\lib\net462\Bonsai.Windows.Input.dll" />
189194
<AssemblyLocation assemblyName="BonVision" processorArchitecture="MSIL" location="Packages\BonVision.0.11.0\lib\net462\BonVision.dll" />
195+
<AssemblyLocation assemblyName="CsvHelper" processorArchitecture="MSIL" location="Packages\CsvHelper.33.1.0\lib\net48\CsvHelper.dll" />
190196
<AssemblyLocation assemblyName="Harp.AnalogInput" processorArchitecture="MSIL" location="Packages\Harp.AnalogInput.0.2.0\lib\net462\Harp.AnalogInput.dll" />
191197
<AssemblyLocation assemblyName="Harp.Behavior" processorArchitecture="MSIL" location="Packages\Harp.Behavior.0.1.0\lib\net462\Harp.Behavior.dll" />
192198
<AssemblyLocation assemblyName="Harp.LoadCells" processorArchitecture="MSIL" location="Packages\Harp.LoadCells.0.2.0\lib\net462\Harp.LoadCells.dll" />
@@ -203,6 +209,8 @@
203209
<AssemblyLocation assemblyName="IronPython.Wpf" processorArchitecture="MSIL" location="Packages\IronPython.2.7.5\lib\Net45\IronPython.Wpf.dll" />
204210
<AssemblyLocation assemblyName="Markdig" processorArchitecture="MSIL" location="Packages\Markdig.0.18.1\lib\net40\Markdig.dll" />
205211
<AssemblyLocation assemblyName="MathNet.Numerics" processorArchitecture="MSIL" location="Packages\MathNet.Numerics.4.15.0\lib\net461\MathNet.Numerics.dll" />
212+
<AssemblyLocation assemblyName="Microsoft.Bcl.AsyncInterfaces" processorArchitecture="MSIL" location="Packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll" />
213+
<AssemblyLocation assemblyName="Microsoft.Bcl.HashCode" processorArchitecture="MSIL" location="Packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll" />
206214
<AssemblyLocation assemblyName="Microsoft.Dynamic" processorArchitecture="MSIL" location="Packages\IronPython.2.7.5\lib\Net45\Microsoft.Dynamic.dll" />
207215
<AssemblyLocation assemblyName="Microsoft.Scripting" processorArchitecture="MSIL" location="Packages\IronPython.2.7.5\lib\Net45\Microsoft.Scripting.dll" />
208216
<AssemblyLocation assemblyName="Microsoft.Scripting.AspNet" processorArchitecture="MSIL" location="Packages\IronPython.2.7.5\lib\Net45\Microsoft.Scripting.AspNet.dll" />
@@ -231,6 +239,7 @@
231239
<AssemblyLocation assemblyName="System.Reactive.Linq" processorArchitecture="MSIL" location="Packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll" />
232240
<AssemblyLocation assemblyName="System.Reactive.PlatformServices" processorArchitecture="MSIL" location="Packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll" />
233241
<AssemblyLocation assemblyName="System.Runtime.CompilerServices.Unsafe" processorArchitecture="MSIL" location="Packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll" />
242+
<AssemblyLocation assemblyName="System.Threading.Tasks.Extensions" processorArchitecture="MSIL" location="Packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll" />
234243
<AssemblyLocation assemblyName="YamlDotNet" processorArchitecture="MSIL" location="Packages\YamlDotNet.16.3.0\lib\net47\YamlDotNet.dll" />
235244
<AssemblyLocation assemblyName="ZedGraph" processorArchitecture="MSIL" location="Packages\ZedGraph.5.1.7\lib\net35-Client\ZedGraph.dll" />
236245
</AssemblyLocations>

src/foraging_gui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.6.62"
1+
__version__ = "1.6.65"
22

src/workflows/Extensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageReference Include="Bonsai.Osc" Version="2.7.0" />
1111
<PackageReference Include="Bonsai.DAQmx" Version="0.2.1-alpha1" />
1212
<PackageReference Include="Bonsai.Vision.Design" Version="2.7.0" />
13+
<PackageReference Include="CsvHelper" Version="27.2.1" />
1314
</ItemGroup>
1415

1516
</Project>

src/workflows/Extensions/ParseSettingCsv.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Reactive.Linq;
7+
using System.IO;
8+
using CsvHelper;
9+
using System.Globalization;
710

811
[Combinator]
9-
[Description("Parses lines, splitting at the first comma.")]
12+
[Description("Parses CSV synchronously.")]
1013
[WorkflowElementCategory(ElementCategory.Transform)]
1114
public class ParseSettingCsv
1215
{
1316
public IObservable<Dictionary<string, string>> Process(IObservable<string> source)
1417
{
1518
return source.Select(value =>
1619
{
17-
// split into lines
18-
var lines = value.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
19-
2020
var settings = new Dictionary<string, string>();
21-
foreach (var line in lines)
21+
22+
using (var reader = new StringReader(value))
23+
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
2224
{
23-
int commaIndex = line.IndexOf(',');
24-
if (commaIndex >= 0) // skip if no comma in line
25+
while (csv.Read())
2526
{
26-
string key = line.Substring(0, commaIndex);
27-
string val = line.Substring(commaIndex + 1);
27+
var key = csv.GetField(0);
28+
var val = csv.GetField(1);
2829
settings[key] = val;
2930
}
3031
}
3132

3233
return settings;
34+
3335
});
3436
}
3537
}

0 commit comments

Comments
 (0)