private void updateMap(@NotNull NetworkStats ns, final long index) {
final String key = ns.userId();
@Nullable final Stats stats = latestStatsPerClientId.getUsing(key, stats0);
if (stats == null) {
Stats value = project(Stats.class, ns);
value.writeEma = value.writeBps();
value.readEma = value.readBps();
value.index = index;
latestStatsPerClientId.put(key, value);
return;
}
double lastWriteEma = stats.writeEma;
double lastReadEma = stats.readEma;
if (equalsSecond(stats.timestamp(), ns.timestamp())) {
long lastWriteBps = stats.writeBps();
long lastReadBps = stats.readBps();
Wires.copyTo(ns, stats);
stats.writeBps(stats.writeBps() + lastWriteBps);
stats.readBps(stats.readBps() + lastReadBps);
} else
Wires.copyTo(ns, stats);
stats.writeEma((stats.writeBps() * (1 - alpha)) + (lastWriteEma * alpha));
stats.readEma((stats.readBps() * (1 - alpha)) + (lastReadEma * alpha));
latestStatsPerClientId.put(key, stats);
}