예제 #1
0
        public async Task <IHttpActionResult> Post([FromBody] TrashCanStatus trashCanStatus, Guid deviceId)
        {
            trashCanStatus.DeviceId  = deviceId;
            trashCanStatus.Timestamp = DateTime.UtcNow;
            if (trashCanStatus.Distance < 0)
            {
                return(BadRequest("Negative distance"));
            }
            await DocumentDbRepository <TrashCanStatus> .CreateItemAsync(trashCanStatus);

            return(Ok());
        }
예제 #2
0
        public static decimal FillGrade(TrashCanStatus status)
        {
            if (!status.LidIsClosed)
            {
                return((decimal) - 1.0);
            }

            decimal height = (status.Distance.Sensor1 + status.Distance.Sensor2) / 2;

            if (height <= 0 || height >= MAX_TRASH_CAN_HEIGHT)
            {
                return((decimal) - 1.0);
            }

            return(1 - (height / MAX_TRASH_CAN_HEIGHT));
        }
        public async Task <IHttpActionResult> Post([FromBody] TrashCanStatus trashCanStatus, string deviceId)
        {
            var storedTrashCanStatus = TrashCanReadingMapper.MapToStoredCanStatus(trashCanStatus);
            var existing             = await DocumentDbRepository <TrashCan> .GetItemAsync(deviceId);

            if (existing == null)
            {
                return(NotFound());
            }
            storedTrashCanStatus.Timestamp = DateTime.UtcNow;
            existing.LatestReading         = storedTrashCanStatus;
            existing.TrashCanStatuses.Add(storedTrashCanStatus);
            await DocumentDbRepository <TrashCan> .UpdateItemAsync(existing.id, existing);

            TrashWebSocketHandler.SendTrashCanStaus(deviceId);

            return(Ok());
        }
        public static StoredTrashCanStatus MapToStoredCanStatus(TrashCanStatus incomingStatus)
        {
            var fillGrade = FillCalculator.FillGrade(incomingStatus);

            var result = new StoredTrashCanStatus
            {
                Accelerometer = incomingStatus.Accelerometer,
                Distance      = incomingStatus.Distance,
                Temperature   = incomingStatus.Temperature,
                Timestamp     = incomingStatus.Timestamp,
                Flame         = incomingStatus.Flame,
                LidIsClosed   = incomingStatus.LidIsClosed,
                FillGrade     = fillGrade,
                Weight        = incomingStatus.Weight
            };


            return(result);
        }