Files

29 lines
914 B
C#
Raw Permalink Normal View History

2026-08-06 13:17:29 -05:00
using System.Collections.Concurrent;
using System.Numerics;
namespace SafelyYou.Data;
2026-08-06 13:17:29 -05:00
public sealed class UploadTimes
{
private readonly Lock _lock = new();
2026-08-06 13:17:29 -05:00
private readonly ConcurrentDictionary<DeviceId, (BigInteger TotalUploadTime, int UploadCounts)> _uploadHistories = new();
public void Add(DeviceId deviceId, BigInteger uploadTimeNanos)
{
lock (_lock)
2026-08-06 13:17:29 -05:00
{
if (!_uploadHistories.TryGetValue(deviceId, out var history))
{
history = (BigInteger.Zero, 0);
}
2026-08-06 13:17:29 -05:00
_uploadHistories[deviceId] = (history.TotalUploadTime + uploadTimeNanos, history.UploadCounts + 1);
}
2026-08-06 13:17:29 -05:00
}
2026-08-06 13:40:07 -05:00
public BigInteger AverageUploadTimeNanoseconds(DeviceId deviceId)
{
if (!_uploadHistories.TryGetValue(deviceId, out var history)) return BigInteger.Zero;
return history.TotalUploadTime / history.UploadCounts;
}
2026-08-06 13:17:29 -05:00
}