Ejemplo n.º 1
0
        public static void SeedTrainingData(List <int> userIds, DateTime now, int effortId, int trainigTypeId,
                                            int days = 1)
        {
            GenericError error;
            var          trainingDataRepository = new TrainingSessionsRepository();
            var          trainingSessionMeasurmentDataRepository = new TrainingSessionMeasurmentDataRepository();

            trainingDataRepository.Drop();
            trainingSessionMeasurmentDataRepository.Drop();

            userIds.ForEach(userId =>
            {
                DateTime initial = now.AddDays(-days);
                for (int i = 0; i < days; i++)
                {
                    TrainingSession session = CreateEffortTrainingData(initial, i,
                                                                       trainingSessionMeasurmentDataRepository, null,
                                                                       userId);
                    session.TrainingTypeId = trainigTypeId;
                    session.EffortId       = effortId;

                    trainingDataRepository.InsertEntity(out error, session);
                }
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sessions"></param>
        /// <param name="trainingSession"></param>
        /// <param name="splitingSeconds"></param>
        public void SplitSessionAtSpecificTime(List <TrainingSession> sessions, TrainingSession trainingSession, DateTime splitingDateTime)
        {
            var measurmentData = GetSessionMeasurmentInfo(trainingSession.TrainingSessionId);

            var data = measurmentData.FirstOrDefault();

            TrainingSessionMeasurmentData session2Data = null;
            TrainingSessionMeasurmentData session1Data = null;

            if (data != null)
            {
                session1Data = CopyPartialMeasurmentsData(data, (m, t) => m.Where(x => x.Time >= splitingDateTime).ToList());
                session2Data = CopyPartialMeasurmentsData(data, (m, t) => m.Where(x => x.Time <= splitingDateTime).ToList());
                //session1Data = CopyPartialMeasurmentsData(data, (m, t) => m.Take(GetIndexForTime(t, splitingSeconds)).ToList());
                //session2Data = CopyPartialMeasurmentsData(data, (m, t) => m.Skip(GetIndexForTime(t, splitingSeconds)).ToList());
            }

            if (session1Data != null &&
                session2Data != null)
            {
                session1Data.TrainingSessionId = sessions[0].TrainingSessionId;
                session2Data.TrainingSessionId = sessions[1].TrainingSessionId;

                session1Data.UserId = trainingSession.UserId;
                session2Data.UserId = trainingSession.UserId;

                GenericError error;

                try
                {
                    TrainingSessionDataRepository.InsertEntity(out error, session1Data);
                    TrainingSessionDataRepository.InsertEntity(out error, session2Data);
                }
                catch (Exception e)
                {
                    error = new GenericError {
                        ErrorDesc = e.Message
                    };
                }

                if (error == null)
                {
                    TrainingSessionsRepository.InsertEntity(out error, sessions);

                    measurmentData.ToList().ForEach(md => TrainingSessionDataRepository.Remove(m => m.TrainingSessionId == md.TrainingSessionId, out error));
                    TrainingSessionsRepository.Remove(s => s.TrainingSessionId == trainingSession.TrainingSessionId, out error);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sessions"></param>
        public void InsertTrainingSession(List <TrainingSession> sessions)
        {
            GenericError error;

            TrainingSessionsRepository.InsertEntity(out error, sessions);
        }