diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs index abed9e4b067a02d4e8b1902e0ad44c7050d196ad..ded3731c05539d84b42b3355ee450e59e47d35a2 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/01Overview.xaml.cs @@ -232,6 +232,11 @@ namespace InnoLabProjektDektopApp return tmpSession; } + public static void SetSessionInstance(Session newSession) + { + tmpSession = newSession; + } + private void ComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !int.TryParse(e.Text, out _); diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/02Session.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/02Session.xaml.cs index 1f58cb63bdd8f3a243d54b57acf745acc79a52aa..011d391712f59fa76abd275e4cc0c2ead3d91b91 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/02Session.xaml.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/02Session.xaml.cs @@ -41,6 +41,7 @@ namespace InnoLabProjektDektopApp private int step = -1; //Indicates whether the timer is running (-1) or paused (0) private int sessions; private int currentSession = 1; //Tracks which session is currently running + private ProcessMonitor processMonitor = App.GetProcessMonitor(); public Session(int focusPeriod, int breakPeriod, @@ -71,6 +72,7 @@ namespace InnoLabProjektDektopApp mascott = new Mascott(); mascott.Show(); + processMonitor.StartMonitoring(); CreateCycleIndicators(); // Kreise erstellen updateTexts(); } @@ -91,26 +93,37 @@ namespace InnoLabProjektDektopApp { stopTimer(); // Timer stoppen + if (currentSession >= sessions) // Wenn alle Zyklen abgeschlossen sind + { + timer.Dispose(); // Timer stoppen und aufräumen + MessageBox.Show("All sessions completed!", "Info", MessageBoxButton.OK, MessageBoxImage.Information); + var jsonpath = processMonitor.FinishSession(); + this.NavigationService.Navigate(new SessionStatistics(jsonpath)); + return; + } if (isBreakPeriod) // Wenn wir in einer Pause sind { isBreakPeriod = false; // Zurück zum Fokus seconds = maxTime; // Zeit für die Fokusperiode currentSession++; // Gehe zum nächsten Zyklus + processMonitor.EndBreak(); + PlayPauseButton.Content = "Pause"; } else // Wenn wir im Fokus sind { isBreakPeriod = true; // Wechsel in den Pausenmodus seconds = breakPeriod; // Zeit für die Pause + processMonitor.StartBreak(); } + - if (currentSession >= sessions) // Wenn alle Zyklen abgeschlossen sind + startTimer(); // Starte den Timer für die nächste Periode + } else + { + if(isBreakPeriod) { - timer.Dispose(); // Timer stoppen und aufräumen - MessageBox.Show("All sessions completed!", "Info", MessageBoxButton.OK, MessageBoxImage.Information); - return; + PlayPauseButton.Content = "Skip Break"; } - - startTimer(); // Starte den Timer für die nächste Periode } }); } @@ -121,12 +134,14 @@ namespace InnoLabProjektDektopApp if (seconds <= 0) return; // Prevent starting if time is zero step = -1; // Set step to countdown PlayPauseButton.Content = "Pause"; // Update button text + processMonitor.EndPause(); } public void stopTimer() { step = 0; // Stop counting down PlayPauseButton.Content = "Start"; // Update button text + processMonitor.StartPause(); } public void setTime(int minutes, int seconds) @@ -156,12 +171,24 @@ namespace InnoLabProjektDektopApp { if (step < 0) { - stopTimer(); + if(isBreakPeriod) + { + isBreakPeriod = false; // Zurück zum Fokus + seconds = maxTime; // Zeit für die Fokusperiode + currentSession++; // Gehe zum nächsten Zyklus + processMonitor.EndBreak(); + PlayPauseButton.Content = "Pause"; + } + else + { + stopTimer(); + } } else { startTimer(); } + } @@ -269,9 +296,8 @@ namespace InnoLabProjektDektopApp MessageBox.Show($"Abbruchgrund: {selectedReason}", "Sitzung beendet", MessageBoxButton.OK, MessageBoxImage.Information); reasonWindow.Close(); - - this.NavigationService.Navigate(new Overview()); - + var jsonpath = processMonitor.FinishSession(); + this.NavigationService.Navigate(new SessionStatistics(jsonpath)); }; // Radiobuttons und Button zum StackPanel hinzufügen diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/Mascott.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/Mascott.xaml.cs index 2df52b358db1bed7cd9e3e6aa7305585e07acd40..c7269fcb1dbd32e227191ce781284c121a4f1942 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/Mascott.xaml.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/Mascott.xaml.cs @@ -60,29 +60,24 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer private void animationTick(object state) { - if (!processMonitor.isMonitoring) processMonitor.StartMonitoring(); Application.Current.Dispatcher.Invoke(() => { DateTime timeLeft = Overview.getSessionInstance().timeLeft(); - int processMonitorStage = processMonitor.CalculateCurrentDistractionStage(timeLeft); //processMonitor.CalculateCurrentDistractionStage(timeLeft); - /* */ + int processMonitorStage = processMonitor.CalculateCurrentDistractionStage(DateTime.Now); if (processMonitorStage == oldDistractionStage) { Counterxd.Text = "x: " + processMonitorStage.ToString(); return; - } - - if (processMonitorStage < oldDistractionStage) { + } else if (processMonitorStage < oldDistractionStage) { emotionDown_(); Counterxd.Text = "d: " + processMonitorStage.ToString(); } else if(processMonitorStage > oldDistractionStage) { emotionUp_(); Counterxd.Text = "u: " + processMonitorStage.ToString(); } - oldDistractionStage = processMonitorStage; }); } @@ -199,7 +194,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - processMonitor.StopMonitoring(); + // processMonitor.FinishSession(); } } } diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml index e34880c5acd074153d7621e36d3588050b276abb..53372509559e15fed620f16cb9e318274a10e010 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml @@ -19,8 +19,8 @@ <Canvas Name="chartCanvas" Margin="50" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Grid Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="350" Height="350"> - <lvc:PieChart Series="{Binding Series}" /> <Image Source="{Binding CenterImageSource}" Width="200" Height="200" HorizontalAlignment="Center" VerticalAlignment="Center"/> + <lvc:PieChart Series="{Binding Series}" /> </Grid> </Grid> </Page> diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml.cs index ddf76753a6b810c614bf33b0df81f1aa800c1ce6..26c1e9b3172c44d7ef8fa1a689b5eac8a934e8b3 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Screens/Regulaer/SessionStatistics.xaml.cs @@ -284,7 +284,7 @@ namespace InnoLabProjektDektopApp.Screens.Regulaer { new PieSeries<double> { Name = $"Distractions:", - Values = distractedTime.TotalMinutes > 0 ? [distractedTime.TotalMinutes] : new List<double>(), + Values = distractedTime.TotalSeconds > 1 ? [distractedTime.TotalMinutes] : new List<double>(), MaxRadialColumnWidth = 50, Fill = new SolidColorPaint(SKColors.Red), ToolTipLabelFormatter = value => $"{distractedTimeFormatted} minutes" diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs index cbd2baa312e4b89d238bd0a308d3efcbf65a6dc8..6dd8ec06ceea6df125283cfaa8282fcfa999ef30 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs @@ -40,6 +40,11 @@ namespace InnoLabProjektDektopApp.Services private DateTime breakStartTime; public int currentCycle = 1; + public event EventHandler MonitorCycleStarted; + public event EventHandler MonitorPaused; + public event EventHandler MonitorResumed; + public event EventHandler MonitorBreakStarted; + public ProcessMonitor() { IsBreak = false; @@ -55,6 +60,7 @@ namespace InnoLabProjektDektopApp.Services } if (cycleStartTimeList.Count == 0) { + MonitorCycleStarted?.Invoke(this, EventArgs.Empty); cycleStartTimeList[1] = DateTime.Now; } Debug.WriteLine("Started Process Monitoring"); @@ -116,6 +122,7 @@ namespace InnoLabProjektDektopApp.Services IsBreak = true; breakStartTime = DateTime.Now; StopMonitoring(); + MonitorBreakStarted?.Invoke(this, EventArgs.Empty); } public void EndBreak() @@ -129,6 +136,7 @@ namespace InnoLabProjektDektopApp.Services StartMonitoring(); currentCycle++; cycleStartTimeList[currentCycle] = DateTime.Now; + MonitorCycleStarted?.Invoke(this, EventArgs.Empty); } public void StartPause() @@ -140,6 +148,7 @@ namespace InnoLabProjektDektopApp.Services IsPause = true; breakStartTime = DateTime.Now; StopMonitoring(); + MonitorPaused?.Invoke(this, EventArgs.Empty); } public void EndPause() @@ -151,6 +160,7 @@ namespace InnoLabProjektDektopApp.Services breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now, IsBreak, currentCycle)); IsPause = false; StartMonitoring(); + MonitorResumed?.Invoke(this, EventArgs.Empty); } public string FinishSession() @@ -382,7 +392,14 @@ namespace InnoLabProjektDektopApp.Services public static List<(DateTime Start, DateTime End)> MergeIntervals(List<(DateTime Start, DateTime End)> intervals) { - var mergedIntervals = new List<(DateTime Start, DateTime End)> { intervals[0] }; + // return a list that includes DateTime.now to DateTime.now to prevent the stage from being 0 + if (intervals.Count == 0) + { + return [(DateTime.Now, DateTime.Now)]; + } + var mergedIntervals = new List<(DateTime Start, DateTime End)> { + intervals[0] + }; foreach (var interval in intervals.Skip(1)) { var last = mergedIntervals.Last(); diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/NotifyIconManager.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/NotifyIconManager.cs index de15c3ce805fafade8dce62c4fe2762d19210644..3a06ec8cf3ebc85a000f03a69646803c4a76fcab 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/NotifyIconManager.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Utils/NotifyIconManager.cs @@ -45,6 +45,12 @@ namespace InnoLabProjektDektopApp.Utils _countdownTimer.Interval = TimeSpan.FromSeconds(1); _countdownTimer.Tick += CountdownTimer_Tick; + // Subscribe to the events of the process monitor + _processMonitor.MonitorCycleStarted += HandleMonitorCycleStarted; + _processMonitor.MonitorPaused += HandleMonitorPaused; + _processMonitor.MonitorResumed += HandleMonitorResumed; + _processMonitor.MonitorBreakStarted += HandleMonitorBreakStarted; + RerenderContextMenu(); } @@ -71,7 +77,6 @@ namespace InnoLabProjektDektopApp.Utils { _notifyIcon.ContextMenuStrip.Items.Add("Pause", Drawing.Image.FromFile("Assets/pause.png"), (sender, args) => { - _countdownTimer.Stop(); _processMonitor.StartPause(); RerenderContextMenu(true); }); @@ -80,7 +85,6 @@ namespace InnoLabProjektDektopApp.Utils { _notifyIcon.ContextMenuStrip.Items.Add("Continue", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) => { - _countdownTimer.Start(); _processMonitor.EndPause(); RerenderContextMenu(true); }); @@ -114,19 +118,18 @@ namespace InnoLabProjektDektopApp.Utils $"Focus Duration: {_settings.focusPeriod} min | Break Duration: {_settings.breakPeriod} min | Cycles: {_settings.cycles}", null, false)); _notifyIcon.ContextMenuStrip.Items.Add("Start Session", Drawing.Image.FromFile("Assets/start.png"), (sender, args) => { - _processMonitor.StartMonitoring(); - StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod)); RerenderContextMenu(true); Window mainWindow = Application.Current.MainWindow; NavigationService mainNavigation = ((System.Windows.Navigation.NavigationWindow)mainWindow).NavigationService; - mainNavigation.Navigate( - new Session(_settings.focusPeriod, + Session tmpSession = new(_settings.focusPeriod, _settings.breakPeriod, _settings.cycles, _settings.distractionMode, _settings.mascotVisible, _settings.wordsOfAffirmation, - _settings.insultingWords)); + _settings.insultingWords); + Overview.SetSessionInstance(tmpSession); + mainNavigation.Navigate(tmpSession); }); } @@ -138,6 +141,26 @@ namespace InnoLabProjektDektopApp.Utils } } + private void HandleMonitorCycleStarted(object sender, EventArgs e) + { + StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod)); + } + + private void HandleMonitorPaused(object sender, EventArgs e) + { + _countdownTimer.Stop(); + } + + private void HandleMonitorResumed(object sender, EventArgs e) + { + _countdownTimer.Start(); + } + + private void HandleMonitorBreakStarted(object sender, EventArgs e) + { + StartCountdown(TimeSpan.FromMinutes(_settings.breakPeriod)); + } + private void NotifyIcon_MouseClick(object sender, Forms.MouseEventArgs e) { if (e.Button == Forms.MouseButtons.Left) @@ -182,7 +205,6 @@ namespace InnoLabProjektDektopApp.Utils if (_processMonitor.IsBreak) { _processMonitor.EndBreak(); - StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod)); RerenderContextMenu(); } else @@ -190,7 +212,6 @@ namespace InnoLabProjektDektopApp.Utils if (_processMonitor.currentCycle < _settings.cycles) { _processMonitor.StartBreak(); - StartCountdown(TimeSpan.FromMinutes(_settings.breakPeriod)); RerenderContextMenu(); } else @@ -233,6 +254,5 @@ namespace InnoLabProjektDektopApp.Utils } } } - } } \ No newline at end of file