/// <summary> /// /// </summary> void GenerateDataLIsts() { // ************** Systems Inf Graph data **************** DEPerformance.Clear(); foreach (var sys in _deSystems) { factionPerformance fp = new factionPerformance(); fp.StarSystem = sys.StarSystem; fp.DEInf = new List <DEInfHistory>(); foreach (var histRec in sys.FactionHistory) { DEInfHistory dh = new DEInfHistory(); // Create new record dh.Date = histRec.timestamp.Date; dh.DarkEchoInf = histRec.Factions[histRec.Factions.FindIndex(y => y.Name == Helper.FactionName)].Influence * 100; fp.DEInf.Add(dh); } DEPerformance.Add(fp); } // *************** Average Influence ******************** avgDEInf.Clear(); foreach (var sys in _deSystems) { foreach (var histRec in sys.FactionHistory) { AvgInf ai = new AvgInf(); ai.date = histRec.timestamp.Date; ai.starSystem = sys.StarSystem; var index = histRec.Factions.FindIndex(f => f.Name == Helper.FactionName); ai.deInf = histRec.Factions[index].Influence; avgDEInf.Add(ai); } } var result = avgDEInf .GroupBy(d => d.date) .Select(g => new { InfDate = g.Key, TotalInf = g.Sum(d => d.deInf), systems = g.Count() }).ToList(); foreach (var r in result) { TheResults tr = new TheResults(); tr.InfDate = r.InfDate; tr.TotalInf = ((r.TotalInf * 100) / r.systems); theResults.Add(tr); } theResults.Sort((x, y) => x.InfDate.CompareTo(y.InfDate)); }
private static void CafeBabeGame_GameEnded(object sender, DeadBeefCafeGameEndedEventArgs e) { if (e != null) { using var lck = TheResults.Lock(); if (lck.Value != default) { throw new Exception("Duplicate results!"); } if (e.Results != default) { lck.Value = e; } } }
private static Result?WaitForGameEndOrTimeout(TimeSpan maxWait) { maxWait = (maxWait <= TimeSpan.Zero) ? TimeSpan.FromSeconds(1) : maxWait; DateTime startedAt = TimeStampSource.Now; TimeSpan elapsed = TimeStampSource.Now - startedAt; Result res = default; while (res == default && elapsed <= maxWait) { try { using var lck = TheResults.Lock(); res = lck.Value; lck.Value = default; } catch (TimeoutException) { Console.Error.WriteLineAsync("Attempt to get results lock timed out."); } if (res == null) { Thread.Sleep(TimeSpan.FromMilliseconds(10)); elapsed = TimeStampSource.Now - startedAt; } } if (res == default) { Debug.Assert(elapsed > maxWait); Console.Error.WriteLineAsync( "Game did not terminate within time limit. " + $"Time limit: {maxWait.TotalMilliseconds:F3} milliseconds; Elapsed time: {elapsed.TotalMilliseconds:F3} milliseconds. " + "Consider increasing the time limit."); } return(res); }