Refacto
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByAircraft
|
||||
{
|
||||
public string Label { get; set; }
|
||||
public string Aircraft { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByDz
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string DropZone { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByGear
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string Gear { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByJumpType
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string JumpType { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByYear
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string Year { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsByYearByJumpType
|
||||
{
|
||||
public string Label { get; set; }
|
||||
public string Year { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string JumpType { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsForLastMonthByDz
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string DropZone { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsForLastMonthByJumpType
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string JumpType { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsForLastYearByDz
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string DropZone { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class StatsForLastYearByJumpType
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public string Label2 { get; set; }
|
||||
public string JumpType { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByDz> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByGear> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByJumpType> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByYearByJumpType> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
public interface IStatsByYearService
|
||||
{
|
||||
#region Public Methods
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByYear> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsForLastMonthByDz> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsForLastMonthByJumpType> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsForLastYearByDz> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsForLastYearByJumpType> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
@@ -8,6 +9,26 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
|
||||
SimpleSummary GetSimpleSummary();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByAircraft();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByGear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByJumpType();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByYear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByYearByJumpType();
|
||||
|
||||
void Reset();
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,13 +6,13 @@ using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class StatsByByAircraftService : IStatsByAircraftService
|
||||
public class StatsByAircraftService : IStatsByAircraftService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsByByAircraftService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByAircraftRepository statsByAircraftRepository)
|
||||
public StatsByAircraftService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByAircraftRepository statsByAircraftRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
@@ -33,11 +33,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByAircraft
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Aircraft = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
|
||||
@@ -23,370 +23,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public IEnumerable<Statistic> GetStats()
|
||||
public IEnumerable<StatsByDz> GetStats()
|
||||
{
|
||||
// var allStats = GetAllStats();
|
||||
// if (!allStats.ByAircraft.Any())
|
||||
// {
|
||||
// var allJumps = _jumpService.GetAllJumps();
|
||||
// var results = new List<Statistic>();
|
||||
|
||||
// if (allJumps.Any())
|
||||
// {
|
||||
// results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
// j => j,
|
||||
// (groupby, jumps) => new Statistic
|
||||
// {
|
||||
// Label = groupby.ToString(),
|
||||
// Nb = jumps.Count()
|
||||
// })];
|
||||
// }
|
||||
|
||||
// allStats.ByAircraft = results;
|
||||
// _userStatsRepository.Update(allStats);
|
||||
// }
|
||||
|
||||
// return allStats.ByAircraft;
|
||||
return null;
|
||||
}
|
||||
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsByDzRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsByDz>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByDz
|
||||
{
|
||||
DropZone = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsByDzRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsByDzRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
|
||||
@@ -11,385 +11,57 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsByGearService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsByGearRepository statsByGearRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsByGear> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsByGearRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsByGear>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByGear
|
||||
{
|
||||
Gear = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsByGearRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsByGearRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,385 +11,57 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsByJumpTypeService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsByJumpType> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsByJumpType>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByJumpType
|
||||
{
|
||||
JumpType = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsByJumpTypeRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsByJumpTypeRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,385 +11,58 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsByYearByJumpTypeService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsByYearByJumpType> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsByYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsByYearByJumpType>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByYearByJumpType
|
||||
{
|
||||
Year = groupby.Year.ToString(),
|
||||
JumpType = groupby.Name.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsByYearByJumpTypeRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsByYearByJumpTypeRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,385 +11,57 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsByYearService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsByYearRepository statsByYearRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsByYear> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsByYearRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsByYear>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsByYear
|
||||
{
|
||||
Year = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsByYearRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsByYearRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,191 +11,25 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsForLastMonthByDzService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsForLastMonthByDz> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsForLastMonthByDzRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsForLastMonthByDz>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
@@ -204,192 +38,35 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsForLastMonthByDz
|
||||
{
|
||||
DropZone = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsForLastMonthByDzRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsForLastMonthByDzRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,191 +11,25 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsForLastMonthByJumpTypeService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsForLastMonthByJumpType> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsForLastMonthByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsForLastMonthByJumpType>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
@@ -204,192 +38,35 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsForLastMonthByJumpType
|
||||
{
|
||||
JumpType = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsForLastMonthByJumpTypeRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsForLastMonthByJumpTypeRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,253 +11,25 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsForLastYearByDzService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsForLastYearByDz> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsForLastYearByDzRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsForLastYearByDz>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
@@ -265,131 +37,35 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsForLastYearByDz
|
||||
{
|
||||
DropZone = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsForLastYearByDzRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
public void Reset()
|
||||
{
|
||||
_statsForLastYearByDzRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -11,27 +11,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
#region Public Constructors
|
||||
|
||||
public StatsForLastYearByJumpTypeService(IJumpService jumpService,
|
||||
IIdentityService identityService,
|
||||
IStatsByDzRepository statsByDzRepository,
|
||||
IStatsByGearRepository statsByGearRepository,
|
||||
IStatsByJumpTypeRepository statsByJumpTypeRepository,
|
||||
IStatsByYearByJumpTypeRepository statsByYearByJumpTypeRepository,
|
||||
IStatsByYearRepository statsByYearRepository,
|
||||
IStatsForLastMonthByDzRepository statsForLastMonthByDzRepository,
|
||||
IStatsForLastMonthByJumpTypeRepository statsForLastMonthByJumpTypeRepository,
|
||||
IStatsForLastYearByDzRepository statsForLastYearByDzRepository,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
IIdentityService identityService,
|
||||
IStatsForLastYearByJumpTypeRepository statsForLastYearByJumpTypeRepository)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_statsByDzRepository = statsByDzRepository;
|
||||
_statsByGearRepository = statsByGearRepository;
|
||||
_statsByJumpTypeRepository = statsByJumpTypeRepository;
|
||||
_statsByYearByJumpTypeRepository = statsByYearByJumpTypeRepository;
|
||||
_statsByYearRepository = statsByYearRepository;
|
||||
_statsForLastMonthByDzRepository = statsForLastMonthByDzRepository;
|
||||
_statsForLastMonthByJumpTypeRepository = statsForLastMonthByJumpTypeRepository;
|
||||
_statsForLastYearByDzRepository = statsForLastYearByDzRepository;
|
||||
_statsForLastYearByJumpTypeRepository = statsForLastYearByJumpTypeRepository;
|
||||
}
|
||||
|
||||
@@ -39,225 +23,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
public IEnumerable<StatsForLastYearByJumpType> GetStats()
|
||||
{
|
||||
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 IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
var allStats = _statsForLastYearByJumpTypeRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (!allStats.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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 Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
var results = new List<StatsForLastYearByJumpType>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
@@ -265,130 +37,36 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = [.. allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new StatsForLastYearByJumpType
|
||||
{
|
||||
JumpType = groupby.ToString(),
|
||||
Nb = jumps.Count(),
|
||||
User = _identityService.ConnectedUser
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYearByJumpType()
|
||||
{
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYearByJumpType.Any())
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = [.. allJumps.GroupBy(j => new { j.JumpType.Name, j.JumpDate.Year },
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.Year.ToString(),
|
||||
Label2 = groupby.Name.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})];
|
||||
}
|
||||
|
||||
allStats.ByYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return allStats.ByYearByJumpType;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats
|
||||
{
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
_userStatsRepository.Add(allStats);
|
||||
_statsForLastYearByJumpTypeRepository.Add(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_statsForLastYearByJumpTypeRepository.Delete(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IStatsByDzRepository _statsByDzRepository;
|
||||
private readonly IStatsByGearRepository _statsByGearRepository;
|
||||
private readonly IStatsByJumpTypeRepository _statsByJumpTypeRepository;
|
||||
private readonly IStatsByYearByJumpTypeRepository _statsByYearByJumpTypeRepository;
|
||||
private readonly IStatsByYearRepository _statsByYearRepository;
|
||||
private readonly IStatsForLastMonthByDzRepository _statsForLastMonthByDzRepository;
|
||||
private readonly IStatsForLastMonthByJumpTypeRepository _statsForLastMonthByJumpTypeRepository;
|
||||
private readonly IStatsForLastYearByDzRepository _statsForLastYearByDzRepository;
|
||||
private readonly IStatsForLastYearByJumpTypeRepository _statsForLastYearByJumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
@@ -8,9 +9,29 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsService(IJumpService jumpService)
|
||||
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
|
||||
@@ -55,11 +76,122 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
// _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
|
||||
}
|
||||
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByDzRepository : IRepository<StatsByDz>
|
||||
public interface IStatsByDzRepository : IStatsRepository<StatsByDz>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByDz GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByGearRepository : IRepository<StatsByGear>
|
||||
public interface IStatsByGearRepository : IStatsRepository<StatsByGear>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByGear GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByJumpTypeRepository : IRepository<StatsByJumpType>
|
||||
public interface IStatsByJumpTypeRepository : IStatsRepository<StatsByJumpType>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByJumpType GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByYearByJumpTypeRepository : IRepository<StatsByYearByJumpType>
|
||||
public interface IStatsByYearByJumpTypeRepository : IStatsRepository<StatsByYearByJumpType>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByYearByJumpType GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByYearRepository : IRepository<StatsByYear>
|
||||
public interface IStatsByYearRepository : IStatsRepository<StatsByYear>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByYear GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsForLastMonthByDzRepository : IRepository<StatsForLastMonthByDz>
|
||||
public interface IStatsForLastMonthByDzRepository : IStatsRepository<StatsForLastMonthByDz>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsForLastMonthByDz GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsForLastMonthByJumpTypeRepository : IRepository<StatsForLastMonthByJumpType>
|
||||
public interface IStatsForLastMonthByJumpTypeRepository : IStatsRepository<StatsForLastMonthByJumpType>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsForLastMonthByJumpType GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsForLastYearByDzRepository : IRepository<StatsForLastYearByDz>
|
||||
public interface IStatsForLastYearByDzRepository : IStatsRepository<StatsForLastYearByDz>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsForLastYearByDz GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsForLastYearByJumpTypeRepository : IRepository<StatsForLastYearByJumpType>
|
||||
public interface IStatsForLastYearByJumpTypeRepository : IStatsRepository<StatsForLastYearByJumpType>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsForLastYearByJumpType GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
T GetAll(User user);
|
||||
IEnumerable<T> GetAll(User user);
|
||||
|
||||
int Add(T newEntity);
|
||||
int Add(IEnumerable<T> newEntity);
|
||||
|
||||
bool Update(T updated);
|
||||
bool Update(IEnumerable<T> updatedEntity, User user);
|
||||
|
||||
bool Delete(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByAircraftRepository : IStatsRepository<StatsByAircraft>
|
||||
public class StatsByAircraftRepository : IStatsByAircraftRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByDzRepository : IStatsRepository<StatsByDz>
|
||||
public class StatsByDzRepository : IStatsByDzRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByDz newStats)
|
||||
public int Add(IEnumerable<StatsByDz> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByDz GetAll(User user)
|
||||
public IEnumerable<StatsByDz> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByDz stats)
|
||||
public bool Update(IEnumerable<StatsByDz> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByGearRepository : IStatsRepository<StatsByGear>
|
||||
public class StatsByGearRepository : IStatsByGearRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByGear newStats)
|
||||
public int Add(IEnumerable<StatsByGear> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByGear GetAll(User user)
|
||||
public IEnumerable<StatsByGear> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByGear stats)
|
||||
public bool Update(IEnumerable<StatsByGear> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByJumpTypeRepository : IStatsRepository<StatsByJumpType>
|
||||
public class StatsByJumpTypeRepository : IStatsByJumpTypeRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByJumpType newStats)
|
||||
public int Add(IEnumerable<StatsByJumpType> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByJumpType GetAll(User user)
|
||||
public IEnumerable<StatsByJumpType> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByJumpType stats)
|
||||
public bool Update(IEnumerable<StatsByJumpType> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByYearByJumpTypeRepository : IStatsRepository<StatsByYearByJumpType>
|
||||
public class StatsByYearByJumpTypeRepository : IStatsByYearByJumpTypeRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByYearByJumpType newStats)
|
||||
public int Add(IEnumerable<StatsByYearByJumpType> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByYearByJumpType GetAll(User user)
|
||||
public IEnumerable<StatsByYearByJumpType> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByYearByJumpType stats)
|
||||
public bool Update(IEnumerable<StatsByYearByJumpType> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
@@ -5,7 +6,7 @@ using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByYearRepository : IStatsRepository<StatsByYear>
|
||||
public class StatsByYearRepository : IStatsByYearRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -19,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByYear newStats)
|
||||
public int Add(IEnumerable<StatsByYear> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -36,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByYear GetAll(User user)
|
||||
public IEnumerable<StatsByYear> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByYear stats)
|
||||
public bool Update(IEnumerable<StatsByYear> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsForLastMonthByDzRepository : IStatsRepository<StatsForLastMonthByDz>
|
||||
public class StatsForLastMonthByDzRepository : IStatsForLastMonthByDzRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsForLastMonthByDz newStats)
|
||||
public int Add(IEnumerable<StatsForLastMonthByDz> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsForLastMonthByDz GetAll(User user)
|
||||
public IEnumerable<StatsForLastMonthByDz> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsForLastMonthByDz stats)
|
||||
public bool Update(IEnumerable<StatsForLastMonthByDz> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsForLastMonthByJumpTypeRepository : IStatsRepository<StatsForLastMonthByJumpType>
|
||||
public class StatsForLastMonthByJumpTypeRepository : IStatsForLastMonthByJumpTypeRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsForLastMonthByJumpType newStats)
|
||||
public int Add(IEnumerable<StatsForLastMonthByJumpType> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsForLastMonthByJumpType GetAll(User user)
|
||||
public IEnumerable<StatsForLastMonthByJumpType> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsForLastMonthByJumpType stats)
|
||||
public bool Update(IEnumerable<StatsForLastMonthByJumpType> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsForLastYearByDzRepository : IStatsRepository<StatsForLastYearByDz>
|
||||
public class StatsForLastYearByDzRepository : IStatsForLastYearByDzRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsForLastYearByDz newStats)
|
||||
public int Add(IEnumerable<StatsForLastYearByDz> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsForLastYearByDz GetAll(User user)
|
||||
public IEnumerable<StatsForLastYearByDz> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsForLastYearByDz stats)
|
||||
public bool Update(IEnumerable<StatsForLastYearByDz> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsForLastYearByJumpTypeRepository : IStatsRepository<StatsForLastYearByJumpType>
|
||||
public class StatsForLastYearByJumpTypeRepository : IStatsForLastYearByJumpTypeRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsForLastYearByJumpType newStats)
|
||||
public int Add(IEnumerable<StatsForLastYearByJumpType> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsForLastYearByJumpType GetAll(User user)
|
||||
public IEnumerable<StatsForLastYearByJumpType> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsForLastYearByJumpType stats)
|
||||
public bool Update(IEnumerable<StatsForLastYearByJumpType> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
Reference in New Issue
Block a user