Skip to content

Commit 070d5c8

Browse files
committed
Refactored unit to units
1 parent 511a89b commit 070d5c8

27 files changed

+188
-188
lines changed

src/symphony-core/HekaDAQController.Tests/HekaDAQControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void RoundTripStreamITChannelInfo()
233233

234234
//NO_SCALE is seconds scale (Hz)
235235
Assert.AreEqual(ITCMM.USE_FREQUENCY & ITCMM.NO_SCALE & ITCMM.ADJUST_RATE, info.SamplingIntervalFlag);
236-
Assert.That(info.SamplingRate, Is.EqualTo(stream.SampleRate.QuantityInBaseUnit));
236+
Assert.That(info.SamplingRate, Is.EqualTo(stream.SampleRate.QuantityInBaseUnits));
237237
Assert.AreEqual(IntPtr.Zero, info.FIFOPointer);
238238
Assert.AreEqual(0, info.Gain);
239239
}

src/symphony-core/HekaDAQController.Tests/HekaDAQStreamTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void PreloadShouldFeedBuffer()
6464

6565
s.Preload(itcMock.Object as IHekaDevice, new OutputData(dataQueue[s].Peek()));
6666

67-
int expectedSamples = (int)Math.Ceiling(bufferDuration.TotalSeconds * (double)s.SampleRate.QuantityInBaseUnit);
67+
int expectedSamples = (int)Math.Ceiling(bufferDuration.TotalSeconds * (double)s.SampleRate.QuantityInBaseUnits);
6868
itcMock.VerifyAll();
6969
Assert.AreEqual(availableSamplesStart - expectedSamples, availableSamples); //Preload should not affect buffer availablility because PRELOAD_FIFO is used
7070
}
@@ -104,7 +104,7 @@ StreamType streamType
104104

105105
Assert.AreEqual(channelNumber, info.ChannelNumber);
106106
Assert.AreEqual((int)streamType, info.ChannelType);
107-
Assert.AreEqual(s.SampleRate.QuantityInBaseUnit, info.SamplingRate);
107+
Assert.AreEqual(s.SampleRate.QuantityInBaseUnits, info.SamplingRate);
108108
Assert.AreEqual(ITCMM.USE_FREQUENCY, info.SamplingIntervalFlag);
109109
Assert.AreEqual(0, info.Gain);
110110
Assert.AreEqual(IntPtr.Zero, info.FIFOPointer);
@@ -195,7 +195,7 @@ StreamType streamType
195195

196196
Assert.AreEqual(channelNumber, info.ChannelNumber);
197197
Assert.AreEqual((int)streamType, info.ChannelType);
198-
Assert.AreEqual(s.SampleRate.QuantityInBaseUnit, info.SamplingRate);
198+
Assert.AreEqual(s.SampleRate.QuantityInBaseUnits, info.SamplingRate);
199199
Assert.AreEqual(ITCMM.USE_FREQUENCY, info.SamplingIntervalFlag);
200200
Assert.AreEqual(0, info.Gain);
201201
Assert.AreEqual(IntPtr.Zero, info.FIFOPointer);

src/symphony-core/HekaDAQController/HekaDAQController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public IMeasurement SampleRate
125125
set
126126
{
127127
// Set the ProcessInterval longer for high sampling rates
128-
var rateProcessInterval = value.QuantityInBaseUnit > 10000m
128+
var rateProcessInterval = value.QuantityInBaseUnits > 10000m
129129
? TimeSpan.FromSeconds(2*DEFAULT_TRANSFER_BLOCK_SECONDS)
130130
: TimeSpan.FromSeconds(DEFAULT_TRANSFER_BLOCK_SECONDS);
131131

@@ -368,7 +368,7 @@ private void PreloadStreams()
368368
var nextOutputDataForStream = NextOutputDataForStream(s);
369369
var nextSamples = nextOutputDataForStream.DataWithUnits(HekaDAQOutputStream.DAQCountUnits).Data.
370370
Select(
371-
(m) => (short)m.QuantityInBaseUnit);
371+
(m) => (short)m.QuantityInBaseUnits);
372372

373373
outputSamples = outputSamples.Concat(nextSamples).ToList();
374374

@@ -434,11 +434,11 @@ protected override IDictionary<IDAQInputStream, IInputData> ProcessLoopIteration
434434

435435
var cons = outputData.DataWithUnits(HekaDAQOutputStream.DAQCountUnits).SplitData(deficit);
436436

437-
short[] deficitOutputSamples = cons.Head.Data.Select((m) => (short)m.QuantityInBaseUnit).ToArray();
437+
short[] deficitOutputSamples = cons.Head.Data.Select((m) => (short)m.QuantityInBaseUnits).ToArray();
438438
deficitOutput[new ChannelIdentifier { ChannelNumber = s.ChannelNumber, ChannelType = (ushort)s.ChannelType }] =
439439
deficitOutputSamples;
440440

441-
short[] outputSamples = cons.Rest.Data.Select((m) => (short)m.QuantityInBaseUnit).ToArray();
441+
short[] outputSamples = cons.Rest.Data.Select((m) => (short)m.QuantityInBaseUnits).ToArray();
442442
output[new ChannelIdentifier { ChannelNumber = s.ChannelNumber, ChannelType = (ushort)s.ChannelType }] =
443443
outputSamples;
444444
}
@@ -522,10 +522,10 @@ public override Maybe<string> Validate()
522522
if (SampleRate == null)
523523
return Maybe<string>.No("Sample rate required.");
524524

525-
if (SampleRate.BaseUnit.ToLower() != "hz")
525+
if (SampleRate.BaseUnits.ToLower() != "hz")
526526
return Maybe<string>.No("Sample rate must be in Hz.");
527527

528-
if (SampleRate.QuantityInBaseUnit <= 0)
528+
if (SampleRate.QuantityInBaseUnits <= 0)
529529
return Maybe<string>.No("Sample rate must be greater than 0");
530530

531531
if (!ActiveStreams.Any())
@@ -543,7 +543,7 @@ public override Maybe<string> Validate()
543543

544544
if (Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()) >= 1)
545545
{
546-
var samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnit * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));
546+
var samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnits * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));
547547

548548
while (samplingInterval % Device.DeviceInfo.MinimumSamplingStep != 0m)
549549
{
@@ -555,7 +555,7 @@ public override Maybe<string> Validate()
555555
var dev = new NullDevice();
556556
dev.BindStream(inactive.First());
557557

558-
samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnit * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));
558+
samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnits * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));
559559
}
560560
}
561561
}

src/symphony-core/HekaDAQController/HekaDAQInputStream.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ITCMM.ITCChannelInfo ChannelInfo
6161
result.ChannelNumber = ChannelNumber;
6262
result.ChannelType = (uint)ChannelType;
6363
result.SamplingIntervalFlag = ITCMM.USE_FREQUENCY;// &ITCMM.NO_SCALE & ITCMM.ADJUST_RATE;
64-
result.SamplingRate = (double) this.SampleRate.QuantityInBaseUnit;
64+
result.SamplingRate = (double) this.SampleRate.QuantityInBaseUnits;
6565
result.Gain = 0;
6666
result.FIFOPointer = System.IntPtr.Zero;
6767

@@ -73,7 +73,7 @@ public static void RegisterConverters()
7373
{
7474
Converters.Register(DAQCountUnits,
7575
"V",
76-
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnit / (decimal)ITCMM.ANALOGVOLT, 0, "V")
76+
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnits / (decimal)ITCMM.ANALOGVOLT, 0, "V")
7777
);
7878

7979
Converters.Register(DAQCountUnits,
@@ -82,9 +82,9 @@ public static void RegisterConverters()
8282

8383
Converters.Register(DAQCountUnits,
8484
Measurement.NORMALIZED,
85-
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnit < 0 ?
86-
m.QuantityInBaseUnit / (decimal)ITCMM.NEGATIVEVOLT / -(decimal)ITCMM.ANALOGVOLT :
87-
m.QuantityInBaseUnit / (decimal)ITCMM.POSITIVEVOLT / +(decimal)ITCMM.ANALOGVOLT,
85+
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnits < 0 ?
86+
m.QuantityInBaseUnits / (decimal)ITCMM.NEGATIVEVOLT / -(decimal)ITCMM.ANALOGVOLT :
87+
m.QuantityInBaseUnits / (decimal)ITCMM.POSITIVEVOLT / +(decimal)ITCMM.ANALOGVOLT,
8888
0, DAQCountUnits));
8989
}
9090
}
@@ -129,7 +129,7 @@ public override void PushInputData(IInputData inData)
129129
data = new InputData(data,
130130
data.Data.Select(
131131
m =>
132-
MeasurementPool.GetMeasurement(((short) m.QuantityInBaseUnit >> bitPosition) & 1, 0, Measurement.UNITLESS)));
132+
MeasurementPool.GetMeasurement(((short) m.QuantityInBaseUnits >> bitPosition) & 1, 0, Measurement.UNITLESS)));
133133
ed.PushInputData(this, data.DataWithStreamConfiguration(this, this.Configuration));
134134
}
135135
}

src/symphony-core/HekaDAQController/HekaDAQOutputStream.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void RegisterConverters()
6363
{
6464
Converters.Register("V",
6565
DAQCountUnits,
66-
(m) => MeasurementPool.GetMeasurement((decimal)Math.Round((double)m.QuantityInBaseUnit * ITCMM.ANALOGVOLT), 0, DAQCountUnits)
66+
(m) => MeasurementPool.GetMeasurement((decimal)Math.Round((double)m.QuantityInBaseUnits * ITCMM.ANALOGVOLT), 0, DAQCountUnits)
6767
);
6868

6969
Converters.Register(Measurement.UNITLESS,
@@ -72,9 +72,9 @@ public static void RegisterConverters()
7272

7373
Converters.Register(Measurement.NORMALIZED,
7474
DAQCountUnits,
75-
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnit < 0 ?
76-
Math.Round(m.QuantityInBaseUnit * (decimal)ITCMM.NEGATIVEVOLT * -(decimal)ITCMM.ANALOGVOLT) :
77-
Math.Round(m.QuantityInBaseUnit * (decimal)ITCMM.POSITIVEVOLT * +(decimal)ITCMM.ANALOGVOLT),
75+
(m) => MeasurementPool.GetMeasurement(m.QuantityInBaseUnits < 0 ?
76+
Math.Round(m.QuantityInBaseUnits * (decimal)ITCMM.NEGATIVEVOLT * -(decimal)ITCMM.ANALOGVOLT) :
77+
Math.Round(m.QuantityInBaseUnits * (decimal)ITCMM.POSITIVEVOLT * +(decimal)ITCMM.ANALOGVOLT),
7878
0, DAQCountUnits));
7979
}
8080
public ITCMM.ITCChannelInfo ChannelInfo
@@ -86,7 +86,7 @@ public ITCMM.ITCChannelInfo ChannelInfo
8686
ChannelNumber = ChannelNumber,
8787
ChannelType = (uint)ChannelType,
8888
SamplingIntervalFlag = ITCMM.USE_FREQUENCY,
89-
SamplingRate = (double)SampleRate.QuantityInBaseUnit,
89+
SamplingRate = (double)SampleRate.QuantityInBaseUnits,
9090
Gain = 0, //Gain = 1x
9191
FIFOPointer = IntPtr.Zero,
9292
};
@@ -149,15 +149,15 @@ public override IMeasurement Background
149149
foreach (var ed in Devices)
150150
{
151151
var m = Converters.Convert(ed.Background, MeasurementConversionTarget);
152-
if (m.QuantityInBaseUnit != 0 && m.QuantityInBaseUnit != 1)
152+
if (m.QuantityInBaseUnits != 0 && m.QuantityInBaseUnits != 1)
153153
throw new DAQException(ed.Name + " background must contain a value of 0 or 1");
154154

155155
ushort bitPosition = BitPositions[ed];
156-
m = MeasurementPool.GetMeasurement((short)((short)m.QuantityInBaseUnit << bitPosition), 0, m.BaseUnit);
156+
m = MeasurementPool.GetMeasurement((short)((short)m.QuantityInBaseUnits << bitPosition), 0, m.BaseUnits);
157157

158158
background = background == null
159159
? m
160-
: MeasurementPool.GetMeasurement((short)background.QuantityInBaseUnit | (short)m.QuantityInBaseUnit, 0, background.BaseUnit);
160+
: MeasurementPool.GetMeasurement((short)background.QuantityInBaseUnits | (short)m.QuantityInBaseUnits, 0, background.BaseUnits);
161161
}
162162
return background;
163163
}
@@ -176,17 +176,17 @@ public override IOutputData PullOutputData(TimeSpan duration)
176176
ushort bitPosition = BitPositions[ed];
177177
pulled = new OutputData(pulled, pulled.Data.Select(m =>
178178
{
179-
if (m.QuantityInBaseUnit != 0 && m.QuantityInBaseUnit != 1)
179+
if (m.QuantityInBaseUnits != 0 && m.QuantityInBaseUnits != 1)
180180
throw new DAQException(ed.Name + " output data must contain only values of 0 and 1");
181181

182-
return MeasurementPool.GetMeasurement((short)((short)m.QuantityInBaseUnit << bitPosition), 0, m.BaseUnit);
182+
return MeasurementPool.GetMeasurement((short)((short)m.QuantityInBaseUnits << bitPosition), 0, m.BaseUnits);
183183
}));
184184

185185
outData = outData == null
186186
? pulled
187187
: outData.Zip(pulled,
188188
(m1, m2) =>
189-
MeasurementPool.GetMeasurement((short) m1.QuantityInBaseUnit | (short) m2.QuantityInBaseUnit, 0, m1.BaseUnit));
189+
MeasurementPool.GetMeasurement((short) m1.QuantityInBaseUnits | (short) m2.QuantityInBaseUnits, 0, m1.BaseUnits));
190190
}
191191

192192
if (!outData.SampleRate.Equals(this.SampleRate))

src/symphony-core/HekaDAQController/QueuedHekaHardwareDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void WriteAsyncIO(HekaDAQOutputStream stream, IMeasurement streamValue)
100100
Value =
101101
(short)
102102
Converters.Convert(streamValue, HekaDAQOutputStream.DAQCountUnits)
103-
.QuantityInBaseUnit
103+
.QuantityInBaseUnits
104104
}
105105
};
106106

src/symphony-core/IntegrationTests/HekaIntegration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void RenderedStimulus(
228228

229229
var failures0 =
230230
e.Responses[dev0].Data.Select(
231-
(t, i) => new { index = i, diff = t.QuantityInBaseUnit - stimData[i].QuantityInBaseUnit })
231+
(t, i) => new { index = i, diff = t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits })
232232
.Where(dif => Math.Abs(dif.diff) > (decimal)MAX_VOLTAGE_DIFF);
233233

234234
foreach (var failure in failures0.Take(10))
@@ -389,7 +389,7 @@ public void ContinuousAcquisition(
389389

390390
var failures0 =
391391
e.Responses[dev0].Data.Select(
392-
(t, i) => new {index = i, diff = t.QuantityInBaseUnit - stimData[i].QuantityInBaseUnit})
392+
(t, i) => new {index = i, diff = t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits})
393393
.Where(dif => Math.Abs(dif.diff) > (decimal) MAX_VOLTAGE_DIFF);
394394

395395
foreach (var failure in failures0.Take(10))
@@ -484,8 +484,8 @@ public void ShouldSetStreamBackgroundOnStop(
484484
daq.GetStreams("ANALOG_IN.0").First() as IDAQInputStream);
485485

486486
//Should be within +/- 0.025 volts
487-
Assert.That(actual.Data.First().QuantityInBaseUnit, Is.InRange(expectedBackground.QuantityInBaseUnit - (decimal)0.025,
488-
expectedBackground.QuantityInBaseUnit + (decimal)0.025));
487+
Assert.That(actual.Data.First().QuantityInBaseUnits, Is.InRange(expectedBackground.QuantityInBaseUnits - (decimal)0.025,
488+
expectedBackground.QuantityInBaseUnits + (decimal)0.025));
489489
}
490490
finally
491491
{

src/symphony-core/IntegrationTests/SimulationIntegration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private Epoch RunSingleEpoch(double sampleRate, int nChannels, IEpochPersistor e
4848

4949
var inputData = e.Responses[dev0].Data;
5050
const double MAX_VOLTAGE_DIFF = 0.001;
51-
int failures = inputData.Select((t, i) => t.QuantityInBaseUnit - stimData[i].QuantityInBaseUnit)
51+
int failures = inputData.Select((t, i) => t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits)
5252
.Count(dif => Math.Abs(dif) > (decimal) MAX_VOLTAGE_DIFF);
5353

5454
Assert.AreEqual(0, failures);
@@ -162,7 +162,7 @@ public void MultipleEpochs(
162162

163163
var inputData = e.Responses[dev0].Data;
164164
const double MAX_VOLTAGE_DIFF = 0.001;
165-
int failures = inputData.Select((t, i) => t.QuantityInBaseUnit - stimData[i].QuantityInBaseUnit)
165+
int failures = inputData.Select((t, i) => t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits)
166166
.Count(dif => Math.Abs(dif) > (decimal) MAX_VOLTAGE_DIFF);
167167

168168
Assert.AreEqual(0, failures);
@@ -192,7 +192,7 @@ public void MultipleEpochs(
192192
Assert.DoesNotThrow(() => controller.RunEpoch(e, new FakeEpochPersistor()));
193193

194194
inputData = e.Responses[dev0].Data;
195-
failures = inputData.Select((t, i) => t.QuantityInBaseUnit - stimData[i].QuantityInBaseUnit)
195+
failures = inputData.Select((t, i) => t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits)
196196
.Count(dif => Math.Abs(dif) > (decimal) MAX_VOLTAGE_DIFF);
197197

198198

src/symphony-core/Symphony.Core.Tests/DAQStreamTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public void ThrowsIfDeviceOutputDataSampleRateMismatch()
107107

108108

109109
DAQOutputStream s = new DAQOutputStream("OUT");
110-
s.MeasurementConversionTarget = measurements.First().BaseUnit;
110+
s.MeasurementConversionTarget = measurements.First().BaseUnits;
111111

112-
s.SampleRate = new Measurement(sampleRate.QuantityInBaseUnit * 2, "Hz");
112+
s.SampleRate = new Measurement(sampleRate.QuantityInBaseUnits * 2, "Hz");
113113

114114
var outData = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(1);
115115
outData[s] = new Queue<IOutputData>(data);
@@ -163,7 +163,7 @@ public void PullsDataFromMultipleExternalDevices()
163163

164164
foreach (IOutputData d in data)
165165
{
166-
var measurements = Measurement.FromArray(d.Data.Select(m => m.QuantityInBaseUnit*numDevices).ToArray(), d.Data.BaseUnits());
166+
var measurements = Measurement.FromArray(d.Data.Select(m => m.QuantityInBaseUnits*numDevices).ToArray(), d.Data.BaseUnits());
167167
var expected = new OutputData(measurements, d.SampleRate, d.IsLast);
168168

169169
var actual = s.PullOutputData(TimeSpan.FromSeconds(1));
@@ -189,7 +189,7 @@ public void BackgroundProxiesExternalDevice()
189189
var stream = new DAQOutputStream(UNUSED_NAME);
190190
stream.Devices.Add(dev);
191191

192-
Assert.AreEqual(background.QuantityInBaseUnit, stream.Background.QuantityInBaseUnit);
192+
Assert.AreEqual(background.QuantityInBaseUnits, stream.Background.QuantityInBaseUnits);
193193
}
194194

195195
private static void OutputStreamFixture(out IList<IOutputData> data, out DAQOutputStream s, int numData)
@@ -212,7 +212,7 @@ private static void OutputStreamFixture(out IList<IOutputData> data, out DAQOutp
212212

213213
s = new DAQOutputStream("OUT")
214214
{
215-
MeasurementConversionTarget = measurements.First().BaseUnit,
215+
MeasurementConversionTarget = measurements.First().BaseUnits,
216216
SampleRate = sampleRate
217217
};
218218

0 commit comments

Comments
 (0)