Add StatisticsController, add /planetStats

This commit is contained in:
jvyden 2021-10-29 19:00:50 -04:00
commit 30e5d4e3b5
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 39 additions and 10 deletions

View file

@ -74,15 +74,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
return this.Ok("[{\"StatusCode\":200}]");
}
[HttpGet("playersInPodCount")]
[HttpGet("totalPlayerCount")]
public async Task<IActionResult> TotalPlayerCount() {
int recentMatches = await this.database.LastMatches
.Where(l => TimestampHelper.Timestamp - l.Timestamp < 60)
.CountAsync();
return this.Ok(recentMatches.ToString());
}
}
}

View file

@ -0,0 +1,39 @@
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class StatisticsController : ControllerBase {
private readonly Database database;
public StatisticsController(Database database) {
this.database = database;
}
[HttpGet("playersInPodCount")]
[HttpGet("totalPlayerCount")]
public async Task<IActionResult> TotalPlayerCount() {
int recentMatches = await this.database.LastMatches
.Where(l => TimestampHelper.Timestamp - l.Timestamp < 60)
.CountAsync();
return this.Ok(recentMatches.ToString());
}
[HttpGet("planetStats")]
public async Task<IActionResult> PlanetStats() {
int totalSlotCount = await this.database.Slots.CountAsync();
const int mmPicksCount = 0;
return this.Ok(LbpSerializer.StringElement("planetStats",
LbpSerializer.StringElement("totalSlotCount", totalSlotCount) +
LbpSerializer.StringElement("mmPicksCount", mmPicksCount)
));
}
}
}