diff --git a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs index 0d3b8047f94fca78efee8c72e7b278514aadbeb1..731269595d516603cc74b964ecddb3c42efe0411 100644 --- a/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs +++ b/InnoLabProjektDektopApp/InnoLabProjektDektopApp/Services/ProcessMonitor.cs @@ -58,10 +58,14 @@ namespace InnoLabProjektDektopApp.Services public void CalculateCurrentDistractionStage(DateTime endTime) { + TimeSpan totalDistractionTime = CalculateTotalDistractionTime(); Debug.WriteLine("Total distraction time: {0}", totalDistractionTime); - double totalMinutes = (endTime - startTime).TotalMinutes; - double distractedMinutes = totalDistractionTime.TotalMinutes; + + // Adds a dummy value to the distractedMinutes and totalMinutes so the stage starts in the middle + double dummyTimeInMinutes = 8; + double totalMinutes = (endTime - startTime).TotalMinutes + 2 * dummyTimeInMinutes; + double distractedMinutes = totalDistractionTime.TotalMinutes + dummyTimeInMinutes; double distractionFraction = (distractedMinutes / totalMinutes); int stage = (int)Math.Ceiling(distractionFraction * 7); Debug.WriteLine($"Distraction stage: {stage}"); @@ -71,10 +75,8 @@ namespace InnoLabProjektDektopApp.Services { var processName = Path.GetFileNameWithoutExtension((string)((ManagementBaseObject)e["TargetInstance"])["Name"]); - if (processStartTimes.TryGetValue(processName, out _)) - { - return; - } + // Check if the process is already being tracked + if (processStartTimes.TryGetValue(processName, out _)) return; processStartTimes[processName] = DateTime.Now;