public async Task BuildDocumentationAsync() { string docuHTML = DocumentationBuilder.BuildDocumentation(commandService, DocumentationOutputTypes.HTML); string fileHTML = Path.Combine(AppContext.BaseDirectory, "documentation.html"); await MonkeyHelpers.WriteTextAsync(fileHTML, docuHTML).ConfigureAwait(false); string docuMD = DocumentationBuilder.BuildDocumentation(commandService, DocumentationOutputTypes.MarkDown); string fileMD = Path.Combine(AppContext.BaseDirectory, "documentation.md"); await MonkeyHelpers.WriteTextAsync(fileMD, docuMD).ConfigureAwait(false); }
protected static async Task <string> GenerateHistoryChartAsync(GameServer discordGameServer, int currentPlayers, int maxPlayers) { string id = discordGameServer.ServerIP.ToString().Replace(".", "_").Replace(":", "_"); var historyPeriod = TimeSpan.FromMinutes(90); const string folder = "Gameservers"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string baseFilePath = Path.Combine(folder, id); string storedValuesPath = $"{baseFilePath}.txt"; DateTime now = DateTime.Now; DateTime minTime = now.Subtract(historyPeriod); var historicData = new List <HistoricData <int> >(); if (File.Exists(storedValuesPath)) { string json = await MonkeyHelpers.ReadTextAsync(storedValuesPath); List <HistoricData <int> > loadedData = JsonSerializer.Deserialize <List <HistoricData <int> > >(json); historicData = loadedData .Where(x => x.Time > minTime) .ToList(); } historicData.Add(new HistoricData <int>(now, Math.Min(currentPlayers, maxPlayers))); await MonkeyHelpers.WriteTextAsync(storedValuesPath, JsonSerializer.Serialize(historicData, new JsonSerializerOptions() { WriteIndented = true })) ; int maxIntervals = 10; int interval = 10; for (int i = (int)Math.Ceiling(1.0 * maxPlayers / maxIntervals); i < 10; i++) { if (maxPlayers % i == 0) { interval = i; break; } } List <int> roundedPlayerCounts = Enumerable .Range(0, 10) .Reverse() .Select(mins => now.Subtract(TimeSpan.FromMinutes(mins * 10))) // Last 90 minutes .Select(t => historicData.FirstOrDefault(hd => Math.Abs(hd.Time.Subtract(t).TotalMinutes) < 1)?.Value ?? 0) .Select(v => (int)Math.Round(v / (1.0 * interval))) .ToList(); //Bottom up var lines = new List <string> { " minutes ago", " 0┊0┊0┊0┊0┊0┊0┊0┊0┊0", " 9┊8┊7┊6┊5┊4┊3┊2┊1┊0" }; int maxI = maxPlayers / interval; for (int i = 0; i <= maxI; i++) { string line = $"{i * interval,2}"; line += i == 0 ? "┴" : i == maxI ? "┐" : "┤"; string joinChar = i == 0 ? "┼" : i == maxI ? "┬" : "┊"; line += string.Join(joinChar, Enumerable .Range(0, 10) .Select(n => roundedPlayerCounts[n]) .Select(cnt => (i, cnt) switch { (0, 0) => "─", (_, 0) => " ", (0, _) => "╨", var(ii, c) when ii < c => "║", var(ii, c) when ii == c => "╥", _ => " " })