Merge dependencies

This commit is contained in:
Andrei Zavatski 2019-09-27 19:00:17 +03:00
parent 5405102393
commit 2a395956aa
8 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,58 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Game.Utils;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneMetricNumbers : OsuTestScene
{
public TestSceneMetricNumbers()
{
Child = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new DrawableNumber(0),
new DrawableNumber(1001),
new DrawableNumber(999_999),
new DrawableNumber(1_000_000),
new DrawableNumber(845_006_456),
new DrawableNumber(999_999_999),
new DrawableNumber(1_000_000_000),
new DrawableNumber(7_875_454_545),
new DrawableNumber(999_999_999_999),
new DrawableNumber(1_000_000_000_000),
new DrawableNumber(687_545_454_554_545),
new DrawableNumber(999_999_999_999_999),
new DrawableNumber(1_000_000_000_000_000),
new DrawableNumber(587_545_454_554_545_455),
new DrawableNumber(999_999_999_999_999_999),
new DrawableNumber(1_000_000_000_000_000_000),
new DrawableNumber(long.MaxValue),
}
};
}
private class DrawableNumber : SpriteText, IHasTooltip
{
public string TooltipText => value.ToString("F0");
private readonly long value;
public DrawableNumber(long value)
{
this.value = value;
Text = HumanizerUtils.ToMetric(value);
}
}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests
{
public class GetCountryRankingsRequest : GetRankingsRequest<APICountryRankings>
{
public GetCountryRankingsRequest(RulesetInfo ruleset, int page = 1)
: base(ruleset, page)
{
}
protected override string TargetPostfix() => "country";
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.IO.Network;
using osu.Game.Rulesets;
using System.Collections.Generic;
namespace osu.Game.Online.API.Requests
{
public abstract class GetRankingsRequest<TModel> : APIRequest<List<TModel>>
{
private readonly RulesetInfo ruleset;
private readonly int page;
protected GetRankingsRequest(RulesetInfo ruleset, int page = 1)
{
this.ruleset = ruleset;
this.page = page;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("page", page.ToString());
return req;
}
protected override string Target => $"rankings/{ruleset.ShortName}/{TargetPostfix()}";
protected abstract string TargetPostfix();
}
}

View File

@ -0,0 +1,40 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.IO.Network;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests
{
public class GetUserRankingsRequest : GetRankingsRequest<APIUserRankings>
{
private readonly string country;
private readonly UserRankingsType type;
public GetUserRankingsRequest(RulesetInfo ruleset, UserRankingsType type = UserRankingsType.Performance, int page = 1, string country = null)
: base(ruleset, page)
{
this.type = type;
this.country = country;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
if (country != null)
req.AddParameter("country", country);
return req;
}
protected override string TargetPostfix() => type.ToString().ToLowerInvariant();
}
public enum UserRankingsType
{
Performance,
Score
}
}

View File

@ -0,0 +1,14 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
using osu.Game.Users;
namespace osu.Game.Online.API.Requests.Responses
{
public class APICountryRankings : CountryStatistics
{
[JsonProperty]
public Country Country;
}
}

View File

@ -0,0 +1,14 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
using osu.Game.Users;
namespace osu.Game.Online.API.Requests.Responses
{
public class APIUserRankings : UserStatistics
{
[JsonProperty]
public User User;
}
}

View File

@ -0,0 +1,25 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
namespace osu.Game.Users
{
public class CountryStatistics
{
[JsonProperty(@"code")]
public string FlagName;
[JsonProperty(@"active_users")]
public long ActiveUsers;
[JsonProperty(@"play_count")]
public long PlayCount;
[JsonProperty(@"ranked_score")]
public long RankedScore;
[JsonProperty(@"performance")]
public long Performance;
}
}

View File

@ -26,5 +26,32 @@ namespace osu.Game.Utils
return input.Humanize(culture: new CultureInfo("en-US"));
}
}
/// <summary>
/// Turns the current or provided big number into a readable string.
/// </summary>
/// <param name="input">The number to be humanized.</param>
/// <returns>Simplified number with a suffix.</returns>
public static string ToMetric(long input)
{
const int k = 1000;
if (input < k)
return input.ToString();
int i = (int)Math.Floor(Math.Round(Math.Log(input, k)));
return $"{input / Math.Pow(k, i):F} {suffixes[i]}";
}
private static readonly string[] suffixes = new[]
{
"",
"k",
"million",
"billion",
"trillion",
"quadrillion",
"quintillion",
};
}
}