コード例 #1
0
		public static void PublishReading(Reading reading)
		{
            Logger.Debug("Enqueuing reding " + GetReadingInfo(reading));
			lock (PublishReadingLock)
			{
				Readings.Enqueue(reading);
			}
		}
コード例 #2
0
        public void Aggregate_AddsUpTheValuesFromTwoDatapoints()
        {
            var reading1 = new Reading() { FeatureName = "test", Data = new DoubleReadingData(10.5) };
            var reading2 = new Reading() { FeatureName = "test", Data = new DoubleReadingData(1.1) };
            reading1.Data.Aggregate(reading2.Data);

            Assert.That(reading1.Data.GetValue(), Is.EqualTo(10.5 + 1.1));

        }
コード例 #3
0
        public void Aggregate_ReturnsTheMinOfTwoValues()
        {
            var reading1 = new Reading() { FeatureName = "test", Data = new MinReadingData(10.5) };
            var reading2 = new Reading() { FeatureName = "test", Data = new MinReadingData(1.1) };

            reading1.Data.Aggregate(reading2.Data);

            Assert.That(reading1.Data.GetValue(), Is.EqualTo(1.1));
        }
コード例 #4
0
        protected void AddReading(ReadingData data)
        {
            if (string.IsNullOrEmpty(data.Name))
                data.Name = ReadingName;

            FeatureDescriptor descriptor = GetFeatureDescriptor();
            var newReading = new Reading { FeatureName = descriptor.Name, FeatureGroup = descriptor.Group, Data = data };
            ReadingPublisher.PublishReading(newReading);
        }
コード例 #5
0
        public void Aggregate_ReturnsTheAvegareOfAllAggregatedValues()
        {
            var reading1 = new Reading() { FeatureName = "test", Data = new AvgReadingData(10.0) };
            var reading2 = new Reading() { FeatureName = "test", Data = new AvgReadingData(1.0) };
            var reading3 = new Reading() { FeatureName = "test", Data = new AvgReadingData(4.0) };

            reading1.Data.Aggregate(reading2.Data);
            reading1.Data.Aggregate(reading3.Data);

            Assert.That(reading1.Data.GetValue(), Is.EqualTo(5.0));
        }
コード例 #6
0
 private static string GetReadingInfo(Reading reading)
 {
     if (reading != null)
         return String.Format("FeatureName: {0}, group: {1}, reading; {2}, value: {3}", reading.FeatureName, reading.FeatureGroup, reading.Data.Name, reading.Data.GetValue());
     return "Null reading";
 }
コード例 #7
0
		static void ProcessReading(ICollection<FeatureStatistics> dataPoints, Reading reading)
		{
			var dataPoint = dataPoints.FirstOrDefault(data => data.Name == reading.FeatureName && data.Group == reading.FeatureGroup);
			if (dataPoint == null)
			{
				dataPoint = new FeatureStatistics { Name = reading.FeatureName, Group = reading.FeatureGroup };
				dataPoint.Readings.Add(reading.Data);
				dataPoints.Add(dataPoint);
			}
			else
			{
				var readingData = dataPoint.Readings.FirstOrDefault(rd => rd.Name == reading.Data.Name);
				if (readingData == null)
					dataPoint.Readings.Add(reading.Data);
				else
					readingData.Aggregate(reading.Data);
			}
		}