public async Task <IActionResult> GetMeasurmentsByDeviceId(string deviceName)
        {
            var devices = await _unitOfWork.Devices.GetAllActiveDevices();

            var deviceFound = devices.FirstOrDefault(d => d.Name.ToLowerInvariant().Equals(deviceName.ToLowerInvariant()));

            if (deviceFound == null)
            {
                return(NoContent());
            }

            var measurment = await _unitOfWork.Measurements.GetByDeviceId(deviceFound.Id);

            if (measurment == null)
            {
                return(NoContent());
            }

            var dto = new MeasurementDto
            {
                DeviceId    = measurment.DeviceId,
                Timestamp   = measurment.Timestamp,
                Temperature = Math.Truncate(measurment.Temperature * 100) / 100,
                Humidity    = Math.Round(measurment.Humidity)
            };

            return(Ok(dto));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddMeasurement([FromBody] MeasurementDto dto)
        {
            var measurement = new Measurement
            {
                DeviceId    = dto.DeviceId,
                Temperature = dto.Temperature,
                Humidity    = dto.Humidity,
                Timestamp   = DateTime.Now
            };

            var m = await _unitOfWork.Measurements.GetByDeviceId(dto.DeviceId);

            if (m == null)
            {
                _unitOfWork.Measurements.Add(measurement);
                _unitOfWork.Save();
            }
            else
            {
                m.Temperature = dto.Temperature;
                m.Humidity    = dto.Humidity;
                m.Timestamp   = DateTime.Now;

                await _unitOfWork.Measurements.UpdateAsync(m);
            }

            await _hubContext.Clients.All.InvokeAsync("Broadcast", "Sensor", measurement);

            return(NoContent());
        }
        public void InsertMeasurement(string userId, MeasurementDto measurementDto)
        {
            var measurement = Mapper.Map <Measurement>(measurementDto);

            measurement.UserId = userId;
            _db.Measurements.Add(measurement);
            _db.SaveChanges();
        }
Ejemplo n.º 4
0
 public static Measurement DtoMeasurementMapper(MeasurementDto measurementDto, UserDto userDto)
 {
     return(new Measurement()
     {
         User = Mappers.UserMapper.DtoUserMapper(userDto),
         Weight = measurementDto.Weight
     });
 }
Ejemplo n.º 5
0
        private Task <Guid> RunAsync(MeasurementDto measurementDto)
        {
            _measurementRepository.AddMeasurement(
                testSeriesId: _context.TestSeriesId,
                MAC: measurementDto.MAC,
                RSSI: measurementDto.RSSI,
                channel: measurementDto.Channel);

            return(Task.FromResult(Guid.NewGuid()));
        }
Ejemplo n.º 6
0
 public async Task AddAsync(MeasurementDto measurementDto)
 {
     var measurement = new Measurement
     {
         Id     = 0,
         ItemId = measurementDto.ItemId,
         Value  = measurementDto.Value,
         Time   = measurementDto.Time,
     };
     await DbContext.Measurements.AddAsync(measurement);
 }
Ejemplo n.º 7
0
        private Task <MeasurementDto> RunAsync(MeasurementDto measurementDto)
        {
            if (_context.MACFilter != null && _context.MACFilter != measurementDto.MAC)
            {
                return(Task.FromResult((MeasurementDto)null));
            }

            _logger.LogInformation(measurementDto.ToString());

            return(Task.FromResult(measurementDto));
        }
        // POST: api/Measurements
        public IHttpActionResult PostMeasurement([FromBody] MeasurementDto measurement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = GetCurrentUserId();

            _measurementsService.AddMeasurement(userId, measurement);

            return(Ok());
        }
Ejemplo n.º 9
0
 public static MeasurementModel Converter(this MeasurementDto measurementDto)
 {
     return(measurementDto == null ? null : new MeasurementModel
     {
         Smoke = measurementDto.Fumaca,
         AirHumidity = measurementDto.UmidadeAr,
         Danger = measurementDto.Risco,
         Gas = measurementDto.Gas,
         IdDispositivo = measurementDto.DispositivoId,
         Temperature = measurementDto.Temperatura,
         UpdateDate = measurementDto.DataAtualizacao,
         IdMedicao = measurementDto.IdMedicao
     });
 }
Ejemplo n.º 10
0
        private async Task <MeasurementDto> RunAsync(string rawLine)
        {
            var parts = rawLine
                        .Trim()
                        .Split(';');

            var measurementDto = new MeasurementDto()
            {
                MAC     = parts[0],
                RSSI    = int.Parse(parts[1]),
                Channel = int.Parse(parts[2])
            };

            return(measurementDto);
        }
        public void UpdateMeasurement(string userId, MeasurementDto measurementDto)
        {
            var measurement = _db.Measurements
                              .Where(m => m.UserId == userId)
                              .First(m => m.Id == measurementDto.Id);

            if (measurement == null)
            {
                return;
            }
            measurement.Date        = measurementDto.Date;
            measurement.Description = measurementDto.Description;
            measurement.Result      = measurementDto.Result;
            //measurement = _mapper.Map<Measurement>(measurementDto); // To rozwiązanie nie działa, dowiedzieć się czemu
            _db.SaveChanges();
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> CreateMeasurement([FromBody] MeasurementDto measurementDto, long id)
        {
            if (measurementDto == null)
            {
                return(BadRequest());
            }
            var userDto = await _userService.GetById(id);

            if (userDto == null)
            {
                return(BadRequest());
            }
            await _measurementService.Add(measurementDto, userDto);

            return(Created("Created new measurement record", measurementDto));
        }
        // PUT: api/Measurements/5
        public IHttpActionResult PutMeasurement(int id, [FromBody] MeasurementDto measurement)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = GetCurrentUserId();

            if (!_measurementsService.DoesMeasurementExists(userId, id))
            {
                return(StatusCode(HttpStatusCode.NotFound));
            }

            measurement.Id = id;
            _measurementsService.UpdateMeasurement(userId, measurement);
            return(Ok());
        }
Ejemplo n.º 14
0
        public IActionResult Record(MeasurementDto measurement)
        {
            if (!measurement.Water.HasValue && !measurement.Electricity.HasValue && !measurement.Gas.HasValue)
            {
                return(BadRequest("Invalid values provided!"));
            }

            if (measurement.ApiKey?.Equals(configuration["apiKey"]) == true)
            {
                influxCollector.Record(measurement);
                logger.LogInformation($"Water: {measurement.Water}, Electicity: {measurement.Electricity}, Gas: {measurement.Gas}, Timestamp: {measurement.Timestamp}");

                return(NoContent());
            }
            else
            {
                return(BadRequest("Invalid api key provided!"));
            }
        }
Ejemplo n.º 15
0
        public void Record(MeasurementDto measurement)
        {
            var values = new Dictionary <string, object>();

            if (measurement.Water.HasValue)
            {
                values.Add("water", measurement.Water.Value);
            }

            if (measurement.Electricity.HasValue)
            {
                values.Add("electricity", measurement.Electricity.Value);
            }

            if (measurement.Gas.HasValue)
            {
                values.Add("gas", measurement.Gas.Value);
            }

            Metrics.Collector.Write(
                "energy",
                values,
                timestamp: measurement.Timestamp.ToUniversalTime());
        }
        public async Task <MeasurementDto> GetLatestMeasurement(string deviceUuid)
        {
            var measurement = await _measurementService.GetLatestMeasurement(deviceUuid);

            return(MeasurementDto.FromModel(measurement));
        }
Ejemplo n.º 17
0
 public InstallationDto WithMeasurement(MeasurementDto measurement)
 {
     this.Measurement = measurement;
     return(this);
 }
Ejemplo n.º 18
0
 public void NewActorValueReceived(MeasurementDto measurement)
 {
     WaitingForResponse = false;
     _isOn = measurement.Value == 1;
     System.Console.WriteLine($"{Name}, NewActorValueReceived, IsOn: {IsOn}, WaitingForResponse: {WaitingForResponse}");
 }
Ejemplo n.º 19
0
 public async Task SendMeasurement(MeasurementDto measurement)
 {
     await Clients.All.SendAsync("ReceiveMeasurement", measurement);
 }
Ejemplo n.º 20
0
 public void AddMeasurement(string userId, MeasurementDto measurementDto)
 {
     measurementDto.Date = DateTime.Now;
     _repository.InsertMeasurement(userId, measurementDto);
 }
Ejemplo n.º 21
0
 public void UpdateMeasurement(string userId, MeasurementDto measurementDto)
 {
     _repository.UpdateMeasurement(userId, measurementDto);
 }
Ejemplo n.º 22
0
 public async Task Add(MeasurementDto entity, UserDto userDto)
 {
     await _iMeasurementRepository.Add(MeasurementMapper.DtoMeasurementMapper(entity, userDto));
 }
Ejemplo n.º 23
0
 private void HomematicHttpCommunicationService_MeasurementReceived(object sender, MeasurementDto measurementDto)
 {
     if (measurementDto.ItemName == SensorName.HmoLivingroomFirstFloorSet.ToString())
     {
         HeatingCircuit.TargetTemperature = measurementDto.Value;
     }
 }