wip
This commit is contained in:
+11
-15
@@ -14,24 +14,20 @@ namespace AnotherReplayReader.Utils
|
||||
|
||||
public class EmaSpeed
|
||||
{
|
||||
const double Tau = 5;
|
||||
const double Tau = 2;
|
||||
|
||||
private DateTimeOffset lastEventTime = DateTimeOffset.UtcNow;
|
||||
private DateTimeOffset timeSinceLastSpeedMeasure = DateTimeOffset.UtcNow;
|
||||
private int bufferedCharactersSinceLastSpeedMeasure = 0;
|
||||
private double emaSpeed = double.NaN;
|
||||
|
||||
public void ProcessEvent(AIAnalyzeProgressData data)
|
||||
public void ProcessEvent(int textLength, DateTimeOffset? eventTime)
|
||||
{
|
||||
if (data.IsExtra)
|
||||
if (eventTime is { } value)
|
||||
{
|
||||
return;
|
||||
lastEventTime = value;
|
||||
}
|
||||
if (data.TimeStamp is { } timestamp)
|
||||
{
|
||||
lastEventTime = timestamp;
|
||||
}
|
||||
bufferedCharactersSinceLastSpeedMeasure += data.Delta.Text.Length;
|
||||
bufferedCharactersSinceLastSpeedMeasure += textLength;
|
||||
}
|
||||
|
||||
public double GetDisplaySpeed(DateTimeOffset now)
|
||||
@@ -42,7 +38,7 @@ namespace AnotherReplayReader.Utils
|
||||
double instant = 0;
|
||||
double dt = (now - timeSinceLastSpeedMeasure).TotalSeconds;
|
||||
|
||||
if (bufferedCharactersSinceLastSpeedMeasure > 0 && dt > 0.05)
|
||||
if (/*bufferedCharactersSinceLastSpeedMeasure > 0 && */dt > 0.05)
|
||||
{
|
||||
instant = bufferedCharactersSinceLastSpeedMeasure / dt;
|
||||
|
||||
@@ -64,11 +60,11 @@ namespace AnotherReplayReader.Utils
|
||||
double idle = (now - lastEventTime).TotalSeconds;
|
||||
double display = emaSpeed;
|
||||
|
||||
if (idle > 0.5)
|
||||
{
|
||||
double decay = Math.Exp(-(idle - 0.5) / Tau);
|
||||
display *= decay;
|
||||
}
|
||||
//if (idle > 0.5)
|
||||
//{
|
||||
// double decay = Math.Exp(-(idle - 0.5) / Tau);
|
||||
// display *= decay;
|
||||
//}
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user