Stats Page Overhaul (#4292)

Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
Joe Milazzo
2025-12-19 13:23:55 -07:00
committed by GitHub
parent 20197fa712
commit e1f421ccc0
175 changed files with 12122 additions and 5746 deletions
@@ -372,6 +372,28 @@ public static class QueryableExtensions
};
}
/// <summary>
/// Filters a sequence to elements where the specified key falls within an inclusive range.
/// </summary>
/// <param name="keySelector">Expression to extract the comparable key</param>
/// <param name="start">Inclusive lower bound</param>
/// <param name="end">Inclusive upper bound</param>
public static IQueryable<T> Between<T>(
this IQueryable<T> source,
Expression<Func<T, DateTime>> keySelector,
DateTime start,
DateTime end)
{
var parameter = keySelector.Parameters[0];
var memberAccess = keySelector.Body;
var greaterOrEqual = Expression.GreaterThanOrEqual(memberAccess, Expression.Constant(start));
var lessOrEqual = Expression.LessThanOrEqual(memberAccess, Expression.Constant(end));
var combined = Expression.AndAlso(greaterOrEqual, lessOrEqual);
return source.Where(Expression.Lambda<Func<T, bool>>(combined, parameter));
}
public static IQueryable<FullAnnotationDto> OrderFullAnnotation(this IQueryable<FullAnnotationDto> query)
{
return query
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using API.Entities.Progress;
using Microsoft.EntityFrameworkCore;
namespace API.Extensions.QueryExtensions;
public class IdCount
{
public int Id { get; set; }
public int Count { get; set; }
}
/// <summary>
/// Extensions primarily focusing on Profile and Server Stats pages/queries
/// </summary>
public static class StatisticsQueryExtensions
{
public static async Task<List<IdCount>> GetTopCounts( this IQueryable<AppUserProgress> query, Expression<Func<AppUserProgress, int>> keySelector, int? take = null)
{
var result = query
.GroupBy(keySelector)
.Select(g => new IdCount {Id = g.Key, Count = g.Count()})
.OrderByDescending(x => x.Count);
if (take.HasValue)
{
return await result.Take(take.Value).ToListAsync();
}
return await result.ToListAsync();
}
}