Skip to content

Commit

Permalink
add get_commander_tag_data and get_player_death_on_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Drevarr committed Nov 21, 2024
1 parent 87ff20f commit f5bb775
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
3 changes: 2 additions & 1 deletion output_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ def write_data_to_db(top_stats: dict, last_fight: str) -> None:
print("Database updated.")


def output_top_stats_json(top_stats: dict, buff_data: dict, skill_data: dict, damage_mod_data: dict, high_scores: dict, personal_damage_mod_data: dict, fb_pages: dict, mechanics: dict, minions: dict, outfile: str) -> None:
def output_top_stats_json(top_stats: dict, buff_data: dict, skill_data: dict, damage_mod_data: dict, high_scores: dict, personal_damage_mod_data: dict, fb_pages: dict, mechanics: dict, minions: dict, death_on_tag: dict, outfile: str) -> None:
"""Print the top_stats dictionary as a JSON object to the console."""

json_dict = {}
Expand All @@ -2220,6 +2220,7 @@ def output_top_stats_json(top_stats: dict, buff_data: dict, skill_data: dict, da
json_dict["fb_pages"] = {key: value for key, value in fb_pages.items()}
json_dict["mechanics"] = {key: value for key, value in mechanics.items()}
json_dict["minions"] = {key: value for key, value in minions.items()}
json_dict["death_on_tag"] = {key: value for key, value in death_on_tag.items()}
json_dict['players_running_healing_addon'] = top_stats['players_running_healing_addon']
with open(outfile, 'w') as json_file:
json.dump(json_dict, json_file, indent=4)
Expand Down
114 changes: 112 additions & 2 deletions parser_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

players_running_healing_addon = []

On_Tag = 600
Run_Back = 5000
death_on_tag = {}
commander_tag_positions = {}


def determine_log_type_and_extract_fight_name(fight_name: str) -> tuple:
"""
Expand Down Expand Up @@ -128,6 +133,106 @@ def determine_player_role(player_data: dict) -> str:
return "DPS"


def get_commander_tag_data(fight_json):
"""Get commander tag data from the fight json."""

commander_tag_data = {}
dead_tag_mark = 999999999
dead_tag = 0

for player in fight_json["players"]:
if player["hasCommanderTag"] and not player["notInSquad"]:
commander_tag_data = player["combatReplayData"]
commander_tag_positions = commander_tag_data["positions"]

if commander_tag_data["dead"]:
for death in commander_tag_data["dead"]:
if death[0] <= 0:
continue
dead_tag_mark = min(death[0], dead_tag_mark)
dead_tag = 1
break

return commander_tag_positions, dead_tag_mark, dead_tag


def get_player_death_on_tag(player, commander_tag_positions, dead_tag_mark, dead_tag, inch_to_pixel, polling_rate):
name_prof = player['name'] + "|" + player['profession']
if name_prof not in death_on_tag:
death_on_tag[name_prof] = {
"name": player['name'],
"profession": player['profession'],
"distToTag": [],
"On_Tag": 0,
"Off_Tag": 0,
"Run_Back": 0,
"After_Tag_Death": 0,
"Total": 0,
"Ranges": [],
}

if player['combatReplayData']['dead'] and player['combatReplayData']['down']:
player_deaths = dict(player['combatReplayData']['dead'])
player_downs = dict(player['combatReplayData']['down'])
player_dist_to_tag = player['statsAll'][0]['distToCom']

for death_key, death_value in player_deaths.items():
if death_key < 0: # Handle death on the field before main squad combat log starts
continue

position_mark = math.ceil(death_key / polling_rate)
player_positions = player['combatReplayData']['positions']

for down_key, down_value in player_downs.items():
if death_key == down_value:
# process data for downKey
x1, y1 = player_positions[position_mark]
#y1 = player_positions[position_mark][1]
x2, y2 = commander_tag_positions[position_mark]
#y2 = commander_tag_positions[position_mark][1]
death_distance = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
death_range = death_distance / inch_to_pixel

death_on_tag[name_prof]["Total"] += 1

if int(down_key) > int(dead_tag_mark) and dead_tag:
death_on_tag[name_prof]["After_Tag_Death"] += 1

# Calc Avg distance through dead tag final mark
player_dead_poll = int(dead_tag_mark / polling_rate)
player_distances = []
for position, tag_position in zip(player_positions[:player_dead_poll], commander_tag_positions[:player_dead_poll]):
delta_x = position[0] - tag_position[0]
delta_y = position[1] - tag_position[1]
player_distances.append(math.sqrt(delta_x * delta_x + delta_y * delta_y))

player_dist_to_tag = (sum(player_distances) / len(player_distances)) / inch_to_pixel
else:
player_dead_poll = position_mark
player_positions = player['combatReplayData']['positions']
player_distances = []
for position, tag_position in zip(player_positions[:player_dead_poll], commander_tag_positions[:player_dead_poll]):
delta_x = position[0] - tag_position[0]
delta_y = position[1] - tag_position[1]
player_distances.append(math.sqrt(delta_x * delta_x + delta_y * delta_y))

player_dist_to_tag = (sum(player_distances) / len(player_distances)) / inch_to_pixel

if death_range <= On_Tag:
death_on_tag[name_prof]["On_Tag"] += 1

if death_range > On_Tag and death_range <= Run_Back:
death_on_tag[name_prof]["Off_Tag"] += 1
death_on_tag[name_prof]["Ranges"].append(death_range)

if death_range > Run_Back:
death_on_tag[name_prof]["Run_Back"] += 1

if player_dist_to_tag <= Run_Back:
death_on_tag[name_prof]["distToTag"].append(player_dist_to_tag)



def get_player_fight_dps(dpsTargets: dict, name: str, profession: str, fight_num: int, fight_time: int) -> None:
"""
Get the maximum damage hit by skill.
Expand Down Expand Up @@ -1219,7 +1324,10 @@ def parse_file(file_path, fight_num, guild_data):
'enemy_Blue': 0,
'enemy_Unk': 0,
}


#get commander data
commander_tag_positions, dead_tag_mark, dead_tag = get_commander_tag_data(json_data)

#collect player counts and parties
get_parties_by_fight(fight_num, players)

Expand Down Expand Up @@ -1274,7 +1382,7 @@ def parse_file(file_path, fight_num, guild_data):
else:
guild_id = None

if tag:
if tag: #Commander Tracking
top_stats['fight'][fight_num]['commander'] = name_prof

if guild_data:
Expand Down Expand Up @@ -1307,6 +1415,8 @@ def parse_file(file_path, fight_num, guild_data):

get_minions_by_player(player, name, profession)

get_player_death_on_tag(player, commander_tag_positions, dead_tag_mark, dead_tag, inches_to_pixel, polling_rate)

# Cumulative group and squad supported counts
top_stats['player'][name_prof]['num_fights'] = top_stats['player'][name_prof].get('num_fights', 0) + 1
top_stats['player'][name_prof]['group_supported'] = top_stats['player'][name_prof].get('group_supported', 0) + group_count
Expand Down
2 changes: 1 addition & 1 deletion tw5_top_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
write_tid_list_to_json(tid_list, args.output_filename)

if write_all_data_to_json:
output_top_stats_json(top_stats, buff_data, skill_data, damage_mod_data, high_scores, personal_damage_mod_data, fb_pages, mechanics, minions, args.json_output_filename)
output_top_stats_json(top_stats, buff_data, skill_data, damage_mod_data, high_scores, personal_damage_mod_data, fb_pages, mechanics, minions, death_on_tag, args.json_output_filename)

if db_update:
write_data_to_db(top_stats, top_stats['overall']['last_fight'])

0 comments on commit f5bb775

Please sign in to comment.