mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 14:53:01 +08:00
Add beatmap metrics lookup.
This commit is contained in:
parent
d6c5654924
commit
e1a2f1bc7a
@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -18,11 +19,13 @@ namespace osu.Game.Database
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Points of failure on a relative time scale (usually 0..100).
|
/// Points of failure on a relative time scale (usually 0..100).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonProperty(@"fail")]
|
||||||
public IEnumerable<int> Fails { get; set; }
|
public IEnumerable<int> Fails { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Points of retry on a relative time scale (usually 0..100).
|
/// Points of retry on a relative time scale (usually 0..100).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonProperty(@"exit")]
|
||||||
public IEnumerable<int> Retries { get; set; }
|
public IEnumerable<int> Retries { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
61
osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs
Normal file
61
osu.Game/Online/API/Requests/GetBeatmapDetailsRequest.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Rulesets.Scoring;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class GetBeatmapDeatilsRequest : APIRequest<GetBeatmapDeatilsResponse>
|
||||||
|
{
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
private string lookupString;
|
||||||
|
|
||||||
|
public GetBeatmapDeatilsRequest(BeatmapInfo beatmap)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
if (beatmap.OnlineBeatmapID > 0)
|
||||||
|
lookupString = beatmap.OnlineBeatmapID.ToString();
|
||||||
|
else
|
||||||
|
lookupString = $@"lookup?checksum={beatmap.Hash}&filename={beatmap.Path}";
|
||||||
|
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $@"beatmaps/{lookupString}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetBeatmapDeatilsResponse : BeatmapMetrics
|
||||||
|
{
|
||||||
|
//the online API returns some metrics as a nested object.
|
||||||
|
[JsonProperty(@"failtimes")]
|
||||||
|
private BeatmapMetrics failTimes
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.Fails = value.Fails;
|
||||||
|
this.Retries = value.Retries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//and other metrics in the beatmap set.
|
||||||
|
[JsonProperty(@"beatmapset")]
|
||||||
|
private BeatmapMetrics beatmapSet
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.Ratings = value.Ratings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
beatmap = value;
|
beatmap = value;
|
||||||
Leaderboard.Beatmap = beatmap?.BeatmapInfo;
|
Leaderboard.Beatmap = beatmap?.BeatmapInfo;
|
||||||
Details.Beatmap = beatmap?.Beatmap.BeatmapInfo;
|
Details.Beatmap = beatmap?.BeatmapInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Framework.Threading;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
{
|
{
|
||||||
@ -39,19 +43,23 @@ namespace osu.Game.Screens.Select
|
|||||||
private readonly BarGraph retryGraph;
|
private readonly BarGraph retryGraph;
|
||||||
private readonly BarGraph failGraph;
|
private readonly BarGraph failGraph;
|
||||||
|
|
||||||
|
private ScheduledDelegate pendingBeatmapSwitch;
|
||||||
private BeatmapInfo beatmap;
|
private BeatmapInfo beatmap;
|
||||||
|
|
||||||
public BeatmapInfo Beatmap
|
public BeatmapInfo Beatmap
|
||||||
{
|
{
|
||||||
get
|
get { return beatmap; }
|
||||||
{
|
|
||||||
return beatmap;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
beatmap = value;
|
beatmap = value;
|
||||||
|
|
||||||
if (beatmap == null) return;
|
pendingBeatmapSwitch?.Cancel();
|
||||||
|
pendingBeatmapSwitch = Schedule(updateStats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStats()
|
||||||
|
{
|
||||||
description.Text = beatmap.Version;
|
description.Text = beatmap.Version;
|
||||||
source.Text = beatmap.Metadata.Source;
|
source.Text = beatmap.Metadata.Source;
|
||||||
tags.Text = beatmap.Metadata.Tags;
|
tags.Text = beatmap.Metadata.Tags;
|
||||||
@ -62,9 +70,35 @@ namespace osu.Game.Screens.Select
|
|||||||
approachRate.Value = beatmap.Difficulty.ApproachRate;
|
approachRate.Value = beatmap.Difficulty.ApproachRate;
|
||||||
stars.Value = (float)beatmap.StarDifficulty;
|
stars.Value = (float)beatmap.StarDifficulty;
|
||||||
|
|
||||||
if (beatmap.Metrics?.Ratings.Any() ?? false)
|
var requestedBeatmap = beatmap;
|
||||||
|
if (requestedBeatmap.Metrics == null)
|
||||||
{
|
{
|
||||||
var ratings = beatmap.Metrics.Ratings.ToList();
|
var lookup = new GetBeatmapDeatilsRequest(requestedBeatmap);
|
||||||
|
lookup.Success += res =>
|
||||||
|
{
|
||||||
|
if (beatmap != requestedBeatmap)
|
||||||
|
//the beatmap has been changed since we started the lookup.
|
||||||
|
return;
|
||||||
|
|
||||||
|
requestedBeatmap.Metrics = res;
|
||||||
|
Schedule(() => updateMetrics(res, true));
|
||||||
|
};
|
||||||
|
lookup.Failure += e => updateMetrics(null, true);
|
||||||
|
|
||||||
|
api.Queue(lookup);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMetrics(requestedBeatmap.Metrics, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMetrics(BeatmapMetrics metrics, bool failOnMissing = true)
|
||||||
|
{
|
||||||
|
var hasRatings = metrics?.Ratings.Any() ?? false;
|
||||||
|
var hasRetriesFails = (metrics?.Retries.Any() ?? false) && metrics.Fails.Any();
|
||||||
|
|
||||||
|
if (hasRatings)
|
||||||
|
{
|
||||||
|
var ratings = metrics.Ratings.ToList();
|
||||||
ratingsContainer.Show();
|
ratingsContainer.Show();
|
||||||
|
|
||||||
negativeRatings.Text = ratings.GetRange(0, ratings.Count / 2).Sum().ToString();
|
negativeRatings.Text = ratings.GetRange(0, ratings.Count / 2).Sum().ToString();
|
||||||
@ -72,14 +106,18 @@ namespace osu.Game.Screens.Select
|
|||||||
ratingsBar.Length = (float)ratings.GetRange(0, ratings.Count / 2).Sum() / ratings.Sum();
|
ratingsBar.Length = (float)ratings.GetRange(0, ratings.Count / 2).Sum() / ratings.Sum();
|
||||||
|
|
||||||
ratingsGraph.Values = ratings.Select(rating => (float)rating);
|
ratingsGraph.Values = ratings.Select(rating => (float)rating);
|
||||||
}
|
|
||||||
else
|
|
||||||
ratingsContainer.Hide();
|
|
||||||
|
|
||||||
if ((beatmap.Metrics?.Retries.Any() ?? false) && beatmap.Metrics.Fails.Any())
|
ratingsContainer.FadeColour(Color4.White, 500, EasingTypes.Out);
|
||||||
|
}
|
||||||
|
else if (failOnMissing)
|
||||||
|
ratingsGraph.Values = new float[10];
|
||||||
|
else
|
||||||
|
ratingsContainer.FadeColour(Color4.Gray, 500, EasingTypes.Out);
|
||||||
|
|
||||||
|
if (hasRetriesFails)
|
||||||
{
|
{
|
||||||
var retries = beatmap.Metrics.Retries;
|
var retries = metrics.Retries;
|
||||||
var fails = beatmap.Metrics.Fails;
|
var fails = metrics.Fails;
|
||||||
retryFailContainer.Show();
|
retryFailContainer.Show();
|
||||||
|
|
||||||
float maxValue = fails.Zip(retries, (fail, retry) => fail + retry).Max();
|
float maxValue = fails.Zip(retries, (fail, retry) => fail + retry).Max();
|
||||||
@ -88,10 +126,16 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
failGraph.Values = fails.Select(fail => (float)fail);
|
failGraph.Values = fails.Select(fail => (float)fail);
|
||||||
retryGraph.Values = retries.Zip(fails, (retry, fail) => retry + MathHelper.Clamp(fail, 0, maxValue));
|
retryGraph.Values = retries.Zip(fails, (retry, fail) => retry + MathHelper.Clamp(fail, 0, maxValue));
|
||||||
|
|
||||||
|
retryFailContainer.FadeColour(Color4.White, 500, EasingTypes.Out);
|
||||||
|
}
|
||||||
|
else if (failOnMissing)
|
||||||
|
{
|
||||||
|
failGraph.Values = new float[100];
|
||||||
|
retryGraph.Values = new float[100];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
retryFailContainer.Hide();
|
retryFailContainer.FadeColour(Color4.Gray, 500, EasingTypes.Out);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeatmapDetails()
|
public BeatmapDetails()
|
||||||
@ -272,9 +316,13 @@ namespace osu.Game.Screens.Select
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private APIAccess api;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colour)
|
private void load(OsuColour colour, APIAccess api)
|
||||||
{
|
{
|
||||||
|
this.api = api;
|
||||||
|
|
||||||
description.AccentColour = colour.GrayB;
|
description.AccentColour = colour.GrayB;
|
||||||
source.AccentColour = colour.GrayB;
|
source.AccentColour = colour.GrayB;
|
||||||
tags.AccentColour = colour.YellowLight;
|
tags.AccentColour = colour.YellowLight;
|
||||||
|
@ -179,6 +179,7 @@
|
|||||||
<Compile Include="Rulesets\UI\StandardHudOverlay.cs" />
|
<Compile Include="Rulesets\UI\StandardHudOverlay.cs" />
|
||||||
<Compile Include="Online\API\IOnlineComponent.cs" />
|
<Compile Include="Online\API\IOnlineComponent.cs" />
|
||||||
<Compile Include="Online\API\Requests\GetScoresRequest.cs" />
|
<Compile Include="Online\API\Requests\GetScoresRequest.cs" />
|
||||||
|
<Compile Include="Online\API\Requests\GetBeatmapDetailsRequest.cs" />
|
||||||
<Compile Include="Online\API\Requests\GetUserRequest.cs" />
|
<Compile Include="Online\API\Requests\GetUserRequest.cs" />
|
||||||
<Compile Include="Overlays\DragBar.cs" />
|
<Compile Include="Overlays\DragBar.cs" />
|
||||||
<Compile Include="Overlays\LoginOverlay.cs" />
|
<Compile Include="Overlays\LoginOverlay.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user