Files
SkydiveLogs/Back/skydiveLogs-api.DomainBusiness/StatsForLastMonthByDzService.cs
sandre ceed44f997 Little test with AI + Add the equipment (#8)
Tests using local LLM AI to add comments in the C# files
For the flights tunnel, show the total to day/hours
For the jump, add the equipment (now just with the wingsuit)

Reviewed-on: #8
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
2026-05-16 09:24:13 +00:00

81 lines
3.1 KiB
C#

using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
public class StatsForLastMonthByDzService : IStatsForLastMonthByDzService
{
#region Public Constructors
public StatsForLastMonthByDzService(IJumpService jumpService,
IIdentityService identityService,
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository)
{
_jumpService = jumpService;
_identityService = identityService;
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Retrieves statistics for the last month grouped by drop zone.
/// </summary>
/// <returns>A collection of StatsForLastMonthByDz entities containing the statistics.</returns>
public IEnumerable<StatsForLastMonthByDz> GetStats()
{
var allStats = _statsForLastMonthByDzRepository.GetAll(_identityService.ConnectedUser);
if (!allStats.Any())
{
var allJumps = _jumpService.GetAllJumps();
var results = new List<StatsForLastMonthByDz>();
if (allJumps.Any())
{
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
var yearOfLastJump = lastJump.JumpDate.Year;
var monthOfLastJump = lastJump.JumpDate.Month;
results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
.GroupBy(j => j.DropZone.Name,
j => j,
(groupby, jumps) => new StatsForLastMonthByDz
{
DropZone = groupby.ToString(),
Nb = jumps.Count(),
User = _identityService.ConnectedUser
})];
}
_statsForLastMonthByDzRepository.Add(results);
return results;
}
return allStats;
}
/// <summary>
/// Resets the last month drop zone statistics.
/// </summary>
public void Reset()
{
_statsForLastMonthByDzRepository.Delete(_identityService.ConnectedUser);
}
#endregion Public Methods
#region Private Fields
private readonly IIdentityService _identityService;
private readonly IJumpService _jumpService;
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
#endregion Private Fields
}
}