/// <summary> /// Reset the statistics. /// </summary> public void Reset() { ComplexPoints = 0; ComplexTime.Reset(); ComplexSolveTime.Reset(); ComplexLoadTime.Reset(); ComplexReorderTime.Reset(); ComplexDecompositionTime.Reset(); }
public static ComplexTime CalculateDifference(ComplexTime fewerTime, ComplexTime greaterTime) { if (fewerTime == null || greaterTime == null) { return(new ComplexTime()); } int?fewerHours = fewerTime.Hours; int?fewerMinutes = fewerTime.Minutes; int?fewerSeconds = fewerTime.Seconds; int?greaterHours = greaterTime.Hours; int?greaterMinutes = greaterTime.Minutes; int?greaterSeconds = greaterTime.Seconds; if (!fewerSeconds.HasValue || !fewerMinutes.HasValue || !fewerHours.HasValue || !greaterMinutes.HasValue || !greaterHours.HasValue || !greaterSeconds.HasValue) { return(new ComplexTime()); } var resultHours = greaterHours - fewerHours; int?resultMinutes; int?resultSeconds; if (greaterMinutes >= fewerMinutes) { resultMinutes = greaterMinutes - fewerMinutes; } else { resultHours -= 1; resultMinutes = 60 - Math.Abs(greaterMinutes.Value - fewerMinutes.Value); } if (greaterSeconds >= fewerSeconds) { resultSeconds = greaterSeconds - fewerSeconds; } else { if (resultMinutes > 0) { resultMinutes -= 1; } else { resultMinutes = 59; resultHours -= 1; } resultSeconds = 60 - Math.Abs(greaterSeconds.Value - fewerSeconds.Value); } return(new ComplexTime { Hours = resultHours, Minutes = resultMinutes, Seconds = resultSeconds }); //$"{resultHours:0}:{resultMinutes:00}:{resultSeconds:00}"; }
public static ComplexTime CalculateSum(ComplexTime time1, ComplexTime time2) { if (time1 == null || time2 == null) { return(null); } int?fewerHours = time1.Hours; int?fewerMinutes = time1.Minutes; int?fewerSeconds = time1.Seconds; int?greaterHours = time2.Hours; int?greaterMinutes = time2.Minutes; int?greaterSeconds = time2.Seconds; if (!fewerSeconds.HasValue || !fewerMinutes.HasValue || !fewerHours.HasValue || !greaterMinutes.HasValue || !greaterHours.HasValue || !greaterSeconds.HasValue) { return(null); } ComplexTime resultTime = new ComplexTime { Hours = 0, Minutes = 0, Seconds = 0 }; resultTime.Hours = time1.Hours + time2.Hours; var tempSec = time1.Seconds + time2.Seconds; if (tempSec > 59) { resultTime.Minutes += 1; resultTime.Seconds = tempSec - 60; } else { resultTime.Seconds = tempSec; } var tempMin = time1.Minutes + time2.Minutes + resultTime.Minutes; if (tempMin > 59) { resultTime.Hours += 1; resultTime.Minutes = tempMin - 60; } else { resultTime.Minutes = tempMin; } return(resultTime); }
private void Timer_Tick(object sender, EventArgs e) { if (Window == null) { LoadWindows(); return; } int size = GetWindowTextLength(Window.hwnd); if (size++ > 0 && IsWindowVisible(Window.hwnd)) { StringBuilder sb = new StringBuilder(size); GetWindowText(Window.hwnd, sb, size); var currentTime = Regex.Match(sb.ToString(), "([0-9]+\\s*:\\s*[0-9]+\\s*:\\s*[0-9]+)", RegexOptions.IgnoreCase).Value; if (string.IsNullOrEmpty(currentTime)) { currentTime = Regex.Match(sb.ToString(), "(Time\\s*\\[\\s*[0-9]\\s*\\]\\s*:\\s*[0-9]+)", RegexOptions.IgnoreCase).Value; } if (!string.IsNullOrEmpty(currentTime)) { GameTime = currentTime.Replace("Time", ""); var tempDeaths = Regex.Match(sb.ToString(), DeathsRegex, RegexOptions.IgnoreCase).Value; var temp = Regex.Match(tempDeaths, "\\[[0-9]\\]").Value; Deaths = !string.IsNullOrEmpty(temp) ? tempDeaths.Replace(temp, "") : tempDeaths; Deaths = Deaths.ToUpper() .Replace(" ", "") .Replace(":", "") .Replace("DEATHS", "") .Replace("DEATH", ""); string tempGameName = sb.ToString().Replace(currentTime, "").Replace(tempDeaths, ""); gameName = Regex.Replace(tempGameName, "[^A-Za-zА-Яа-я0-9 _.]", "_") + ".txt"; if (!File.Exists(folder + gameName)) { var fs = File.Create(folder + gameName); fs.Close(); Stats = new Stats { Values = new List <StatsValue>(), Parallels = new ObservableCollection <Parallels>() }; var json = Serializer.Serialize(Stats); File.WriteAllText(folder + gameName, json); } if (Stats == null) { var json = File.ReadAllText(folder + gameName); Stats = Serializer.Deserialize <Stats>(json); } var currentDeaths = GetDeaths(); foreach (var parallel in Stats.Parallels) // для ситуаций, когда текущее время меньше чем записаное в файл { if (parallel.OffTime > new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }) { parallel.OffTime = new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }; parallel.ElapsedTime = GTC.CalculateSum(GTC.CalculateDifference(parallel.BackTime, parallel.OffTime), parallel.ElapsedTime); } if (parallel.BackTime > new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }) { parallel.BackTime = new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }; } if (parallel.OffDeaths > currentDeaths) { parallel.OffDeaths = currentDeaths.Value; parallel.ElapsedDeaths = parallel.OffDeaths - parallel.BackDeaths + parallel.ElapsedDeaths; } if (parallel.BackDeaths > currentDeaths) { parallel.BackDeaths = currentDeaths.Value; } ParallelsVisibility = Visibility.Visible; } foreach (var statsValue in Stats.Values) { if (statsValue.Time > new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }) { statsValue.Time = new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }; } if (statsValue.Deaths.HasValue && statsValue.Deaths.Value > currentDeaths) { statsValue.Deaths = currentDeaths.Value; } } foreach (var parallel in Stats.Parallels) { if (Stats.Values.Last().Time > parallel.OffTime) { ParallelsVisibility = Visibility.Collapsed; } } if (Stats.SelectedParallel == null) { if (Stats.Values.Count == 0) { Current = $"Time: {GetHours():0}:{GetMinutes():00}:{GetSeconds():00}\nDeaths: {GetDeaths()}"; } else { var idk = GTC.CalculateDifference(Stats.Values.Last().Time, new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }); Current = $"Time: {idk.Hours:0}:{idk.Minutes:00}:{idk.Seconds:00}\nDeaths: {GetDeaths() - Stats.Values.Last().Deaths}"; } if (Stats.Values.Count == 0) { Last = ""; } else if (Stats.Values.Count == 1) { Last = $"Time: {Stats.Values.Last().Time.Hours}:{Stats.Values.Last().Time.Minutes}:{Stats.Values.Last().Time.Seconds}\nDeaths: {Stats.Values.Last().Deaths}"; } else { var idk = GTC.CalculateDifference(Stats.Values[Stats.Values.Count - 2].Time, Stats.Values.Last().Time); Last = $"Time:{idk.Hours:0}:{idk.Minutes:00}:{idk.Seconds:00}\nDeaths: {Stats.Values.Last().Deaths - Stats.Values[Stats.Values.Count - 2].Deaths}"; } } else { var currentParallel = Stats.Parallels.FirstOrDefault(i => i.ID.Equals(Stats.SelectedParallel)); if (!currentParallel.Cleared) { var timenow = new ComplexTime { Hours = GetHours(), Minutes = GetMinutes(), Seconds = GetSeconds() }; var idk = GTC.CalculateSum(GTC.CalculateDifference(currentParallel.BackTime, timenow), currentParallel.ElapsedTime); currentParallel.ElapsedTimeString = idk.Hours + ":" + idk.Minutes + ":" + idk.Seconds; var idk2 = currentDeaths - currentParallel.BackDeaths + currentParallel.ElapsedDeaths; currentParallel.ElapsedDeathsString = idk2.ToString(); } } } } else { Stats = null; LoadWindows(); } }