コード例 #1
0
 public Serie BuildReadingSerie(ReadingMessageDTO dto)
 {
     return new Serie.Builder(_influxDbReadingSeries).
         Columns(
             InfluxSerieConstants.SensorId,
             InfluxSerieConstants.RawMessage,
             InfluxSerieConstants.SerialNumber,
             InfluxSerieConstants.Humidity,
             InfluxSerieConstants.Temperature,
             InfluxSerieConstants.Resistance)
         .Values(
             dto.SensorId,
             dto.RawMessage,
             dto.SerialNumber,
             dto.Humidity,
             dto.Temperature,
             dto.Resistance).
         Build();
 }
コード例 #2
0
 public Point BuildReadingPoint(ReadingMessageDTO dto)
 {
     return new Point()
     {
         Name = "reading",
         Tags = new Dictionary<string, object>()
         {
             { InfluxSerieConstants.SensorId, dto.SensorId },
             { InfluxSerieConstants.SerialNumber, dto.SerialNumber }
         },
         Fields = new Dictionary<string, object>()
         {
             { InfluxSerieConstants.RawMessage, dto.RawMessage },
             { InfluxSerieConstants.Humidity, dto.Humidity },
             { InfluxSerieConstants.Temperature, dto.Temperature },
             { InfluxSerieConstants.Resistance, dto.Resistance }
         },
         Timestamp = dto.DateCreated
     };
 }
コード例 #3
0
 public async Task<IInfluxDbApiResponse> SaveReading(ReadingMessageDTO dto)
 {
     var data = BuildReadingPoint(dto);
     return await WriteData(data);
 }
コード例 #4
0
        private static IList<ReadingMessageDTO> ConvertToV9(IList<InfluxDB.Net.Models.Serie> series)
        {
            var readings = new List<ReadingMessageDTO>();

            if (series.Count == 0)
                Console.WriteLine("No data");

            foreach (var serie in series)
            {
                Console.WriteLine("Points: {0}", serie.Points.Count());

                var sensorIdIndex = Array.IndexOf(serie.Columns, "SensorId");
                var rawMessageIndex = Array.IndexOf(serie.Columns, "RawMessage");
                var temperatureIndex = Array.IndexOf(serie.Columns, "Temperature");
                var humidityIndex = Array.IndexOf(serie.Columns, "Humidity");
                var resistanceIndex = Array.IndexOf(serie.Columns, "Resistance");
                var timeIndex = Array.IndexOf(serie.Columns, "time");


                foreach (var point in serie.Points)
                {
                    var sensorId = point[sensorIdIndex];
                    var rawMessage = point[rawMessageIndex];
                    var temperature = point[temperatureIndex];
                    var humidity = point[humidityIndex];
                    var resistance = point[resistanceIndex];
                    var timestamp = point[timeIndex];

                    var reading = new ReadingMessageDTO()
                    {
                        SerialNumber = serie.Name,
                        SensorId = SensorsToMigrate.FromV8ToV9[serie.Name],
                        RawMessage = rawMessage.ToString(),
                        Temperature = Int32.Parse(temperature.ToString()),
                        Humidity = Int32.Parse(humidity.ToString()),
                        Resistance = Int32.Parse(resistance.ToString()),
                        DateCreated = TimeHelper.UnixTimestampToDateTime(Int64.Parse(timestamp.ToString()))
                    };

                    readings.Add(reading);
                }
            }

            return readings;
        }
コード例 #5
0
        private static async Task EnsureAllFieldsExist()
        {
            foreach (var sensor in _sensors)
            {
                var fakeReading = new ReadingMessageDTO()
                {
                    SerialNumber = sensor.Key,
                    SensorId = -1,
                    RawMessage = "fakeMessage",
                    Temperature = 0,
                    Humidity = 0,
                    Resistance = 0,
                    DateCreated = DateTime.UtcNow
                };

                await _v8.SaveReading(fakeReading);
                await Task.Delay(_timeBetweenRequests);
            }
        }
コード例 #6
0
 public async Task<InfluxDbApiResponse> SaveReading(ReadingMessageDTO dto)
 {
     var data = BuildReadingSerie(dto);
     return await WriteData(TimeUnit.Milliseconds, data);
 }