Files
SkydiveLogs/Back/skydiveLogs-api.DomainBusiness/StatsService.cs
2026-01-23 22:52:51 +01:00

198 lines
7.1 KiB
C#

using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
public class StatsService : IStatsService
{
#region Public Constructors
public StatsService(IJumpService jumpService,
IStatsByAircraftService statsByAircraftService,
IStatsByDzService statsByDzService,
IStatsByGearService statsByGearService,
IStatsByJumpTypeService statsByJumpTypeService,
IStatsByYearByJumpTypeService statsByYearByJumpTypeService,
IStatsByYearService statsByYearService,
IStatsForLastMonthByDzService statsForLastMonthByDzService,
IStatsForLastMonthByJumpTypeService statsForLastMonthByJumpTypeService,
IStatsForLastYearByDzService statsForLastYearByDzService,
IStatsForLastYearByJumpTypeService statsForLastYearByJumpTypeService)
{
_jumpService = jumpService;
_statsByAircraftService = statsByAircraftService;
_statsByDzService = statsByDzService;
_statsByGearService = statsByGearService;
_statsByJumpTypeService = statsByJumpTypeService;
_statsByYearByJumpTypeService = statsByYearByJumpTypeService;
_statsByYearService = statsByYearService;
_statsForLastMonthByDzService = statsForLastMonthByDzService;
_statsForLastMonthByJumpTypeService = statsForLastMonthByJumpTypeService;
_statsForLastYearByDzService = statsForLastYearByDzService;
_statsForLastYearByJumpTypeService = statsForLastYearByJumpTypeService;
}
#endregion Public Constructors
#region Public Methods
public SimpleSummary GetSimpleSummary()
{
var allJumps = _jumpService.GetAllJumps();
var results = new SimpleSummary();
if (allJumps.Any())
{
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
results = new SimpleSummary
{
LastJump = lastJump,
TotalJumps = allJumps.Count(),
TotalCutaways = allJumps.Where(j => j.WithCutaway).Count()
};
}
return results;
}
public void Reset()
{
// var resetStats = new UserStats();
// var myStats = GetAllStats();
// myStats.ByAircraft = resetStats.ByAircraft;
// myStats.ByDz = resetStats.ByDz;
// myStats.ByGear = resetStats.ByGear;
// myStats.ByJumpType = resetStats.ByJumpType;
// myStats.ByYear = resetStats.ByYear;
// myStats.ForLastMonthByDz = resetStats.ForLastMonthByDz;
// myStats.ForLastMonthByJumpType = resetStats.ForLastMonthByJumpType;
// myStats.ForLastYearByDz = resetStats.ForLastYearByDz;
// myStats.ForLastYearByJumpType = resetStats.ForLastYearByJumpType;
// myStats.ByYearByJumpType = resetStats.ByYearByJumpType;
// _userStatsRepository.Update(myStats);
}
public IEnumerable<Statistic> GetStatsByAircraft()
{
var tmp = _statsByAircraftService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.Aircraft,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByDz()
{
var tmp = _statsByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByGear()
{
var tmp = _statsByGearService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.Gear,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByJumpType()
{
var tmp = _statsByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByYear()
{
var tmp = _statsByYearService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.Year,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
{
var tmp = _statsForLastMonthByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
{
var tmp = _statsForLastMonthByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastYearByDz()
{
var tmp = _statsForLastYearByDzService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.DropZone,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
{
var tmp = _statsForLastYearByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.JumpType,
Nb = a.Nb
})];
}
public IEnumerable<Statistic> GetStatsByYearByJumpType()
{
var tmp = _statsByYearByJumpTypeService.GetStats();
return [.. tmp.Select(a => new Statistic
{
Label = a.Year,
Label2 = a.JumpType,
Nb = a.Nb
})];
}
#endregion Public Methods
#region Private Fields
private readonly IJumpService _jumpService;
private readonly IStatsByAircraftService _statsByAircraftService;
private readonly IStatsByDzService _statsByDzService;
private readonly IStatsByGearService _statsByGearService;
private readonly IStatsByJumpTypeService _statsByJumpTypeService;
private readonly IStatsByYearByJumpTypeService _statsByYearByJumpTypeService;
private readonly IStatsByYearService _statsByYearService;
private readonly IStatsForLastMonthByDzService _statsForLastMonthByDzService;
private readonly IStatsForLastMonthByJumpTypeService _statsForLastMonthByJumpTypeService;
private readonly IStatsForLastYearByDzService _statsForLastYearByDzService;
private readonly IStatsForLastYearByJumpTypeService _statsForLastYearByJumpTypeService;
#endregion Private Fields
}
}