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 List <Training> GetAllTrainings() { return(trainingRepository.GetTrainings()); }
public ActionResult Index() { List<Training> allTrainings = _trainingRepository.GetTrainings().ToList(); return View(allTrainings); }