I'm writing a service that tracks game stats for an online shooter. Clients report events to the server which are then recorded in a SQL Server database. The server is expected to generate a report of game events aggregated from client reports - the authenticity of an event claim is based on the number of clients that reported it.
I have a Linq-to-SQL query that groups event reports from different clients based on the time they occurred (within 7 seconds).
Events
.Select(e =>
Events.Where(ev =>
// Same event type
ev.Discriminator == e.Discriminator &&
// Same match
ev.ServerIpAddress == e.ServerIpAddress &&
SqlMethods.DateDiffSecond(ev.MatchStartTime, e.MatchStartTime) < 30 &&
// Find nearby events
Math.Abs(ev.MatchTime.TotalSeconds - e.MatchTime.TotalSeconds) < 7 &&
// That are duplicate
ev.VictimTribesGuid == e.VictimTribesGuid &&
ev.KillerTribesGuid == e.KillerTribesGuid &&
ev.KillType == e.KillType &&
ev.Weapon == e.Weapon
)
)
This returns the following:
Events are grouped as expected, but as the outer query is "per-event", groups are duplicated (see the first two rows).
Is there a way to strip these duplicate groups?