예제 #1
0
        public async Task <StateRecordSlimDTO> GetForTrainingAsync(int trainingId)
        {
            IEnumerable <StateRecord> records = await stateRecords.GetForTrainingAsync(trainingId);

            return(new StateRecordSlimDTO
            {
                TrainingId = trainingId,
                StateRecords = records.Select(rec => new StateRecordSlimDTO.StateRecord
                {
                    CreateTime = rec.CreateTime,
                    TeamMemberId = rec.TeamMemberId,
                    HeartRate = rec.HeartRate,
                    Temperature = rec.Temperature
                })
            });
        }
예제 #2
0
        public async Task <IEnumerable <CriticalMomentDTO> > GetCriticalMomentsForTrainingAsync(int trainingId)
        {
            TrainingDTO training = await trainingService.GetTrainingAsync(trainingId);

            if (training == null)
            {
                throw new NotFoundException("Training doesn't exist!");
            }

            bool hasCachedInDb = await criticalMoments.IsCachedForTrainingAsync(trainingId);

            IEnumerable <CriticalMoment> moments;

            if (hasCachedInDb)
            {
                moments = await criticalMoments.GetForTrainingAsync(trainingId);
            }
            else
            {
                bool isTrainingOver = await trainingService.IsTrainingOverAsync(trainingId);

                if (!isTrainingOver)
                {
                    throw new BadRequestException("Training hasn't finished yet! Stop it or wait!");
                }

                var states = await stateRecors.GetForTrainingAsync(trainingId);

                moments = stressRecognitionService
                          .FindCriticalMoments(states)
                          .Select(interval => new CriticalMoment
                {
                    TrainingId = trainingId,
                    BeginTime  = interval.Begin,
                    EndTime    = interval.End
                });
                await criticalMoments.SetCachedForTrainingAsync(trainingId);

                await criticalMoments.CreateManyAsync(moments);
            }

            return(moments.Select(moment => new CriticalMomentDTO
            {
                Id = moment.Id,
                TrainingId = moment.TrainingId,
                BeginTime = moment.BeginTime,
                EndTime = moment.EndTime
            }));
        }