use of com.ixale.starparse.domain.CombatSelection in project StarParse by Ixale.
the class CombatDaoImpl method getCombatStats.
private CombatStats getCombatStats(final Combat combat, final CombatSelection combatSel, final String playerName, final boolean realDuration) throws Exception {
final Map<String, Object> args = new HashMap<>();
args.put("playerName", playerName == null ? getCharacterName(combat) : playerName);
final Long timeFrom;
final String sql;
if (combatSel == null) {
sql = SQL_GET_STATS_SUMS_CACHED;
args.put("combatId", combat.getCombatId());
timeFrom = null;
} else {
final Boundaries bounds = getBoundaries(combat, combatSel);
// time from
args.put("timeFrom", bounds.timeFrom);
args.put("timeTo", bounds.timeTo);
timeFrom = bounds.timeFrom.getTime();
// events
args.put("eventIdFrom", bounds.eventIdFrom);
args.put("eventIdTo", bounds.eventIdTo);
// support for custom conditions (for challenges)
if (combatSel.getSql() != null) {
sql = SQL_GET_STATS_SUMS.substring(0, SQL_GET_STATS_SUMS.length() - 1) + " AND " + combatSel.getSql() + ")";
if (combatSel.getArgs() != null) {
args.putAll(combatSel.getArgs());
}
} else {
sql = SQL_GET_STATS_SUMS;
}
}
try {
final CombatStats stats = getJdbcTemplate().query(sql, args, rs -> {
if (!rs.next()) {
return null;
}
int duration;
if (realDuration) {
if (getTimestamp(rs, "time_to") != null && timeFrom != null) {
duration = (int) Math.max(1000, getTimestamp(rs, "time_to").getTime() - timeFrom);
} else {
duration = 1000;
}
} else {
duration = rs.getInt("duration");
}
return new CombatStats(duration, getIntSafe(rs, "actions"), getIntSafe(rs, "damage"), getIntSafe(rs, "heal"), getIntSafe(rs, "effective_heal"), getIntSafe(rs, "damage_taken"), // total = sub-total
getIntSafe(rs, "damage_taken"), getIntSafe(rs, "absorbed"), // total = sub-total
getIntSafe(rs, "absorbed"), getIntSafe(rs, "heal_taken"), getIntSafe(rs, "effective_heal_taken"), // total = sub-total
getIntSafe(rs, "effective_heal_taken"), getIntSafe(rs, "threat"), // not used in total statistics
getIntSafe(rs, "threat_positive"), rs.getString("discipline") != null ? CharacterDiscipline.valueOf(rs.getString("discipline")) : null);
});
if (stats == null && combatSel == null) {
// NPC perspective = no cached sums
return getCombatStats(combat, new CombatSelection(combat.getEventIdFrom(), combat.getEventIdTo(), null, null), playerName, realDuration);
}
return stats;
} catch (Exception e) {
throw new Exception("Unable to get combat summary (" + args + "): " + e.getMessage(), e);
}
}
use of com.ixale.starparse.domain.CombatSelection in project StarParse by Ixale.
the class CombatDaoImpl method getCombatChallengeStats.
@Override
public List<ChallengeStats> getCombatChallengeStats(final Combat combat, final CombatSelection combatSel, final String playerName) throws Exception {
if ((combat.getBoss() == null) || ((availableChallenges = combat.getBoss().getRaid().getChallenges(combat.getBoss())) == null)) {
return null;
}
phasesToChallenges.clear();
for (final CombatChallenge ch : availableChallenges) {
phasesToChallenges.put(ch.getPhaseName(), ch);
}
final Map<String, Object> args = new HashMap<>();
args.put("combatId", combat.getCombatId());
args.put("tickFrom", combatSel != null && combatSel.getTickFrom() != null ? combatSel.getTickFrom() : 0);
args.put("tickTo", combatSel != null && combatSel.getTickTo() != null ? combatSel.getTickTo() : Integer.MAX_VALUE);
args.put("phaseNames", new ArrayList<>(phasesToChallenges.keySet()));
return getJdbcTemplate().query(SQL_GET_COMBAT_CHALLENGES, args, new RowMapper<ChallengeStats>() {
Long tickFrom, tickTo;
boolean noCache = false;
@Override
public ChallengeStats mapRow(ResultSet rs, int rowNum) {
try {
noCache = false;
if (combatSel != null) {
if (combatSel.getTickFrom() != null && (combatSel.getTickFrom() > rs.getLong("tick_from"))) {
tickFrom = combatSel.getTickFrom();
noCache = true;
} else {
tickFrom = rs.getLong("tick_from");
}
if (combatSel.getTickTo() != null && (getValueOrNull(rs, rs.getLong("tick_to")) == null || context.getTickTo() < rs.getLong("tick_to"))) {
tickTo = combatSel.getTickTo();
noCache = true;
} else {
tickTo = getValueOrNull(rs, rs.getLong("tick_to"));
noCache = noCache || tickTo == null;
}
} else {
tickFrom = rs.getLong("tick_from");
tickTo = getValueOrNull(rs, rs.getLong("tick_to"));
}
if (!noCache && cachedChallenges.containsKey(combat.getCombatId())) {
if (cachedChallenges.get(combat.getCombatId()).containsKey(playerName)) {
if (cachedChallenges.get(combat.getCombatId()).get(playerName).containsKey(rs.getLong("tick_from"))) {
return cachedChallenges.get(combat.getCombatId()).get(playerName).get(rs.getLong("tick_from"));
// NOTREACHED
}
}
}
final CombatSelection challengeCombatSel = new CombatSelection(rs.getInt("event_id_from"), getValueOrNull(rs, rs.getInt("event_id_to")), tickFrom, tickTo, phasesToChallenges.get(rs.getString("name")).getArgs(), phasesToChallenges.get(rs.getString("name")).getSql());
final CombatStats stats = getCombatStats(combat, challengeCombatSel, playerName, true);
final ChallengeStats challengeStats = new ChallengeStats(phasesToChallenges.get(rs.getString("name")).getChallengeName(), tickFrom, tickFrom + stats.getTick(), stats.getDamage(), stats.getHeal(), stats.getEffectiveHeal());
if (!noCache && (getValueOrNull(rs, rs.getLong("tick_to")) != null)) {
if (!cachedChallenges.containsKey(combat.getCombatId())) {
cachedChallenges.put(combat.getCombatId(), new HashMap<>());
}
if (!cachedChallenges.get(combat.getCombatId()).containsKey(playerName)) {
cachedChallenges.get(combat.getCombatId()).put(playerName, new HashMap<>());
}
cachedChallenges.get(combat.getCombatId()).get(playerName).put(rs.getLong("tick_from"), challengeStats);
}
return challengeStats;
} catch (Exception e) {
logger.error("Unable to get combat challenge: " + e.getMessage(), e);
return null;
}
}
});
}
use of com.ixale.starparse.domain.CombatSelection in project StarParse by Ixale.
the class RaidPresenter method getDeathRecap.
private List<Event> getDeathRecap(final RaidRequest request, final String playerName) throws Exception {
final long timestamp = request.getParams().getTimestamp();
final Integer combatId = context.findCombatIdByCombatEvent(Event.Type.DEATH, timestamp, playerName);
Combat combat = null;
if (combatId != null) {
combat = eventService.findCombat(combatId);
}
if (combat == null) {
// no longer valid (another log maybe?)
return null;
}
final long deathTick = timestamp - combat.getTimeFrom();
final CombatSelection combatSel = new CombatSelection(combat.getEventIdFrom(), combat.getEventIdTo(), // last 10 seconds
deathTick > 10000 ? deathTick - 10000 : 0, deathTick);
return eventService.getCombatEvents(combat, Collections.singleton(Event.Type.SIMPLIFIED), null, null, null, combatSel, playerName).stream().filter((e) -> playerName.equals(e.getSource().getName()) || playerName.equals(e.getTarget().getName())).collect(Collectors.toList());
}
use of com.ixale.starparse.domain.CombatSelection in project StarParse by Ixale.
the class CombatDaoImpl method storeCombat.
private void storeCombat(final Combat c, boolean create, boolean close) throws Exception {
// resolve name
final String combatName = close ? getJdbcTemplate().query(SQL_GET_NAME, new Object[] { c.getEventIdFrom(), c.getEventIdTo() != null ? c.getEventIdTo() : Integer.MAX_VALUE }, rs -> rs.next() ? rs.getString("combat_name") : null) : null;
final Timestamp fromTs = new Timestamp(c.getTimeFrom());
Integer selfTick = null;
for (final Map.Entry<Actor, CharacterDiscipline> entry : context.getCombatInfo().get(c.getCombatId()).getCombatPlayers().entrySet()) {
// gather statistics
final CombatStats stats = getCombatStats(c, new CombatSelection(c.getEventIdFrom(), c.getEventIdTo(), null, null), entry.getKey().getName());
// insert or update (same structure)
final Timestamp toTs = new Timestamp(c.getTimeTo() != null ? c.getTimeTo() : c.getTimeFrom() + stats.getTick());
if (selfTick == null) {
// take first encountered (== this player)
selfTick = stats.getTick();
}
getJdbcTemplate().update(create ? SQL_INSERT_STATS : SQL_UPDATE_STATS, new Object[] { c.getEventIdFrom(), c.getEventIdTo(), fromTs, toTs, stats.getActions(), stats.getApm(), stats.getDamage(), stats.getDps(), stats.getHeal(), stats.getHps(), stats.getEffectiveHeal(), stats.getEhps(), stats.getEhpsPercent(), stats.getDamageTaken(), stats.getDtps(), stats.getAbsorbed(), stats.getAps(), stats.getHealTaken(), stats.getHpsTaken(), stats.getEhpsTaken(), stats.getEffectiveHealTakenTotal(), stats.getThreat(), stats.getThreatPositive(), stats.getTps(), entry.getValue() != null ? entry.getValue().name() : null, c.getCombatId(), entry.getKey().getName() });
}
getJdbcTemplate().update(create ? SQL_INSERT : SQL_UPDATE, new Object[] { c.getLogId(), c.getEventIdFrom(), c.getEventIdTo(), fromTs, new Timestamp(c.getTimeTo() != null ? c.getTimeTo() : c.getTimeFrom() + (selfTick == null ? 1000 : selfTick)), c.getBoss() != null ? c.getBoss().getRaid().getName() : null, c.getBoss() != null ? c.getBoss().toString() : null, combatName, c.isPvp() != null ? c.isPvp() : null, !close, c.getCombatId() });
}
Aggregations