public Beatmap(Input input) { if (input.BeatmapId == null) { throw new Exception("No beatmap link provided"); } Task <BeatmapData[]> beatmapRequest = OsuApi.Beatmap(input.BeatmapId, input.ModRequestNumber ?? 0, input.Gamemode); Task <ScoreData[]> leaderboardRequest = OsuApi.Leaderboard(input.BeatmapId, input.Gamemode); Task.WhenAll( beatmapRequest, leaderboardRequest ).Wait(); beatmap = beatmapRequest.Result[0]; leaderboard = leaderboardRequest.Result; CountLeaderboardFullCombo(); difficultyCalculator = new DifficultyCalculator(input.BeatmapId, input.Gamemode, input.ModNumber); difficulty = difficultyCalculator.Calculate(); Embed = CreateEmbed(); }
public DifficultyGraph(Input input, BeatmapData beatmap) { this.beatmap = beatmap; var difficultyCalculator = new DifficultyCalculator(input.BeatmapId, input.Gamemode, input.ModNumber); difficulty = difficultyCalculator.Calculate(); double maxDifficulty = (double)beatmap.DifficultyRating > difficulty.StrainPeakTotal.Max() ? (double)beatmap.DifficultyRating : difficulty.StrainPeakTotal.Max(); var webClient = new WebClient(); Image background = null; Graphics graphic = null; try { byte[] backgroundBytes = webClient.DownloadData($"https://assets.ppy.sh/beatmaps/{beatmap.BeatmapSetId}/covers/cover.jpg"); var backgroundStream = new MemoryStream(backgroundBytes); background = Image.FromStream(backgroundStream); graphic = Graphics.FromImage(background); } catch (Exception e) { } double[] dataX = CreateXRange(); var plt = new Plot(900, 250); plt.Axis(0, beatmap.TotalLength, 0, maxDifficulty + 0.5); plt.PlotScatter(dataX, difficulty.StrainPeakTotal, markerSize: 0, label: "Strain", lineWidth: 3, color: Color.DodgerBlue); plt.PlotScatter(dataX, difficulty.StrainPeakAim, markerShape: MarkerShape.none, label: "Aim", lineWidth: 1, color: Color.MediumAquamarine, lineStyle: LineStyle.Solid); plt.PlotScatter(dataX, difficulty.StrainPeakSpeed, markerShape: MarkerShape.none, label: "Speed", lineWidth: 1, color: Color.Firebrick); plt.Title($"{beatmap.Artist} - {beatmap.Title} [{beatmap.Version}]", fontSize: 24); plt.Ticks(displayTicksXminor: false, displayTicksYminor: false, fontSize: 16); plt.PlotHLine((double)beatmap.DifficultyRating, lineWidth: 1, label: "SR", color: Color.Gold); plt.Legend(location: legendLocation.upperLeft, fontSize: 10, fixedLineWidth: true, bold: true); plt.Style(figBg: Color.FromArgb(150, 35, 39, 42), dataBg: Color.FromArgb(150, 35, 39, 42), tick: Color.White, title: Color.White, label: Color.White); plt.Layout(xLabelHeight: 5, yLabelWidth: -10); if (graphic != null && background != null) { graphic.DrawImage(plt.GetBitmap(), new Point(0, 0)); Graph = background; } else { Graph = plt.GetBitmap(); } //background.Save("output.png", ImageFormat.Png); }