Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion src/main/java/opendota/CreateParsedDataBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class PlayerData {
public List<Integer> lh_t = new ArrayList<>();
public List<Integer> dn_t = new ArrayList<>();
public List<Integer> xp_t = new ArrayList<>();
public List<Integer> camps_stacked_t = new ArrayList<>();
public List<Integer> hero_damage_t = new ArrayList<>();
public List<Integer> hero_healing_t = new ArrayList<>();
public List<Entry> obs_log = new ArrayList<>();
public List<Entry> sen_log = new ArrayList<>();
public List<Entry> obs_left_log = new ArrayList<>();
Expand Down Expand Up @@ -142,6 +145,50 @@ public class CreateParsedDataBlob {

private Gson g = new Gson();

// Damage/healing dealt to real (non-illusion) heroes, bucketed by slot and
// minute of the event time, then emitted as cumulative hero_damage_t and
// hero_healing_t series on minute boundaries. Bucketed by event time in a
// pre-scan (rather than accumulated in stream order) because combat log
// entries can appear in the stream after the interval entry of the same
// game time, which would drop the final minute of a match.
private Map<Integer, Map<Integer, Integer>> heroDamageMinuteBySlot = new HashMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to bucket into minutes here? Isn't hero damage/healing additive, so we can just add to it whenever we encounter a combat log event and then add on minute boundaries?

@geracosta geracosta Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damage is additive — the bucketing isn't about that, it's about stream order. The combat log entries aren't strictly ordered against the interval entries: events for game time T can show up in the stream after the interval entry for T. With a running total snapshotted at each interval, every sample misses the tail of its own minute (it lands one sample late), and anything after the last interval entry is lost for good — that's how I first ran into it, the accumulator version was dropping the final teamfight from the last sample on the match I verified against the scoreboard. Bucketing by event time makes each sample include exactly what happened up to its boundary, regardless of arrival order. Memory-wise it's one int per slot per minute.

private Map<Integer, Map<Integer, Integer>> heroHealingMinuteBySlot = new HashMap<>();
private Map<Integer, Integer> heroDamageCumBySlot = new HashMap<>();
private Map<Integer, Integer> heroHealingCumBySlot = new HashMap<>();

// Events in (60*(k-1), 60*k] belong to bucket k so they are included in the
// sample taken at the minute boundary 60*k
private int minuteBucket(Integer time) {
return Math.max(0, (int) Math.ceil(time / 60.0));
}

private void precomputeMinuteSeries(List<Entry> entries, Metadata meta) {
for (Entry e : entries) {
if (e.time == null || e.value == null) {
continue;
}
// matches the Valve scoreboard definitions: damage/healing dealt to
// real (non-illusion) heroes other than yourself; illusion attacker
// damage counts toward the owning hero
if ("DOTA_COMBATLOG_DAMAGE".equals(e.type) || "DOTA_COMBATLOG_HEAL".equals(e.type)) {
if (e.targethero == null || !e.targethero ||
(e.targetillusion != null && e.targetillusion) ||
e.targetname == null || e.targetname.equals(e.sourcename)) {
continue;
}
Integer sourceSlot = meta.hero_to_slot.get(e.sourcename);
if (sourceSlot == null) {
continue;
}
Map<Integer, Map<Integer, Integer>> target = "DOTA_COMBATLOG_DAMAGE".equals(e.type)
? heroDamageMinuteBySlot
: heroHealingMinuteBySlot;
target.computeIfAbsent(sourceSlot, k -> new HashMap<>())
.merge(minuteBucket(e.time), e.value, Integer::sum);
}
}
}

public ParsedData createParsedDataBlob(List<Entry> entries) {
long tStart = System.currentTimeMillis();
Metadata meta = processMetadata(entries);
Expand Down Expand Up @@ -461,6 +508,7 @@ private List<Entry> processExpand(List<Entry> entries, Metadata meta) {
List<Entry> output = new ArrayList<>();
Integer aegisHolder = null;
Integer aegisDeathTime = null;
precomputeMinuteSeries(entries, meta);

for (Entry e : entries) {
String type = e.type;
Expand Down Expand Up @@ -1124,6 +1172,21 @@ private void handleInterval(Entry e, List<Entry> output, Metadata meta) {
addIntervalData(e, output, meta, "xp_t", e.xp);
addIntervalData(e, output, meta, "lh_t", e.lh);
addIntervalData(e, output, meta, "dn_t", e.denies);
if (e.camps_stacked != null) {
// not present in old replays; leave the array empty rather than filling with nulls
addIntervalData(e, output, meta, "camps_stacked_t", e.camps_stacked);
}
int minuteIdx = e.time / 60;
int dmgCum = heroDamageCumBySlot.getOrDefault(e.slot, 0)
+ heroDamageMinuteBySlot.getOrDefault(e.slot, Collections.emptyMap())
.getOrDefault(minuteIdx, 0);
heroDamageCumBySlot.put(e.slot, dmgCum);
addIntervalData(e, output, meta, "hero_damage_t", dmgCum);
int healCum = heroHealingCumBySlot.getOrDefault(e.slot, 0)
+ heroHealingMinuteBySlot.getOrDefault(e.slot, Collections.emptyMap())
.getOrDefault(minuteIdx, 0);
heroHealingCumBySlot.put(e.slot, healCum);
addIntervalData(e, output, meta, "hero_healing_t", healCum);
}
}

Expand Down Expand Up @@ -1385,7 +1448,8 @@ private void handlePosDataTeamfight(Entry e, TeamfightPlayer player) {

// Helper methods
private boolean isArrayField(String type) {
return Arrays.asList("times", "gold_t", "lh_t", "dn_t", "xp_t", "obs_log",
return Arrays.asList("times", "gold_t", "lh_t", "dn_t", "xp_t",
"camps_stacked_t", "hero_damage_t", "hero_healing_t", "obs_log",
"sen_log", "obs_left_log", "sen_left_log", "purchase_log", "kills_log",
"buyback_log", "runes_log", "connection_log", "neutral_tokens_log",
"neutral_item_history").contains(type);
Expand Down Expand Up @@ -1424,6 +1488,12 @@ private List<Integer> getPlayerIntegerList(PlayerData player, String type) {
return player.dn_t;
case "xp_t":
return player.xp_t;
case "camps_stacked_t":
return player.camps_stacked_t;
case "hero_damage_t":
return player.hero_damage_t;
case "hero_healing_t":
return player.hero_healing_t;
default:
throw new RuntimeException("missing list type " + type);
}
Expand Down