ceed44f997
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>
80 lines
3.0 KiB
C#
80 lines
3.0 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 StatsForLastYearByDzService : IStatsForLastYearByDzService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public StatsForLastYearByDzService(IJumpService jumpService,
|
|
IIdentityService identityService,
|
|
IStatsForLastYearByDzRepository statsForLastYearByDzRepository)
|
|
{
|
|
_jumpService = jumpService;
|
|
_identityService = identityService;
|
|
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Retrieves statistics for the last year grouped by drop zone.
|
|
/// </summary>
|
|
/// <returns>A collection of StatsForLastYearByDz entities containing the statistics.</returns>
|
|
public IEnumerable<StatsForLastYearByDz> GetStats()
|
|
{
|
|
var allStats = _statsForLastYearByDzRepository.GetAll(_identityService.ConnectedUser);
|
|
if (!allStats.Any())
|
|
{
|
|
var allJumps = _jumpService.GetAllJumps();
|
|
var results = new List<StatsForLastYearByDz>();
|
|
|
|
if (allJumps.Any())
|
|
{
|
|
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
|
var yearOfLastJump = lastJump.JumpDate.Year;
|
|
|
|
results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
|
.GroupBy(j => j.DropZone.Name,
|
|
j => j,
|
|
(groupby, jumps) => new StatsForLastYearByDz
|
|
{
|
|
DropZone = groupby.ToString(),
|
|
Nb = jumps.Count(),
|
|
User = _identityService.ConnectedUser
|
|
})];
|
|
}
|
|
|
|
_statsForLastYearByDzRepository.Add(results);
|
|
return results;
|
|
}
|
|
|
|
return allStats;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the last year drop zone statistics.
|
|
/// </summary>
|
|
public void Reset()
|
|
{
|
|
_statsForLastYearByDzRepository.Delete(_identityService.ConnectedUser);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IIdentityService _identityService;
|
|
private readonly IJumpService _jumpService;
|
|
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
}
|