mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-23 15:41:26 +00:00
Make LBP2 lucky dip prefer newer levels and make player count more accurate (#744)
* Lucky Dip, Newest Levels, & Recently Played change * almost broke prod :disaster: * Update ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs I forgor lol Co-authored-by: koko <koko@drones.gay> * Remove TimestampMicros and add random slot selection with bias * playersInPod count filters by platform * Hope this actually commits now, idk github * Apply suggestions from code review Co-authored-by: Josh <josh@slendy.pw> * Update ProjectLighthouse.Servers.GameServer/Controllers/StatisticsController.cs Co-authored-by: Josh <josh@slendy.pw> * Fix random bias ordering --------- Co-authored-by: koko <joebiden@kitgaming67.com> Co-authored-by: koko <koko@drones.gay> Co-authored-by: Slendy <josh@slendy.pw>
This commit is contained in:
parent
d5f3db9201
commit
aefecc7b12
3 changed files with 7 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Security.Cryptography;
|
|
||||||
using LBPUnion.ProjectLighthouse.Configuration;
|
using LBPUnion.ProjectLighthouse.Configuration;
|
||||||
using LBPUnion.ProjectLighthouse.Database;
|
using LBPUnion.ProjectLighthouse.Database;
|
||||||
using LBPUnion.ProjectLighthouse.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
@ -146,7 +145,7 @@ public class SlotsController : ControllerBase
|
||||||
{
|
{
|
||||||
if (page != null) pageStart = (int)page * 30;
|
if (page != null) pageStart = (int)page * 30;
|
||||||
// bit of a better placeholder until we can track average user interaction with /stream endpoint
|
// bit of a better placeholder until we can track average user interaction with /stream endpoint
|
||||||
return await this.ThumbsSlots(pageStart, Math.Min(pageSize, 30), gameFilterType, players, move, "thisWeek");
|
return await this.ThumbsSlots(pageStart, Math.Min(pageSize, 30), gameFilterType, players, move, "thisMonth");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots")]
|
[HttpGet("slots")]
|
||||||
|
@ -160,6 +159,7 @@ public class SlotsController : ControllerBase
|
||||||
|
|
||||||
List<SlotBase> slots = (await this.database.Slots.ByGameVersion(gameVersion, false, true)
|
List<SlotBase> slots = (await this.database.Slots.ByGameVersion(gameVersion, false, true)
|
||||||
.OrderByDescending(s => s.FirstUploaded)
|
.OrderByDescending(s => s.FirstUploaded)
|
||||||
|
.ThenByDescending(s => s.SlotId)
|
||||||
.Skip(Math.Max(0, pageStart - 1))
|
.Skip(Math.Max(0, pageStart - 1))
|
||||||
.Take(Math.Min(pageSize, 30))
|
.Take(Math.Min(pageSize, 30))
|
||||||
.ToListAsync()).ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
|
.ToListAsync()).ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
|
||||||
|
@ -284,8 +284,9 @@ public class SlotsController : ControllerBase
|
||||||
|
|
||||||
GameVersion gameVersion = token.GameVersion;
|
GameVersion gameVersion = token.GameVersion;
|
||||||
|
|
||||||
|
const double biasFactor = .8f;
|
||||||
List<SlotBase> slots = (await this.database.Slots.ByGameVersion(gameVersion, false, true)
|
List<SlotBase> slots = (await this.database.Slots.ByGameVersion(gameVersion, false, true)
|
||||||
.OrderBy(_ => EF.Functions.Random())
|
.OrderByDescending(s => EF.Functions.Random() * (s.FirstUploaded * biasFactor))
|
||||||
.Take(Math.Min(pageSize, 30))
|
.Take(Math.Min(pageSize, 30))
|
||||||
.ToListAsync()).ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
|
.ToListAsync()).ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using LBPUnion.ProjectLighthouse.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ public class StatisticsController : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("playersInPodCount")]
|
[HttpGet("playersInPodCount")]
|
||||||
public IActionResult PlayersInPodCount() => this.Ok((StatisticsHelper.UserCountInPod(this.database)).ToString());
|
public IActionResult PlayersInPodCount() => this.Ok(StatisticsHelper.RoomCountForPlatform(this.GetToken().Platform).ToString());
|
||||||
|
|
||||||
[HttpGet("totalPlayerCount")]
|
[HttpGet("totalPlayerCount")]
|
||||||
public async Task<IActionResult> TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatchesForGame(this.database, this.GetToken().GameVersion)).ToString());
|
public async Task<IActionResult> TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatchesForGame(this.database, this.GetToken().GameVersion)).ToString());
|
||||||
|
|
|
@ -23,7 +23,7 @@ public static class StatisticsHelper
|
||||||
|
|
||||||
public static async Task<int> UserCount(DatabaseContext database) => await database.Users.CountAsync(u => u.PermissionLevel != PermissionLevel.Banned);
|
public static async Task<int> UserCount(DatabaseContext database) => await database.Users.CountAsync(u => u.PermissionLevel != PermissionLevel.Banned);
|
||||||
|
|
||||||
public static int UserCountInPod(DatabaseContext database) => RoomHelper.Rooms.Count(r => r.State == RoomState.Idle);
|
public static int RoomCountForPlatform(Platform targetPlatform) => RoomHelper.Rooms.Count(r => r.IsLookingForPlayers && r.RoomPlatform == targetPlatform);
|
||||||
|
|
||||||
public static async Task<int> TeamPickCount(DatabaseContext database) => await database.Slots.CountAsync(s => s.TeamPick);
|
public static async Task<int> TeamPickCount(DatabaseContext database) => await database.Slots.CountAsync(s => s.TeamPick);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue