Skip to content

Commit

Permalink
Analytics: Fix rare false negative with invalid despawn events
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Jul 27, 2024
1 parent 15a48fc commit 0f1c9f1
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AgentBuffGainedDeterminer(Agent agent, uint buffId, bool ignoreInit

protected override Event GetEvent(IEnumerable<Event> events)
{
var filteredEvents = stopAtDespawn ? events.TakeWhile(x => !(x is AgentDespawnEvent despawn && despawn.Agent == agent)) : events;
var filteredEvents = stopAtDespawn ? TakeUntilDespawn(events) : events;

if (ignoreInitial)
{
Expand All @@ -29,10 +29,30 @@ protected override Event GetEvent(IEnumerable<Event> events)
else
{
return filteredEvents
.TakeWhile(x => x is not AgentDespawnEvent)
.OfType<BuffApplyEvent>()
.FirstOrDefault(x => x.Agent == agent && x.Buff.Id == buffId);
}
}

private IEnumerable<Event> TakeUntilDespawn(IEnumerable<Event> events)
{
// Very rarely, arcdps has been seen to emit a despawn event instead of a spawn event
// (specifically, this has been observed once with arcdps 20220330).
// To work around this issue, we ignore despawn events that happen very soon after the first event.
const long earlyDespawnThreshold = 200;

long firstTime = long.MaxValue;
foreach (var e in events)
{
firstTime = Math.Min(firstTime, e.Time);

if (e is AgentDespawnEvent despawn && despawn.Agent == agent && despawn.Time - firstTime > earlyDespawnThreshold)
{
yield break;
}

yield return e;
}
}
}
}

0 comments on commit 0f1c9f1

Please # to comment.