static void Main(string[] args) { Console.WriteLine("Hello World!"); TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production"))); m.AddCyclingTraining(new DateTime(2020, 4, 21, 16, 00, 00), 40, new TimeSpan(1, 20, 00), 30, null, TrainingType.Endurance, null, BikeType.RacingBike); m.AddCyclingTraining(new DateTime(2020, 4, 18, 18, 00, 00), 40, new TimeSpan(1, 42, 00), null, null, TrainingType.Recuperation, null, BikeType.RacingBike); m.AddCyclingTraining(new DateTime(2020, 4, 19, 16, 45, 00), null, new TimeSpan(1, 0, 00), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike); m.AddRunningTraining(new DateTime(2020, 4, 17, 12, 30, 00), 5000, new TimeSpan(0, 27, 17), null, TrainingType.Endurance, null); m.AddRunningTraining(new DateTime(2020, 4, 19, 12, 30, 00), 5000, new TimeSpan(0, 25, 48), null, TrainingType.Endurance, null); m.AddRunningTraining(new DateTime(2020, 3, 17, 12, 0, 00), 5000, new TimeSpan(0, 28, 10), null, TrainingType.Interval, "3x700m"); m.AddRunningTraining(new DateTime(2020, 3, 17, 11, 0, 00), 8000, new TimeSpan(0, 42, 10), null, TrainingType.Endurance, null); Report r1 = m.GenerateMonthlyCyclingReport(2020, 4); Report r2 = m.GenerateMonthlyRunningReport(2020, 4); Console.WriteLine("---------------------------"); Report r3 = m.GenerateMonthlyTrainingsReport(2020, 4); foreach (var s in r3.TimeLine) { Console.WriteLine($"{s.Item1.ToString()},{s.Item2}"); } }
public void GenerateMonthlyRunningReportTest() { //Arrange = initialisatie objecten en kent waarden van gegevens toe aan methoden int year = 1996; int month = 1; //DB testCyclingSessions TrainingManager t = new TrainingManager(new UnitOfWork(new TrainingContextTest(false))); #region runningTraining maxDistanceSessionRunning DateTime now = new DateTime(1996, 1, 23); int distance = 500; TimeSpan time = new TimeSpan(0, 15, 20); float averageSpeed = 15.00f; t.AddRunningTraining(now, distance, time, averageSpeed, TrainingType.Interval, "good job!"); #endregion #region runningTraining maxSpeedSessionRunning int distance2 = 200; TimeSpan time2 = new TimeSpan(0, 20, 20); float averageSpeed2 = 25.00f; t.AddRunningTraining(now, distance2, time2, averageSpeed2, TrainingType.Recuperation, "awesome new SpeedRecord"); #endregion //Act = roept testen method op met ingestgelde parameters Report rapport = t.GenerateMonthlyRunningReport(year, month); //Assert = verifieert actie van geteste methoden rapport.MaxDistanceSessionRunning.Distance.Should().Be(500); rapport.MaxSpeedSessionRunning.AverageSpeed.Should().Be(25.00f); rapport.TotalSessions.Should().Be(2); rapport.TotalRunningDistance.Should().Be(700); rapport.TotalTrainingTime.Should().Be(new TimeSpan(0, 35, 40)); }
private void go_Click(object sender, RoutedEventArgs e) { int jaarT = 0; int maandT = 0; if (int.TryParse(inputYear.Text.Trim(), out int inputInt)) { jaarT = inputInt; } if (int.TryParse(inputMonth.Text.Trim(), out int input2)) { maandT = input2; } Report r = training.GenerateMonthlyRunningReport(jaarT, maandT); if (list.SelectedItem != null) { if (list.SelectedIndex == 0) { output.Text = ""; var maxDistance = r.MaxDistanceSessionRunning.ToString(); output.Text += maxDistance; } if (list.SelectedIndex == 1) { output.Text = ""; var maxSpeed = r.MaxSpeedSessionRunning.ToString(); output.Text += maxSpeed; } if (list.SelectedIndex == 2) { output.Text = ""; var runes = r.Runs; foreach (var rune in runes) { output.Text += rune.ToString() + "\n"; } } if (list.SelectedIndex == 3) { output.Text = ""; var totalDistance = r.TotalRunningDistance.ToString(); output.Text += totalDistance; } if (list.SelectedIndex == 4) { output.Text = ""; var totalRunninglTrainingTime = r.TotalRunningTrainingTime.ToString(); output.Text += totalRunninglTrainingTime; } } var totalSessions = r.TotalSessions.ToString(); var totalTrainingTime = r.TotalTrainingTime.ToString(); outputTotal.Text = "Total Training Time: " + totalTrainingTime + "\n" + "Total Sessions: " + totalSessions + "\n"; }
private void DialogGenerateClickEevent(object sender, RoutedEventArgs e) { DateTime inputDate = new DateTime(); try { inputDate = InputDate.SelectedDate.Value; } catch (Exception) { MessageBox.Show("You must fill in the date"); return; } if (inputDate > DateTime.Now) { MessageBox.Show("You can't select a date in the future"); return; } TrainingManager manager = new TrainingManager(new UnitOfWork(new TrainingContext("Production"))); Report rapport = manager.GenerateMonthlyRunningReport(inputDate.Year, inputDate.Month); if (rapport.TotalRunningTrainingTime.ToString(@"h\h") != "0h") { CountTime.Text = rapport.TotalRunningTrainingTime.ToString(@"h\h") + " " + rapport.TotalRunningTrainingTime.ToString(@"m\m"); } else { CountTime.Text = rapport.TotalRunningTrainingTime.ToString(@"m\m"); } CountRunning.Text = rapport.RunningSessions.ToString(); int distance = rapport.TotalRunningDistance; if (distance < 10000) { CountDistance.Text = distance.ToString() + "m"; } else { CountDistance.Text = (distance / 1000) + "km"; } dataTable.Clear(); RunningSession maxDistance = rapport.MaxDistanceSessionRunning; addDataLine("Distance", maxDistance.TrainingType.ToString(), maxDistance.Distance + " m", maxDistance.Time, Math.Round(maxDistance.AverageSpeed, 2) + " km/h", maxDistance.When, maxDistance.Comments); RunningSession maxSpeed = rapport.MaxSpeedSessionRunning; addDataLine("Speed", maxSpeed.TrainingType.ToString(), maxSpeed.Distance + " m", maxSpeed.Time, Math.Round(maxSpeed.AverageSpeed, 2) + " km/h", maxSpeed.When, maxSpeed.Comments); Dialog.IsOpen = false; }
public void GenerateMonthlyRunningReportTest() { SetupForReportTests(); var r = tm.GenerateMonthlyRunningReport(2020, 4); r.Runs.Select(x => x.When.Month).All(m => m == 4); r.Runs.Count.Should().Be(2); r.TotalRunningDistance.Should().Be(5000 + 5000); r.TotalRunningTrainingTime.Should().Be(TimeSpan.FromTicks(new TimeSpan(0, 27, 17).Ticks + new TimeSpan(0, 25, 48).Ticks)); }
public void MonthlyRunningTrainingTest() { // t.AddCyclingTraining(new DateTime(2020, 5, 24, 08, 00, 00), 60, new TimeSpan(1, 00, 02), 20, null, TrainingType.Endurance, "comment", BikeType.RacingBike); TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production"))); m.AddRunningTraining(new DateTime(2020, 4, 17, 12, 30, 00), 5000, new TimeSpan(0, 27, 17), 20, TrainingType.Endurance, null); m.AddRunningTraining(new DateTime(2020, 4, 19, 12, 30, 00), 5000, new TimeSpan(0, 25, 48), 25, TrainingType.Endurance, null); var mt = m.GenerateMonthlyRunningReport(2020, 4); mt.TotalRunningDistance.Should().Be(10000); mt.TotalRunningTrainingTime.Should().Be(new TimeSpan(0, 52, 65)); mt.Runs.Select(x => x.When.Month).All(m => m == 4); mt.Runs.Count.Should().Be(2); }
public void RunReportTests() { TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false))); tm.AddRunningTraining(new DateTime(2019, 10, 1), 200, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 1"); tm.AddRunningTraining(new DateTime(2019, 10, 2), 300, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 2"); tm.AddRunningTraining(new DateTime(2019, 10, 3), 150, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 3"); tm.AddRunningTraining(new DateTime(2018, 10, 1), 200, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 4"); int expectedNumberOfTrainings = 3; int expectedDistance = 200; Report report = tm.GenerateMonthlyRunningReport(2019, 10); report.RunningSessions.Should().Be(expectedNumberOfTrainings); report.Runs[0].Distance.Should().Be(expectedDistance); }
private void SetMonthlyOverview() { var yearMonthArray = tbNumberOfMonthAndYear.Text.Split("/").ToList(); bool monthOk = int.TryParse(yearMonthArray.FirstOrDefault(), out int month); bool yearOk = int.TryParse(yearMonthArray.LastOrDefault(), out int year); monthOk = (monthOk) ? (month > 0 && month < 13) : false; yearOk = (yearOk) ? (year > 0 && year < 100000) : false; if (!monthOk || !yearOk) { MessageBox.Show("Give a acceptable date please...", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); tbNumberOfMonthAndYear.Text = String.Empty; return; } if (cbBycicle.IsChecked == true && cbRunning.IsChecked == false) { var report = tm.GenerateMonthlyCyclingReport(year, month); lvOverview.ItemsSource = report.Rides; } else if (cbRunning.IsChecked == true && cbBycicle.IsChecked == false) { var report = tm.GenerateMonthlyRunningReport(year, month); lvOverview.ItemsSource = report.Runs; } else if (cbRunning.IsChecked == true && cbBycicle.IsChecked == true) { var report = tm.GenerateMonthlyTrainingsReport(year, month); var timeLine = report.TimeLine; var objects = new List <Object>(); foreach (var t in timeLine) { objects.Add(t.Item2); } lvOverview.ItemsSource = objects; } else { MessageBox.Show("Please select Running or Biking or both...", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } lbTitle.Content = $"Sessions in {(Months)month} of {year}"; }
public void ShowResults(int year, int month) { TrainingManager trainingManager = new TrainingManager(new UnitOfWork(new TrainingContext(_databaseString))); Report report = trainingManager.GenerateMonthlyRunningReport(year, month); dataGridShowResults.ItemsSource = report.TimeLine; dataGridShowFastest.ItemsSource = new List <object>() { report.MaxSpeedSessionRunning }; dataGridShowLongest.ItemsSource = new List <object>() { report.MaxDistanceSessionRunning }; startDateReport.Text = $"{report.StartDate.Year}/{report.StartDate.Month:00}/{report.StartDate.Day:00}"; endDateReport.Text = $"{report.EndDate.Year}/{report.EndDate.Month:00}/{report.EndDate.Day:00}"; AmountOfRunningSessions.Text = report.RunningSessions.ToString(); TotalRunningTime.Text = report.TotalRunningTrainingTime.ToString(); TotalRunningDistance.Text = report.TotalRunningDistance.ToString() + " km"; }
private void Button_Click(object sender, RoutedEventArgs e) { TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production"))); if (MonthRadioButton.IsChecked == true) { if (RunningRadioButton.IsChecked == true) { Report report = m.GenerateMonthlyRunningReport(2020, (cmbMonth.SelectedIndex) + 1); dgTraining.ItemsSource = report.Runs; txtBestDistance.Text = report.MaxDistanceSessionRunning.ToString(); txtHighestAverageSpeed.Text = report.MaxSpeedSessionRunning.ToString(); } else if (CyclingRadioButton.IsChecked == true) { Report report = m.GenerateMonthlyCyclingReport(2020, (cmbMonth.SelectedIndex) + 1); dgTraining.ItemsSource = report.Rides; txtBestDistance.Text = report.MaxDistanceSessionCycling.ToString(); txtHighestAverageSpeed.Text = report.MaxSpeedSessionCycling.ToString(); txtHighestWattage.Text = report.MaxWattSessionCycling.ToString(); } else { dgTraining.ItemsSource = m.GenerateMonthlyTrainingsReport(2020, (cmbMonth.SelectedIndex) + 1).TimeLine; } } else { if (RunningRadioButton.IsChecked == true) { dgTraining.ItemsSource = m.GetPreviousRunningSessions(int.Parse(txtSessionAmount.Text)); } else if (CyclingRadioButton.IsChecked == true) { dgTraining.ItemsSource = m.GetPreviousCyclingSessions(int.Parse(txtSessionAmount.Text)); } } }
private void inputButton_Click(object sender, RoutedEventArgs e) { try { int year = 0; if (string.IsNullOrWhiteSpace(yearInput.Text)) { throw new ArgumentException("Year is not a whole number."); } if (!int.TryParse(yearInput.Text, out int yearParsed)) { throw new ArgumentException("Year is not a whole number."); } else { year = yearParsed; } int month = 0; if (string.IsNullOrWhiteSpace(monthInput.Text)) { throw new ArgumentException("Month is not a whole number."); } if (!int.TryParse(monthInput.Text, out int monthParsed)) { throw new ArgumentException("Month is not a whole number."); } else { if (!(monthParsed <= 12)) { throw new ArgumentException("Month is bigger than 12."); } month = monthParsed; } Report r = null; if (selectedBoxes == -1) { r = tm.GenerateMonthlyTrainingsReport(year, month); if (r.Runs.Count == 0) { throw new Exception("There are no run session for the given month and year."); } if (r.Rides.Count == 0) { throw new Exception("There are no cycle session for the given month and year."); } } else if (selectedBoxes == 0) { r = tm.GenerateMonthlyRunningReport(year, month); if (r.Runs.Count == 0) { throw new Exception("There are no run session for the given month and year."); } } else if (selectedBoxes == 1) { r = tm.GenerateMonthlyCyclingReport(year, month); if (r.Rides.Count == 0) { throw new Exception("There are no cycle session for the given month and year."); } } sessionsHeader.Text += $@" {month}/{year}"; inputPanel.Visibility = Visibility.Collapsed; MaxHeight = 450; MaxWidth = 550; this.Height = 450; this.Width = 600; if (selectedBoxes == -1 || selectedBoxes == 0) { bestRunningSessions.Visibility = Visibility.Visible; } if (selectedBoxes == -1 || selectedBoxes == 1) { bestCyclingSessions.Visibility = Visibility.Visible; } sessionsPanel.Visibility = Visibility.Visible; MinHeight = 450; MinWidth = 600; SetSessions(r); } catch (ArgumentException aex) { ShowErrorMessage(aex.Message); } catch (Exception ex) { ShowErrorMessage(ex.Message); } }
public Report GetMonlyRunningReport(int jaar, int maant) { return(_gerry.GenerateMonthlyRunningReport(jaar, maant)); }
private void Button_Click(object sender, RoutedEventArgs e) { bool? cycling = cyclingCheckBox.IsChecked; bool? running = runningCheckBox.IsChecked; int year; int month; bool yearW = int.TryParse(yearTextBox.Text, out year); bool monthW = int.TryParse(monthTextBox.Text, out month); Report rapport; try { if (!yearW) { throw new ArgumentException("year is not correct or not inserted"); } else if (!monthW) { throw new ArgumentException("Month is not correct or not inserted"); } if (cycling == true && running == true) { rapport = m.GenerateMonthlyTrainingsReport(year, month); trainingPerMonthDataGrid.ItemsSource = rapport.TimeLine; trainingPerMonthDataGrid.Items.Refresh(); //beste toevoegen besteTrainingen.Text = "CyclingSSession \n" + "----------------\n" + $"MaxDistance: {rapport.MaxDistanceSessionCycling} \n" + $"MaxSpeed: {rapport.MaxSpeedSessionCycling}\n" + $"MaxWatt: {rapport.MaxWattSessionCycling}\n\n" + "RunningSession \n" + "----------------\n" + $"MaxDistance: {rapport.MaxDistanceSessionRunning}\n" + $"MaxSpeed: {rapport.MaxSpeedSessionRunning}\n"; } else if (cycling == true) { rapport = m.GenerateMonthlyCyclingReport(year, month); trainingPerMonthDataGrid.ItemsSource = rapport.Rides; trainingPerMonthDataGrid.Items.Refresh(); //beste toevoegen besteTrainingen.Text = "CyclingSSession \n" + "----------------\n" + $"MaxDistance: {rapport.MaxDistanceSessionCycling}\n" + $"MaxSpeed: {rapport.MaxSpeedSessionCycling}\n" + $"MaxWatt: {rapport.MaxWattSessionCycling} \n"; } else if (running == true) { rapport = m.GenerateMonthlyRunningReport(year, month); trainingPerMonthDataGrid.ItemsSource = rapport.Runs; trainingPerMonthDataGrid.Items.Refresh(); //beste toevoegen besteTrainingen.Text = "RunningSession \n" + "----------------\n" + $"MaxDistance: {rapport.MaxDistanceSessionRunning} m \n" + $"MaxSpeed: {rapport.MaxSpeedSessionRunning} m/s \n"; } else { throw new ArgumentException("Please check at least one checkbox"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Home", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void TestMonthlyRunningReport() { //Arrange TrainingManager addingManager = new TrainingManager(new UnitOfWork(new TrainingContextTest())); DateTime fastestRunTime = new DateTime(2010, 4, 12); DateTime ignoredSessionTime = new DateTime(2000, 2, 5); DateTime longestRunTime = new DateTime(2010, 4, 10); RunningSession fastestRun = new RunningSession(fastestRunTime, 20000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); RunningSession secFastRun = new RunningSession(ignoredSessionTime, 20000, new TimeSpan(5, 0, 0), null, TrainingType.Endurance, null); RunningSession longestRun = new RunningSession(longestRunTime, 25000, new TimeSpan(10, 0, 0), null, TrainingType.Endurance, null); addingManager.AddRunningTraining(fastestRun.When, fastestRun.Distance, fastestRun.Time, fastestRun.AverageSpeed, fastestRun.TrainingType, fastestRun.Comments); addingManager.AddRunningTraining(secFastRun.When, secFastRun.Distance, secFastRun.Time, secFastRun.AverageSpeed, secFastRun.TrainingType, secFastRun.Comments); addingManager.AddRunningTraining(longestRun.When, longestRun.Distance, longestRun.Time, longestRun.AverageSpeed, longestRun.TrainingType, longestRun.Comments); DateTime secondRunTime = new DateTime(2010, 5, 10); DateTime firstRunTime = new DateTime(2010, 5, 1); DateTime thirdRunTime = new DateTime(2010, 5, 31); DateTime laterRunTime = new DateTime(2010, 6, 1); DateTime earlyRunTime = new DateTime(2010, 4, 30); RunningSession secondRun = new RunningSession(secondRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); RunningSession firstRun = new RunningSession(firstRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); RunningSession thirdRun = new RunningSession(thirdRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); RunningSession laterRun = new RunningSession(laterRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); RunningSession earlyRun = new RunningSession(earlyRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null); addingManager.AddRunningTraining(secondRun.When, secondRun.Distance, secondRun.Time, secondRun.AverageSpeed, secondRun.TrainingType, secondRun.Comments); addingManager.AddRunningTraining(firstRun.When, firstRun.Distance, firstRun.Time, firstRun.AverageSpeed, firstRun.TrainingType, firstRun.Comments); addingManager.AddRunningTraining(thirdRun.When, thirdRun.Distance, thirdRun.Time, thirdRun.AverageSpeed, thirdRun.TrainingType, thirdRun.Comments); addingManager.AddRunningTraining(laterRun.When, laterRun.Distance, laterRun.Time, laterRun.AverageSpeed, laterRun.TrainingType, laterRun.Comments); addingManager.AddRunningTraining(earlyRun.When, earlyRun.Distance, earlyRun.Time, earlyRun.AverageSpeed, earlyRun.TrainingType, earlyRun.Comments); //Act TrainingManager reportManager = new TrainingManager(new UnitOfWork(new TrainingContextTest(true))); int reportYear = 2010; int reportMonth = 5; Report report = reportManager.GenerateMonthlyRunningReport(reportYear, reportMonth); //Assert Assert.AreEqual(report.StartDate, new DateTime(reportYear, reportMonth, 1), "StartDate dit not match up"); Assert.AreEqual(report.EndDate, new DateTime(reportYear, reportMonth, DateTime.DaysInMonth(reportYear, reportMonth)), "EndDate did not match up"); Assert.IsNull(report.Rides, "Rides was not null"); Assert.AreEqual(report.RunningSessions, 3, "Number of RunningSession was incorrect"); Assert.AreEqual(report.TotalSessions, 3, "Number of TotalSessions was incorrect"); Assert.AreEqual(report.Runs[0].When, firstRunTime, "The first element in Runs dit not match,probably not sorted by date properly"); Assert.AreEqual(report.Runs[1].When, secondRunTime, "The second element in Runs dit not match"); Assert.AreEqual(report.Runs[2].When, thirdRunTime, "The third element in Runs dit not match"); Assert.AreEqual(report.MaxDistanceSessionRunning.When, longestRunTime, "Max Distance Run did not match up"); Assert.AreEqual(report.MaxSpeedSessionRunning.When, fastestRunTime, "Max Speed Run did not match up"); Assert.AreEqual(report.TotalRunningDistance, secondRun.Distance + firstRun.Distance + thirdRun.Distance); Assert.AreEqual(report.TotalRunningTrainingTime, secondRun.Time + firstRun.Time + thirdRun.Time); Assert.AreEqual(report.TimeLine[0].Item2, report.Runs[0], "Runs and Timeline did not match up"); Assert.AreEqual(report.TimeLine[1].Item2, report.Runs[1], "Runs and Timeline did not match up"); Assert.AreEqual(report.TimeLine[2].Item2, report.Runs[2], "Runs and Timeline did not match up"); }