FunGame-Core/Entity/Statistics/UserStatistics.cs
milimoe 940f8397f1
为服务器统一数据访问连接 (#91)
* 重做 WebSocket 监听;为服务器统一了多种数据连接访问时的处理;统一编码为 UTF-8

* ModelManager已更名并移动到工具命名空间中

* 完成 WebSocket 消息处理系统

* 添加Socket异步接收数据流;修复TaskUtility阻塞的问题;优化心跳、房间、模组

* 添加枚举

* 删除多余字符

* 添加监听器的名称

* 修改了命名
2024-10-02 15:00:34 +08:00

130 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Milimoe.FunGame.Core.Entity
{
/// <summary>
/// 记录 <see cref="Entity.User"/> 的生涯、赛季统计数据<para/>
/// Key为赛季(long)每个key代表第key赛季key = 0时为生涯数据。
/// </summary>
public class UserStatistics
{
public long Id => User.Id;
public User User { get; }
public Dictionary<long, double> DamageStats { get; } = [];
public Dictionary<long, double> PhysicalDamageStats { get; } = [];
public Dictionary<long, double> MagicDamageStats { get; } = [];
public Dictionary<long, double> RealDamageStats { get; } = [];
public Dictionary<long, double> AvgDamageStats
{
get
{
Dictionary<long, double> avgdamage = [];
foreach (long key in Plays.Keys)
{
long plays = Plays[key];
double total = 0;
if (DamageStats.ContainsKey(key))
{
total = DamageStats.Values.Sum();
}
avgdamage.Add(key, Math.Round(total / plays, 2));
}
return avgdamage;
}
}
public Dictionary<long, double> AvgPhysicalDamageStats
{
get
{
Dictionary<long, double> avgdamage = [];
foreach (long key in Plays.Keys)
{
long plays = Plays[key];
double total = 0;
if (PhysicalDamageStats.ContainsKey(key))
{
total = PhysicalDamageStats.Values.Sum();
}
avgdamage.Add(key, Math.Round(total / plays, 2));
}
return avgdamage;
}
}
public Dictionary<long, double> AvgMagicDamageStats
{
get
{
Dictionary<long, double> avgdamage = [];
foreach (long key in Plays.Keys)
{
long plays = Plays[key];
double total = 0;
if (MagicDamageStats.ContainsKey(key))
{
total = MagicDamageStats.Values.Sum();
}
avgdamage.Add(key, Math.Round(total / plays, 2));
}
return avgdamage;
}
}
public Dictionary<long, double> AvgRealDamageStats
{
get
{
Dictionary<long, double> avgdamage = [];
foreach (long key in Plays.Keys)
{
long plays = Plays[key];
double total = 0;
if (RealDamageStats.ContainsKey(key))
{
total = RealDamageStats.Values.Sum();
}
avgdamage.Add(key, Math.Round(total / plays, 2));
}
return avgdamage;
}
}
public Dictionary<long, long> Kills { get; } = [];
public Dictionary<long, long> Deaths { get; } = [];
public Dictionary<long, long> Assists { get; } = [];
public Dictionary<long, long> Plays { get; } = [];
public Dictionary<long, long> Wins { get; } = [];
public Dictionary<long, long> Loses { get; } = [];
public Dictionary<long, double> Winrates
{
get
{
Dictionary<long, double> winrates = [];
foreach (long key in Plays.Keys)
{
long plays = Plays[key];
long wins = 0;
if (Wins.TryGetValue(key, out long value))
{
wins = value;
}
winrates.Add(key, Math.Round(wins * 1.0 / plays * 1.0, 4));
}
return winrates;
}
}
public Dictionary<long, double> RatingStats { get; } = [];
public Dictionary<long, double> EloStats { get; } = [];
public Dictionary<long, string> RankStats { get; } = [];
public string GetWinrate(long season)
{
if (Winrates.TryGetValue(season, out double value))
{
return value.ToString("0.##%");
}
return "0%";
}
internal UserStatistics(User user)
{
User = user;
}
}
}