mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:52:55 +08:00
Decouple rankings table test from online API
This commit is contained in:
parent
dcbeca2407
commit
82d6639a3b
@ -1,38 +1,27 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays.Rankings.Tables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Rulesets;
|
||||
using System.Threading;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Mania;
|
||||
using osu.Game.Rulesets.Taiko;
|
||||
using osu.Game.Rulesets.Catch;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Rankings;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public class TestSceneRankingsTables : OsuTestScene
|
||||
{
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
||||
|
||||
private readonly BasicScrollContainer scrollFlow;
|
||||
private readonly LoadingLayer loading;
|
||||
private CancellationTokenSource cancellationToken;
|
||||
private APIRequest request;
|
||||
|
||||
public TestSceneRankingsTables()
|
||||
{
|
||||
@ -53,73 +42,120 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AddStep("Osu performance", () => createPerformanceTable(new OsuRuleset().RulesetInfo, null));
|
||||
AddStep("Mania scores", () => createScoreTable(new ManiaRuleset().RulesetInfo));
|
||||
AddStep("Taiko country scores", () => createCountryTable(new TaikoRuleset().RulesetInfo));
|
||||
AddStep("Catch US performance page 10", () => createPerformanceTable(new CatchRuleset().RulesetInfo, "US", 10));
|
||||
AddStep("Osu spotlight table (chart 271)", () => createSpotlightTable(new OsuRuleset().RulesetInfo, 271));
|
||||
AddStep("User performance", createPerformanceTable);
|
||||
AddStep("User scores", createScoreTable);
|
||||
AddStep("Country scores", createCountryTable);
|
||||
}
|
||||
|
||||
private void createCountryTable(RulesetInfo ruleset, int page = 1)
|
||||
private void createCountryTable()
|
||||
{
|
||||
onLoadStarted();
|
||||
|
||||
request = new GetCountryRankingsRequest(ruleset, page);
|
||||
((GetCountryRankingsRequest)request).Success += rankings => Schedule(() =>
|
||||
var countries = new List<CountryStatistics>
|
||||
{
|
||||
var table = new CountriesTable(page, rankings.Countries);
|
||||
loadTable(table);
|
||||
});
|
||||
new CountryStatistics
|
||||
{
|
||||
Country = new Country { FlagName = "US", FullName = "United States" },
|
||||
FlagName = "US",
|
||||
ActiveUsers = 2_972_623,
|
||||
PlayCount = 3_086_515_743,
|
||||
RankedScore = 449_407_643_332_546,
|
||||
Performance = 371_974_024
|
||||
},
|
||||
new CountryStatistics
|
||||
{
|
||||
Country = new Country { FlagName = "RU", FullName = "Russian Federation" },
|
||||
FlagName = "RU",
|
||||
ActiveUsers = 1_609_989,
|
||||
PlayCount = 1_637_052_841,
|
||||
RankedScore = 221_660_827_473_004,
|
||||
Performance = 163_426_476
|
||||
}
|
||||
};
|
||||
|
||||
api.Queue(request);
|
||||
var table = new CountriesTable(1, countries);
|
||||
loadTable(table);
|
||||
}
|
||||
|
||||
private void createPerformanceTable(RulesetInfo ruleset, string country, int page = 1)
|
||||
private static List<UserStatistics> createUserStatistics() => new List<UserStatistics>
|
||||
{
|
||||
new UserStatistics
|
||||
{
|
||||
User = new APIUser
|
||||
{
|
||||
Username = "first active user",
|
||||
Country = new Country { FlagName = "JP" },
|
||||
Active = true,
|
||||
},
|
||||
Accuracy = 0.9972,
|
||||
PlayCount = 233_215,
|
||||
TotalScore = 983_231_234_656,
|
||||
RankedScore = 593_231_345_897,
|
||||
PP = 23_934,
|
||||
GradesCount = new UserStatistics.Grades
|
||||
{
|
||||
SS = 35_132,
|
||||
S = 23_345,
|
||||
A = 12_234
|
||||
}
|
||||
},
|
||||
new UserStatistics
|
||||
{
|
||||
User = new APIUser
|
||||
{
|
||||
Username = "inactive user",
|
||||
Country = new Country { FlagName = "AU" },
|
||||
Active = false,
|
||||
},
|
||||
Accuracy = 0.9831,
|
||||
PlayCount = 195_342,
|
||||
TotalScore = 683_231_234_656,
|
||||
RankedScore = 393_231_345_897,
|
||||
PP = 20_934,
|
||||
GradesCount = new UserStatistics.Grades
|
||||
{
|
||||
SS = 32_132,
|
||||
S = 20_345,
|
||||
A = 9_234
|
||||
}
|
||||
},
|
||||
new UserStatistics
|
||||
{
|
||||
User = new APIUser
|
||||
{
|
||||
Username = "second active user",
|
||||
Country = new Country { FlagName = "PL" },
|
||||
Active = true,
|
||||
},
|
||||
Accuracy = 0.9584,
|
||||
PlayCount = 100_903,
|
||||
TotalScore = 97_242_983_434,
|
||||
RankedScore = 3_156_345_897,
|
||||
PP = 9_568,
|
||||
GradesCount = new UserStatistics.Grades
|
||||
{
|
||||
SS = 13_152,
|
||||
S = 24_375,
|
||||
A = 9_960
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
private void createPerformanceTable()
|
||||
{
|
||||
onLoadStarted();
|
||||
|
||||
request = new GetUserRankingsRequest(ruleset, country: country, page: page);
|
||||
((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
|
||||
{
|
||||
var table = new PerformanceTable(page, rankings.Users);
|
||||
loadTable(table);
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
loadTable(new PerformanceTable(1, createUserStatistics()));
|
||||
}
|
||||
|
||||
private void createScoreTable(RulesetInfo ruleset, int page = 1)
|
||||
private void createScoreTable()
|
||||
{
|
||||
onLoadStarted();
|
||||
|
||||
request = new GetUserRankingsRequest(ruleset, UserRankingsType.Score, page);
|
||||
((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
|
||||
{
|
||||
var table = new ScoresTable(page, rankings.Users);
|
||||
loadTable(table);
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
}
|
||||
|
||||
private void createSpotlightTable(RulesetInfo ruleset, int spotlight)
|
||||
{
|
||||
onLoadStarted();
|
||||
|
||||
request = new GetSpotlightRankingsRequest(ruleset, spotlight, RankingsSortCriteria.All);
|
||||
((GetSpotlightRankingsRequest)request).Success += rankings => Schedule(() =>
|
||||
{
|
||||
var table = new ScoresTable(1, rankings.Users);
|
||||
loadTable(table);
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
loadTable(new ScoresTable(1, createUserStatistics()));
|
||||
}
|
||||
|
||||
private void onLoadStarted()
|
||||
{
|
||||
loading.Show();
|
||||
request?.Cancel();
|
||||
cancellationToken?.Cancel();
|
||||
cancellationToken = new CancellationTokenSource();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user