2018-02-07 00:19:06 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
2019-09-09 18:40:04 -04:00
|
|
|
|
using System.Threading;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models.Server;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
namespace Data.Models.Client.Stats
|
2018-02-07 00:19:06 -05:00
|
|
|
|
{
|
|
|
|
|
public class EFClientStatistics : SharedEntity
|
|
|
|
|
{
|
2019-09-09 18:40:04 -04:00
|
|
|
|
public EFClientStatistics()
|
|
|
|
|
{
|
|
|
|
|
ProcessingHit = new SemaphoreSlim(1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~EFClientStatistics()
|
|
|
|
|
{
|
|
|
|
|
ProcessingHit.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public int ClientId { get; set; }
|
|
|
|
|
[ForeignKey("ClientId")]
|
|
|
|
|
public virtual EFClient Client { get; set; }
|
2018-11-27 19:31:48 -05:00
|
|
|
|
public long ServerId { get; set; }
|
2018-02-07 00:19:06 -05:00
|
|
|
|
[ForeignKey("ServerId")]
|
|
|
|
|
public virtual EFServer Server { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int Kills { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int Deaths { get; set; }
|
2018-05-16 00:57:37 -04:00
|
|
|
|
public double EloRating { get; set; }
|
2021-03-22 12:09:25 -04:00
|
|
|
|
public double ZScore { get; set; }
|
|
|
|
|
public DateTime? UpdatedAt { get; set; }
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public virtual ICollection<EFHitLocationCount> HitLocations { get; set; }
|
2018-05-17 19:31:58 -04:00
|
|
|
|
public double RollingWeightedKDR { get; set; }
|
2019-09-09 18:40:04 -04:00
|
|
|
|
public double AverageSnapValue { get; set; }
|
|
|
|
|
public int SnapHitCount { get; set; }
|
2018-05-17 19:31:58 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public double Performance
|
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
get => Math.Round(EloRating * 1/3.0 + Skill * 2/3.0, 2);
|
2018-05-17 19:31:58 -04:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public double KDR
|
|
|
|
|
{
|
2018-02-10 23:33:42 -05:00
|
|
|
|
get => Deaths == 0 ? Kills : Math.Round(Kills / (double)Deaths, 2);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|
|
|
|
|
[Required]
|
|
|
|
|
public double SPM { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public double Skill { get; set; }
|
2018-02-10 23:33:42 -05:00
|
|
|
|
[Required]
|
|
|
|
|
public int TimePlayed { get; set; }
|
2018-05-03 01:25:49 -04:00
|
|
|
|
[Required]
|
|
|
|
|
public double MaxStrain { get; set; }
|
2018-03-27 20:27:01 -04:00
|
|
|
|
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public float AverageHitOffset
|
|
|
|
|
{
|
2018-03-28 23:01:09 -04:00
|
|
|
|
get => (float)Math.Round(HitLocations.Sum(c => c.HitOffsetAverage) / Math.Max(1, HitLocations.Where(c => c.HitOffsetAverage > 0).Count()), 4);
|
2018-03-27 20:27:01 -04:00
|
|
|
|
}
|
2018-02-08 02:23:45 -05:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public int SessionKills { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public int SessionDeaths { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public int KillStreak { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public int DeathStreak { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public DateTime LastStatCalculation { get; set; }
|
2018-02-09 02:21:25 -05:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public int LastScore { get; set; }
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public DateTime LastActive { get; set; }
|
2018-05-17 19:31:58 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public double MaxSessionStrain { get; set; }
|
2018-04-28 01:22:18 -04:00
|
|
|
|
public void StartNewSession()
|
|
|
|
|
{
|
|
|
|
|
KillStreak = 0;
|
|
|
|
|
DeathStreak = 0;
|
|
|
|
|
LastScore = 0;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
SessionScores.Add(0);
|
2021-03-22 12:09:25 -04:00
|
|
|
|
Team = 0;
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public int SessionScore
|
|
|
|
|
{
|
2020-04-22 19:46:41 -04:00
|
|
|
|
set => SessionScores[SessionScores.Count - 1] = value;
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
|
get
|
|
|
|
|
{
|
2020-01-17 18:31:53 -05:00
|
|
|
|
lock (SessionScores)
|
|
|
|
|
{
|
2020-04-22 19:46:41 -04:00
|
|
|
|
return new List<int>(SessionScores).Sum();
|
2020-01-17 18:31:53 -05:00
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[NotMapped]
|
2020-04-22 19:46:41 -04:00
|
|
|
|
public int RoundScore => SessionScores[SessionScores.Count - 1];
|
2018-03-06 02:22:19 -05:00
|
|
|
|
[NotMapped]
|
2019-09-09 18:40:04 -04:00
|
|
|
|
private readonly List<int> SessionScores = new List<int>() { 0 };
|
2018-05-24 15:48:57 -04:00
|
|
|
|
[NotMapped]
|
2021-03-22 12:09:25 -04:00
|
|
|
|
public int Team { get; set; }
|
2018-05-30 21:50:20 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public DateTime LastStatHistoryUpdate { get; set; } = DateTime.UtcNow;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public double SessionSPM { get; set; }
|
2019-09-09 18:40:04 -04:00
|
|
|
|
[NotMapped]
|
|
|
|
|
public SemaphoreSlim ProcessingHit { get; private set; }
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|
|
|
|
|
}
|