Esempio n. 1
0
        public void SaveTraining(Training training, List <List <Localization> > localizations)
        {
            IFormatter formatter = new BinaryFormatter();

            using (MemoryStream stream = new MemoryStream())
            {
                formatter.Serialize(stream, localizations);
                training.SerializedLocalizations = stream.ToArray();
            }
            trainingRepository.SaveTraining(training);
        }
Esempio n. 2
0
        public TrainingTypeStatistic GetTrainingTypeStatistic(TrainingType?type = null)
        {
            var trainingTypeStatistics = new TrainingTypeStatistic();
            var trainings = trainingRepository.GetTrainings();

            if (trainings.Count == trainings.Count(t => t.Type == TrainingType.Running))
            {
                foreach (var t in trainings)
                {
                    if (t.Distance > 200)
                    {
                        t.Type = TrainingType.Skating;
                    }
                    else
                    {
                        t.Type = TrainingType.Cycling;
                    }
                    trainingRepository.SaveTraining(t);
                }
            }

            if (type == null)
            {
                trainingTypeStatistics.Count = trainings.Count();
                if (trainingTypeStatistics.Count > 0)
                {
                    trainingTypeStatistics.AllDistance = trainings
                                                         .Sum(training => training.Distance);
                    trainingTypeStatistics.AllTime = (int)trainings
                                                     .Sum(training => training.Time);
                    trainingTypeStatistics.AverageDistance = trainings
                                                             .Average(training => training.Distance);
                    trainingTypeStatistics.AverageTime = (int)trainings
                                                         .Average(training => training.Time);
                    trainingTypeStatistics.AverageTempo    = trainingTypeStatistics.AllTime / 60 / trainingTypeStatistics.AllDistance;
                    trainingTypeStatistics.AverageVelocity = trainingTypeStatistics.AllDistance / ((double)trainingTypeStatistics.AllTime / 60 / 60);
                }
            }
            else
            {
                trainingTypeStatistics.Count = trainings.Count(training => training.Type == type);
                if (trainingTypeStatistics.Count > 0)
                {
                    trainingTypeStatistics.AllDistance = trainings
                                                         .Where(training => training.Type == type)
                                                         .Sum(training => training.Distance);
                    trainingTypeStatistics.AllTime = (int)trainings
                                                     .Where(training => training.Type == type)
                                                     .Sum(training => training.Time);
                    trainingTypeStatistics.AverageDistance = trainings
                                                             .Where(training => training.Type == type)
                                                             .Average(training => training.Distance);
                    trainingTypeStatistics.AverageTime = (int)trainings
                                                         .Where(training => training.Type == type)
                                                         .Average(training => training.Time);
                    trainingTypeStatistics.AverageTempo    = trainingTypeStatistics.AllTime / 60 / trainingTypeStatistics.AllDistance;
                    trainingTypeStatistics.AverageVelocity = trainingTypeStatistics.AllDistance / ((double)trainingTypeStatistics.AllTime / 60 / 60);
                }
            }
            return(trainingTypeStatistics);
        }
 public int SaveTraining(Training training)
 {
     return(trainingRepository.SaveTraining(training));
 }
Esempio n. 4
0
 public void EditTraining(Training training)
 {
     trainingRepository.SaveTraining(training);
 }