This commit is contained in:
2026-01-08 15:18:34 +01:00
parent d385119ca2
commit 33a0b77bf1
111 changed files with 85489 additions and 24 deletions

View File

@@ -0,0 +1,37 @@
using LogCentral.Server.Data;
using LogCentral.Server.Services;
using Microsoft.EntityFrameworkCore;
public interface IAnalyticsService
{
Task<Dictionary<string, object>> GetAnalyticsAsync(DateTime startDate, DateTime endDate);
}
public class AnalyticsService : IAnalyticsService
{
private readonly LogCentralDbContext _context;
public AnalyticsService(LogCentralDbContext context)
{
_context = context;
}
public async Task<Dictionary<string, object>> GetAnalyticsAsync(DateTime startDate, DateTime endDate)
{
var logs = await _context.LogEntries
.Where(l => l.Timestamp >= startDate && l.Timestamp <= endDate)
.ToListAsync();
return new Dictionary<string, object>
{
["totalEvents"] = logs.Count(l => l.Level == 7),
["topEvents"] = logs
.Where(l => l.Level == 7)
.GroupBy(l => l.Message)
.Select(g => new { Event = g.Key, Count = g.Count() })
.OrderByDescending(x => x.Count)
.Take(10)
.ToList()
};
}
}