Skip to content

Commit

Permalink
Fixing issue with Wildfire not counting in some cases
Browse files Browse the repository at this point in the history
If Wildfire was cast within 60s of the end of a tether window, the total window examined for tick damage, then it would overwrite the start time and suddenly appear to be outside the window. This will also recompute logs not computed since this update
  • Loading branch information
xephero committed Mar 11, 2018
1 parent caffeaf commit 0a5f34b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
19 changes: 14 additions & 5 deletions app.py
@@ -1,10 +1,11 @@
from datetime import datetime
import os
from urllib.parse import urlparse, parse_qs

from flask import Flask, render_template, request, redirect, send_from_directory, url_for
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import IntegrityError
from tethercalc import tethercalc, get_encounter_info, get_last_fight_id, TetherCalcException
from tethercalc import tethercalc, get_last_fight_id, TetherCalcException

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
Expand All @@ -19,6 +20,7 @@ class Report(db.Model):
enc_name = db.Column(db.String(64))
enc_time = db.Column(db.String(9))
enc_kill = db.Column(db.Boolean)
computed = db.Column(db.DateTime, server_default=db.func.now())

def decompose_url(url):
parts = urlparse(url)
Expand Down Expand Up @@ -69,13 +71,20 @@ def calc(report_id, fight_id):
report = Report.query.filter_by(report_id=report_id, fight_id=fight_id).first()

if report:
# Get encounter info if it doesn't exist yet
if not report.enc_name or not report.enc_time or not report.enc_kill:
encounter_info = get_encounter_info(report_id, fight_id)

# Recompute if no computed timestamp
if not report.computed:
try:
results, friends, encounter_info = tethercalc(report_id, fight_id)
except TetherCalcException as exception:
return render_template('error.html', exception=exception)

report.results = results
report.friends = friends
report.enc_name = encounter_info['enc_name']
report.enc_time = encounter_info['enc_time']
report.enc_kill = encounter_info['enc_kill']
report.computed = datetime.now()

db.session.commit()

# These get returned with string keys, so have to massage it some
Expand Down
29 changes: 9 additions & 20 deletions tethercalc.py
Expand Up @@ -166,11 +166,15 @@ def get_tick_damages(report, start, end):
wildfire = {}

if event['type'] == 'applydebuff':
wildfire['start'] = event['timestamp']
if 'start' not in wildfire:
wildfire['start'] = event['timestamp']
elif event['type'] == 'removedebuff':
wildfire['end'] = event['timestamp']
if 'end' not in wildfire:
# Effective WF duration is 9.25
wildfire['end'] = event['timestamp'] - 750
elif event['type'] == 'damage':
wildfire['damage'] = event['amount']
if 'damage' not in wildfire:
wildfire['damage'] = event['amount']

wildfire['target'] = event['targetID']

Expand Down Expand Up @@ -229,11 +233,11 @@ def get_tick_damages(report, start, end):
wildfire['start'] = start
# If wildfire ended after dragon sight, the end will be tether end
if wildfire['end'] > end:
wildfire['end'] = end + 750
wildfire['end'] = end

# Set up query for applicable mch damage
options['start'] = wildfire['start']
options['end'] = wildfire['end'] - 750 # Real WF effect is only 9.25s
options['end'] = wildfire['end']

# Only damage on the WF target by the player, not the turret
options['filter'] = 'source.type!="pet"'
Expand Down Expand Up @@ -395,18 +399,3 @@ def get_last_fight_id(report):
report_data = fflogs_api('fights', report)

return report_data['fights'][-1]['id']

def get_encounter_info(report, fight_id):
"""Get the encounter information about a report"""
report_data = fflogs_api('fights', report)

fight = [fight for fight in report_data['fights'] if fight['id'] == fight_id][0]
timing = timedelta(milliseconds=fight['end_time']-fight['start_time'])

encounter_info = {
'enc_name': fight['name'],
'enc_time': str(timing)[2:11],
'enc_kill': fight['kill'] if 'kill' in fight else False,
}

return encounter_info

0 comments on commit 0a5f34b

Please sign in to comment.