-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_functions.py
1742 lines (1434 loc) · 66.4 KB
/
parser_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file contains the configuration for computing the detailed top stats in arcdps logs as parsed by Elite Insights.
# Copyright (C) 2024 John Long (Drevarr)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import config
import gzip
import json
import math
import requests
# Top stats dictionary to store combined log data
top_stats = config.top_stats
team_colors = config.team_colors
# Buff and skill data collected from al logs
buff_data = {}
skill_data = {}
damage_mod_data = {}
high_scores = {}
fb_pages = {}
mechanics = {}
minions = {}
personal_damage_mod_data = {
"total": [],
}
personal_buff_data = {
"total": [],
}
players_running_healing_addon = []
On_Tag = 600
Run_Back = 5000
death_on_tag = {}
commander_tag_positions = {}
DPSStats = {}
def determine_log_type_and_extract_fight_name(fight_name: str) -> tuple:
"""
Determine if the log is a PVE or WVW log and extract the fight name.
If the log is a WVW log, the fight name is extracted after the " - " delimiter.
If the log is a PVE log, the original fight name is returned.
Args:
fight_name (str): The name of the fight.
Returns:
tuple: A tuple containing the log type and the extracted fight name.
"""
if "Detailed WvW" in fight_name:
# WVW log
log_type = "WVW"
fight_name = fight_name.split(" - ")[1]
elif "World vs World" in fight_name:
# WVW log
log_type = "WVW-Not-Detailed"
fight_name = fight_name.split(" - ")[1]
elif "Detailed" in fight_name:
log_type = "WVW"
fight_name = fight_name.replace("Detailed ", "")
else:
# PVE log
log_type = "PVE"
return log_type, fight_name
def calculate_moving_average(data: list, window_size: int) -> list:
"""
Calculate the moving average of a list of numbers with a specified window size.
Args:
data (list): The list of numbers to calculate the moving average for.
window_size (int): The number of elements to include in the moving average calculation.
Returns:
list: A list of the moving averages for each element in the input list.
"""
ma = []
for i in range(len(data)):
start_index = max(0, i - window_size)
end_index = min(len(data), i + window_size)
sub_data = data[start_index:end_index + 1]
ma.append(sum(sub_data) / len(sub_data))
return ma
def update_high_score(stat_name: str, key: str, value: float) -> None:
"""
Update the high scores dictionary with a new value if it is higher than the current lowest value.
Args:
stat_name (str): The name of the stat to update.
key (str): The key to store the value under.
value (float): The value to store.
Returns:
None
"""
if stat_name not in high_scores:
high_scores[stat_name] = {}
if len(high_scores[stat_name]) < 5 or value > min(high_scores[stat_name].values()):
if len(high_scores[stat_name]) == 5:
lowest_key = min(high_scores[stat_name], key=high_scores[stat_name].get)
del high_scores[stat_name][lowest_key]
high_scores[stat_name][key] = value
def determine_player_role(player_data: dict) -> str:
"""
Determine the role of a player in combat based on their stats.
Args:
player_data (dict): The player data.
Returns:
str: The role of the player.
"""
crit_rate = player_data["statsAll"][0]["criticalRate"]
total_dps = player_data["dpsAll"][0]["damage"]
power_dps = player_data["dpsAll"][0]["powerDamage"]
condi_dps = player_data["dpsAll"][0]["condiDamage"]
if "extHealingStats" in player_data:
total_healing = player_data["extHealingStats"]["outgoingHealing"][0]["healing"]
else:
total_healing = 0
if "extBarrierStats" in player_data:
total_barrier = player_data["extBarrierStats"]["outgoingBarrier"][0]["barrier"]
else:
total_barrier = 0
if total_healing > total_dps:
return "Support"
if total_barrier > total_dps:
return "Support"
if condi_dps > power_dps:
return "Condi"
if crit_rate <= 40:
return "Support"
else:
return "DPS"
def get_commander_tag_data(fight_json):
"""Extract commander tag data from the fight JSON."""
commander_tag_positions = []
earliest_death_time = fight_json['durationMS']
has_died = False
for player in fight_json["players"]:
if player["hasCommanderTag"] and not player["notInSquad"]:
replay_data = player.get("combatReplayData", {})
commander_tag_positions = replay_data.get("positions", [])
for death_time, _ in replay_data.get("dead", []):
if death_time > 0:
earliest_death_time = min(death_time, earliest_death_time)
has_died = True
break
return commander_tag_positions, earliest_death_time, has_died
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": [],
}
player_dist_to_tag = round(player['statsAll'][0]['distToCom'])
if player['combatReplayData']['dead'] and player['combatReplayData']['down']:
player_deaths = dict(player['combatReplayData']['dead'])
player_downs = dict(player['combatReplayData']['down'])
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.floor(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 = round(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 = round((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 = round((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.
Args:
fight_data (dict): The fight data.
"""
target_damage = 0
for target in dpsTargets:
target_damage += target[0]["damage"]
target_damage = round(target_damage / fight_time,2)
update_high_score(
"fight_dps",
"{{"+profession+"}}"+name+"-"+str(fight_num)+" | DPS",
target_damage
)
def get_combat_start_from_player_json(initial_time, player_json):
start_combat = -1
# TODO check healthPercents exists
last_health_percent = 100
for change in player_json['healthPercents']:
if change[0] < initial_time:
last_health_percent = change[1]
continue
if change[1] - last_health_percent < 0:
# got dmg
start_combat = change[0]
break
last_health_percent = change[1]
for i in range(math.ceil(initial_time/1000), len(player_json['damage1S'][0])):
if i == 0:
continue
if player_json['powerDamage1S'][0][i] != player_json['powerDamage1S'][0][i-1]:
if start_combat == -1:
start_combat = i*1000
else:
start_combat = min(start_combat, i*1000)
break
return start_combat
def get_combat_time_breakpoints(player_json):
start_combat = get_combat_start_from_player_json(0, player_json)
if 'combatReplayData' not in player_json:
print("WARNING: combatReplayData not in json, using activeTimes as time in combat")
return [start_combat, player_json.get('activeTimes', 0)]
replay = player_json['combatReplayData']
if 'dead' not in replay:
return [start_combat, player_json.get('activeTimes', 0)]
breakpoints = []
playerDeaths = dict(replay['dead'])
playerDowns = dict(replay['down'])
for deathKey, deathValue in playerDeaths.items():
for downKey, downValue in playerDowns.items():
if deathKey == downValue:
if start_combat != -1:
breakpoints.append([start_combat, deathKey])
start_combat = get_combat_start_from_player_json(deathValue + 1000, player_json)
break
end_combat = (len(player_json['damage1S'][0]))*1000
if start_combat != -1:
breakpoints.append([start_combat, end_combat])
return breakpoints
def sum_breakpoints(breakpoints):
combat_time = 0
for [start, end] in breakpoints:
combat_time += end - start
return combat_time
def calculate_dps_stats(fight_json):
fight_ticks = len(fight_json['players'][0]["damage1S"][0])
duration = round(fight_json['durationMS']/1000)
damage_ps = {}
for index, target in enumerate(fight_json['targets']):
if 'enemyPlayer' in target and target['enemyPlayer'] == True:
for player in fight_json['players']:
if player['notInSquad']:
continue
player_prof_name = player['profession'] + " " + player['name']
if player_prof_name not in damage_ps:
damage_ps[player_prof_name] = [0] * fight_ticks
damage_on_target = player["targetDamage1S"][index][0]
for i in range(fight_ticks):
damage_ps[player_prof_name][i] += damage_on_target[i]
squad_damage_per_tick = []
for fight_tick in range(fight_ticks - 1):
squad_damage_on_tick = 0
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
player_damage = damage_ps[player_prof_name]
squad_damage_on_tick += player_damage[fight_tick + 1] - player_damage[fight_tick]
squad_damage_per_tick.append(squad_damage_on_tick)
squad_damage_total = sum(squad_damage_per_tick)
squad_damage_per_tick_ma = calculate_moving_average(squad_damage_per_tick, 1)
squad_damage_ma_total = sum(squad_damage_per_tick_ma)
CHUNK_DAMAGE_SECONDS = 21
ch5_ca_damage_1s = {}
for player in fight_json['players']:
if player['notInSquad']:
continue
player_prof_name = player['profession'] + " " + player['name']
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
if player_prof_name not in DPSStats:
DPSStats[player_prof_name] = {
"account": player["account"],
"name": player["name"],
"profession": player["profession"],
"duration": 0,
"combatTime": 0,
"coordinationDamage": 0,
"chunkDamage": [0] * CHUNK_DAMAGE_SECONDS,
"chunkDamageTotal": [0] * CHUNK_DAMAGE_SECONDS,
"carrionDamage": 0,
"carrionDamageTotal": 0,
"damageTotal": 0,
"squadDamageTotal": 0,
"burstDamage": [0] * CHUNK_DAMAGE_SECONDS,
"ch5CaBurstDamage": [0] * CHUNK_DAMAGE_SECONDS,
"downs": 0,
"kills": 0,
}
ch5_ca_damage_1s[player_prof_name] = [0] * fight_ticks
player_damage = damage_ps[player_prof_name]
DPSStats[player_prof_name]["duration"] += duration
DPSStats[player_prof_name]["combatTime"] += combat_time
DPSStats[player_prof_name]["damageTotal"] += player_damage[fight_ticks - 1]
DPSStats[player_prof_name]["squadDamageTotal"] += squad_damage_total
for stats_target in player["statsTargets"]:
DPSStats[player_prof_name]["downs"] += stats_target[0]['downed']
DPSStats[player_prof_name]["kills"] += stats_target[0]['killed']
# Coordination_Damage: Damage weighted by coordination with squad
player_damage_per_tick = [player_damage[0]]
for fight_tick in range(fight_ticks - 1):
player_damage_per_tick.append(player_damage[fight_tick + 1] - player_damage[fight_tick])
player_damage_ma = calculate_moving_average(player_damage_per_tick, 1)
for fight_tick in range(fight_ticks - 1):
player_damage_on_tick = player_damage_ma[fight_tick]
if player_damage_on_tick == 0:
continue
squad_damage_on_tick = squad_damage_per_tick_ma[fight_tick]
if squad_damage_on_tick == 0:
continue
squad_damage_percent = squad_damage_on_tick / squad_damage_ma_total
DPSStats[player_prof_name]["coordinationDamage"] += player_damage_on_tick * squad_damage_percent * duration
# Chunk damage: Damage done within X seconds of target down
for index, target in enumerate(fight_json['targets']):
if 'enemyPlayer' in target and target['enemyPlayer'] == True and 'combatReplayData' in target and len(target['combatReplayData']['down']):
for chunk_damage_seconds in range(1, CHUNK_DAMAGE_SECONDS):
targetDowns = dict(target['combatReplayData']['down'])
for targetDownsIndex, (downKey, downValue) in enumerate(targetDowns.items()):
downIndex = math.ceil(downKey / 1000)
startIndex = max(0, math.ceil(downKey / 1000) - chunk_damage_seconds)
if targetDownsIndex > 0:
lastDownKey, lastDownValue = list(targetDowns.items())[targetDownsIndex - 1]
lastDownIndex = math.ceil(lastDownKey / 1000)
if lastDownIndex == downIndex:
# Probably an ele in mist form
continue
startIndex = max(startIndex, lastDownIndex)
squad_damage_on_target = 0
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
damage_on_target = player["targetDamage1S"][index][0]
player_damage = damage_on_target[downIndex] - damage_on_target[startIndex]
DPSStats[player_prof_name]["chunkDamage"][chunk_damage_seconds] += player_damage
squad_damage_on_target += player_damage
if chunk_damage_seconds == 5:
for i in range(startIndex, downIndex):
ch5_ca_damage_1s[player_prof_name][i] += damage_on_target[i + 1] - damage_on_target[i]
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
DPSStats[player_prof_name]["chunkDamageTotal"][chunk_damage_seconds] += squad_damage_on_target
# Carrion damage: damage to downs that die
for index, target in enumerate(fight_json['targets']):
if 'enemyPlayer' in target and target['enemyPlayer'] == True and 'combatReplayData' in target and len(target['combatReplayData']['dead']):
targetDeaths = dict(target['combatReplayData']['dead'])
targetDowns = dict(target['combatReplayData']['down'])
for deathKey, deathValue in targetDeaths.items():
for downKey, downValue in targetDowns.items():
if deathKey == downValue:
dmgEnd = math.ceil(deathKey / 1000)
dmgStart = math.ceil(downKey / 1000)
total_carrion_damage = 0
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
damage_on_target = player["targetDamage1S"][index][0]
carrion_damage = damage_on_target[dmgEnd] - damage_on_target[dmgStart]
DPSStats[player_prof_name]["carrionDamage"] += carrion_damage
total_carrion_damage += carrion_damage
for i in range(dmgStart, dmgEnd):
ch5_ca_damage_1s[player_prof_name][i] += damage_on_target[i + 1] - damage_on_target[i]
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
DPSStats[player_prof_name]["carrionDamageTotal"] += total_carrion_damage
# Burst damage: max damage done in n seconds
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
player_damage = damage_ps[player_prof_name]
for i in range(1, CHUNK_DAMAGE_SECONDS):
for fight_tick in range(i, fight_ticks):
dmg = player_damage[fight_tick] - player_damage[fight_tick - i]
DPSStats[player_prof_name]["burstDamage"][i] = max(dmg, DPSStats[player_prof_name]["burstDamage"][i])
# Ch5Ca Burst damage: max damage done in n seconds
for player in fight_json['players']:
if player['notInSquad']:
continue
combat_time = round(sum_breakpoints(get_combat_time_breakpoints(player)) / 1000)
if combat_time:
player_prof_name = player['profession'] + " " + player['name']
player_damage_ps = ch5_ca_damage_1s[player_prof_name]
player_damage = [0] * len(player_damage_ps)
player_damage[0] = player_damage_ps[0]
for i in range(1, len(player_damage)):
player_damage[i] = player_damage[i - 1] + player_damage_ps[i]
for i in range(1, CHUNK_DAMAGE_SECONDS):
for fight_tick in range(i, fight_ticks):
dmg = player_damage[fight_tick] - player_damage[fight_tick - i]
DPSStats[player_prof_name]["ch5CaBurstDamage"][i] = max(dmg, DPSStats[player_prof_name]["ch5CaBurstDamage"][i])
def get_player_stats_targets(statsTargets: dict, name: str, profession: str, fight_num: int, fight_time: int) -> None:
fight_stat_value= 0
fight_stats = ["killed", "downed", "downContribution", "appliedCrowdControl"]
for stat in fight_stats:
for target in statsTargets:
if target[0]:
fight_stat_value += target[0][stat]
fight_stat_value = round(fight_stat_value / fight_time, 3)
update_high_score(f"statTarget_{stat}", "{{"+profession+"}}"+name+"-"+str(fight_num)+" | "+stat, fight_stat_value)
def get_total_shield_damage(fight_data: dict) -> int:
"""
Extract the total shield damage from the fight data.
Args:
fight_data (dict): The fight data.
Returns:
int: The total shield damage.
"""
total_shield_damage = 0
for skill in fight_data["targetDamageDist"]:
total_shield_damage += skill["shieldDamage"]
return total_shield_damage
def get_buffs_data(buff_map: dict) -> None:
"""
Collect buff data across all fights.
Args:
buff_map (dict): The dictionary of buff data.
"""
for buff in buff_map:
buff_id = buff
name = buff_map[buff]['name']
stacking = buff_map[buff]['stacking']
if 'icon' in buff_map[buff]:
icon = buff_map[buff]['icon']
else:
icon = "unknown.png"
if buff_id not in buff_data:
buff_data[buff_id] = {
'name': name,
'stacking': stacking,
'icon': icon
}
def get_skills_data(skill_map: dict) -> None:
"""
Collect skill data across all fights.
Args:
skill_map (dict): The dictionary of skill data.
"""
for skill in skill_map:
skill_id = skill
name = skill_map[skill]['name']
auto_attack = skill_map[skill]['autoAttack']
if 'icon' in skill_map[skill]:
icon = skill_map[skill]['icon']
else:
icon = "unknown.png"
if skill_id not in skill_data:
skill_data[skill_id] = {
'name': name,
'auto': auto_attack,
'icon': icon
}
def get_damage_mods_data(damage_mod_map: dict, personal_damage_mod_data: dict) -> None:
"""
Collect damage mod data across all fights.
Args:
damage_mod_map (dict): The dictionary of damage mod data.
"""
for mod in damage_mod_map:
name = damage_mod_map[mod]['name']
icon = damage_mod_map[mod]['icon']
if 'incoming' in damage_mod_map[mod]:
incoming = damage_mod_map[mod]['incoming']
else:
incoming = False
shared = False
if mod in personal_damage_mod_data['total']:
shared = False
else:
shared = True
if mod not in damage_mod_data:
damage_mod_data[mod] = {
'name': name,
'icon': icon,
'shared': shared,
'incoming': incoming
}
def get_personal_mod_data(personal_damage_mods: dict) -> None:
"""
Populate the personal_damage_mod_data dictionary with modifiers from personal_damage_mods.
Args:
personal_damage_mods (dict): A dictionary where keys are professions and values are lists of modifier IDs.
"""
for profession, mods in personal_damage_mods.items():
if profession not in personal_damage_mod_data:
personal_damage_mod_data[profession] = []
for mod_id in mods:
mod_id = "d" + str(mod_id)
if mod_id not in personal_damage_mod_data[profession]:
personal_damage_mod_data[profession].append(mod_id)
personal_damage_mod_data['total'].append(mod_id)
def get_personal_buff_data(personal_buffs: dict) -> None:
"""
Populate the personal_buff_data dictionary with buffs from personal_buffs.
Args:
personal_buffs (dict): A dictionary where keys are professions and values are lists of buff IDs.
"""
for profession, buffs in personal_buffs.items():
if profession not in personal_buff_data:
personal_buff_data[profession] = []
for buff_id in buffs:
# Convert the buff ID to the format used in buff_data
buff_id = "b" + str(buff_id)
if buff_id not in personal_buff_data[profession]:
personal_buff_data[profession].append(buff_id)
# Add the buff to the total list
personal_buff_data['total'].append(buff_id)
def get_enemies_by_fight(fight_num: int, targets: dict) -> None:
"""
Organize targets by enemy for a fight.
Args:
fight_num (int): The number of the fight.
targets (list): The list of targets in the fight.
"""
if fight_num not in top_stats["fight"]:
top_stats["fight"][fight_num] = {}
if fight_num not in top_stats["enemies_by_fight"]:
top_stats["enemies_by_fight"][fight_num] = {}
for target in targets:
if target["isFake"]:
continue
if target['enemyPlayer']:
team = target["teamID"]
enemy_prof = target['name'].split(" ")[0]
if team in team_colors:
team = "enemy_" + team_colors[team]
else:
team = "enemy_Unk"
if team not in top_stats["fight"][fight_num]:
# Create a new team if it doesn't exist
top_stats["fight"][fight_num][team] = 0
if enemy_prof not in top_stats["enemies_by_fight"][fight_num]:
top_stats["enemies_by_fight"][fight_num][enemy_prof] = 0
top_stats["enemies_by_fight"][fight_num][enemy_prof] += 1
top_stats["fight"][fight_num][team] += 1
top_stats["fight"][fight_num]["enemy_count"] += 1
top_stats['overall']['enemy_count'] = top_stats['overall'].get('enemy_count', 0) + 1
def get_enemy_downed_and_killed_by_fight(fight_num: int, targets: dict, players: dict, log_type: str) -> None:
"""
Count enemy downed and killed for a fight.
Args:
fight_num (int): The number of the fight.
targets (list): The list of targets in the fight.
"""
enemy_downed = 0
enemy_killed = 0
if fight_num not in top_stats["fight"]:
top_stats["fight"][fight_num] = {}
if log_type == "WVW": # WVW doesn't have target[defense] data, must be "Detailed WvW" or "PVE"
for target in targets:
if target["isFake"]:
continue
if target['defenses'][0]['downCount']:
enemy_downed += target['defenses'][0]['downCount']
if target['defenses'][0]['deadCount']:
enemy_killed += target['defenses'][0]['deadCount']
else:
for player in players:
enemy_downed += sum(enemy[0]['downed'] for enemy in player['statsTargets'])
enemy_killed += sum(enemy[0]['killed'] for enemy in player['statsTargets'])
top_stats["fight"][fight_num]["enemy_downed"] = enemy_downed
top_stats["fight"][fight_num]["enemy_killed"] = enemy_killed
top_stats['overall']['enemy_downed'] = top_stats['overall'].get('enemy_downed', 0) + enemy_downed
top_stats['overall']['enemy_killed'] = top_stats['overall'].get('enemy_killed', 0) + enemy_killed
def get_parties_by_fight(fight_num: int, players: list) -> None:
"""
Organize players by party for a fight.
Args:
fight_num (int): The number of the fight.
players (list): The list of players in the fight.
"""
if fight_num not in top_stats["parties_by_fight"]:
top_stats["parties_by_fight"][fight_num] = {}
for player in players:
if player["notInSquad"]:
# Count players not in a squad
top_stats["fight"][fight_num]["non_squad_count"] += 1
continue
top_stats["fight"][fight_num]["squad_count"] += 1
group = player["group"]
name = player["name"]
profession = player["profession"]
prof_name = profession+"|"+name
if group not in top_stats["parties_by_fight"][fight_num]:
# Create a new group if it doesn't exist
top_stats["parties_by_fight"][fight_num][group] = []
if prof_name not in top_stats["parties_by_fight"][fight_num][group]:
# Add the player to the group
top_stats["parties_by_fight"][fight_num][group].append(prof_name)
def get_stat_by_key(fight_num: int, player: dict, stat_category: str, name_prof: str) -> None:
"""
Add player stats by key to top_stats dictionary
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
"""
for stat, value in player[stat_category][0].items():
if stat in config.high_scores:
active_time_seconds = player['activeTimes'][0] / 1000
high_score_value = round(value / active_time_seconds, 3) if active_time_seconds > 0 else 0
update_high_score(f"{stat_category}_{stat}", "{{"+player["profession"]+"}}"+player["name"]+"-"+str(fight_num)+" | "+stat, high_score_value)
top_stats['player'][name_prof][stat_category][stat] = top_stats['player'][name_prof][stat_category].get(stat, 0) + value
top_stats['fight'][fight_num][stat_category][stat] = top_stats['fight'][fight_num][stat_category].get(stat, 0) + value
top_stats['overall'][stat_category][stat] = top_stats['overall'][stat_category].get(stat, 0) + value
def get_stat_by_target_and_skill(fight_num: int, player: dict, stat_category: str, name_prof: str) -> None:
"""
Add player stats by target and skill to top_stats dictionary
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
"""
for target in player[stat_category]:
if target[0]:
for skill in target[0]:
skill_id = skill['id']
if skill_id not in top_stats['player'][name_prof][stat_category]:
top_stats['player'][name_prof][stat_category][skill_id] = {}
if skill_id not in top_stats['fight'][fight_num][stat_category]:
top_stats['fight'][fight_num][stat_category][skill_id] = {}
if skill_id not in top_stats['overall'][stat_category]:
top_stats['overall'][stat_category][skill_id] = {}
for stat, value in skill.items():
if stat == 'max':
update_high_score(f"statTarget_{stat}", "{{"+player["profession"]+"}}"+player["name"]+"-"+str(fight_num)+" | "+str(skill_id), value)
if value > top_stats['player'][name_prof][stat_category][skill_id].get(stat, 0):
top_stats['player'][name_prof][stat_category][skill_id][stat] = value
top_stats['fight'][fight_num][stat_category][skill_id][stat] = value
top_stats['overall'][stat_category][skill_id][stat] = value
elif stat == 'min':
if value <= top_stats['player'][name_prof][stat_category][skill_id].get(stat, 0):
top_stats['player'][name_prof][stat_category][skill_id][stat] = value
top_stats['fight'][fight_num][stat_category][skill_id][stat] = value
top_stats['overall'][stat_category][skill_id][stat] = value
elif stat not in ['id', 'max', 'min']:
top_stats['player'][name_prof][stat_category][skill_id][stat] = top_stats['player'][name_prof][stat_category][skill_id].get(
stat, 0) + value
top_stats['fight'][fight_num][stat_category][skill_id][stat] = top_stats['fight'][fight_num][stat_category][skill_id].get(
stat, 0) + value
top_stats['overall'][stat_category][skill_id][stat] = top_stats['overall'][stat_category][skill_id].get(stat, 0) + value
def get_stat_by_target(fight_num: int, player: dict, stat_category: str, name_prof: str) -> None:
"""
Add player stats by target to top_stats dictionary
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
"""
if stat_category not in top_stats['player'][name_prof]:
top_stats['player'][name_prof][stat_category] = {}
for target in player[stat_category]:
if target[0]:
for stat, value in target[0].items():
top_stats['player'][name_prof][stat_category][stat] = top_stats['player'][name_prof][stat_category].get(stat, 0) + value
top_stats['fight'][fight_num][stat_category][stat] = top_stats['fight'][fight_num][stat_category].get(stat, 0) + value
top_stats['overall'][stat_category][stat] = top_stats['overall'][stat_category].get(stat, 0) + value
def get_stat_by_skill(fight_num: int, player: dict, stat_category: str, name_prof: str) -> None:
"""
Add player stats by skill to top_stats dictionary
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
"""
for skill in player[stat_category][0]:
if skill:
skill_id = skill['id']
if skill_id not in top_stats['player'][name_prof][stat_category]:
top_stats['player'][name_prof][stat_category][skill_id] = {}
if skill_id not in top_stats['fight'][fight_num][stat_category]:
top_stats['fight'][fight_num][stat_category][skill_id] = {}
if skill_id not in top_stats['overall'][stat_category]:
top_stats['overall'][stat_category][skill_id] = {}
for stat, value in skill.items():
if stat != 'id':
if stat == 'max':
update_high_score(f"{stat_category}_{stat}", "{{"+player["profession"]+"}}"+player["name"]+"-"+str(fight_num)+" | "+str(skill_id), value)
top_stats['player'][name_prof][stat_category][skill_id][stat] = top_stats['player'][name_prof][stat_category][skill_id].get(stat, 0) + value
top_stats['fight'][fight_num][stat_category][skill_id][stat] = top_stats['fight'][fight_num][stat_category][skill_id].get(stat, 0) + value
top_stats['overall'][stat_category][skill_id][stat] = top_stats['overall'][stat_category][skill_id].get(stat, 0) + value
def get_buff_uptimes(fight_num: int, player: dict, group: str, stat_category: str, name_prof: str, fight_duration: int, active_time: int) -> None:
"""
Calculate buff uptime stats for a player
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
fight_duration (int): The duration of the fight in milliseconds.
active_time (int): The duration of the player's active time in milliseconds.
Returns:
None
"""
for buff in player[stat_category]:
buff_id = 'b'+str(buff['id'])
buff_uptime_ms = buff['buffData'][0]['uptime'] * fight_duration / 100
buff_presence = buff['buffData'][0]['presence']
state_changes = len(buff['states'])//2
if buff_id not in top_stats['player'][name_prof][stat_category]:
top_stats['player'][name_prof][stat_category][buff_id] = {}
if buff_id not in top_stats['fight'][fight_num][stat_category]:
top_stats['fight'][fight_num][stat_category][buff_id] = {}
if buff_id not in top_stats['overall'][stat_category]:
top_stats['overall'][stat_category][buff_id] = {}
if "group" not in top_stats['overall'][stat_category]:
top_stats['overall'][stat_category]["group"] = {}
if group not in top_stats['overall'][stat_category]["group"]:
top_stats['overall'][stat_category]["group"][group] = {}
if buff_id not in top_stats['overall'][stat_category]["group"][group]:
top_stats['overall'][stat_category]["group"][group][buff_id] = {}
if stat_category == 'buffUptimes':
stat_value = buff_presence * fight_duration / 100 if buff_presence else buff_uptime_ms
elif stat_category == 'buffUptimesActive':
stat_value = buff_presence * active_time / 100 if buff_presence else buff_uptime_ms
top_stats['player'][name_prof][stat_category][buff_id]['uptime_ms'] = top_stats['player'][name_prof][stat_category][buff_id].get('uptime_ms', 0) + stat_value
top_stats['player'][name_prof][stat_category][buff_id]['state_changes'] = top_stats['player'][name_prof][stat_category][buff_id].get('state_changes', 0) + state_changes
top_stats['fight'][fight_num][stat_category][buff_id]['uptime_ms'] = top_stats['fight'][fight_num][stat_category][buff_id].get('uptime_ms', 0) + stat_value
top_stats['overall'][stat_category][buff_id]['uptime_ms'] = top_stats['overall'][stat_category][buff_id].get('uptime_ms', 0) + stat_value
top_stats['overall'][stat_category]["group"][group][buff_id]['uptime_ms'] = top_stats['overall'][stat_category]["group"][group][buff_id].get('uptime_ms', 0) + stat_value
def get_target_buff_data(fight_num: int, player: dict, targets: dict, stat_category: str, name_prof: str) -> None:
"""
Calculate buff uptime stats for a target caused by squad player
Args:
filename (str): The filename of the fight.
player (dict): The player dictionary.
targets (dict): The targets dictionary.
stat_category (str): The category of stats to collect.
name_prof (str): The name of the profession.
fight_duration (int): The duration of the fight in milliseconds.
Returns:
None
"""
for target in targets:
if 'buffs' in target:
for buff in target['buffs']:
buff_id = 'b'+str(buff['id'])
if player['name'] in buff['statesPerSource']:
name = player['name']
buffTime = 0
buffOn = 0
firstTime = 0
conditionTime = 0
appliedCounts = 0
for stateChange in buff['statesPerSource'][name]:
if stateChange[0] == 0:
continue
elif stateChange[1] >=1 and buffOn == 0:
if stateChange[1] > buffOn:
appliedCounts += 1
buffOn = stateChange[1]
firstTime = stateChange[0]
elif stateChange[1] == 0 and buffOn:
buffOn = 0
secondTime = stateChange[0]
buffTime = secondTime - firstTime
conditionTime += buffTime
#if buff_id not in top_stats['player'][name_prof][stat_category]:
if buff_id not in top_stats['player'][name_prof][stat_category]:
top_stats['player'][name_prof][stat_category][buff_id] = {
'uptime_ms': 0,
'applied_counts': 0,
}
if buff_id not in top_stats['fight'][fight_num][stat_category]:
top_stats['fight'][fight_num][stat_category][buff_id] = {
'uptime_ms': 0,
'applied_counts': 0,
}
if buff_id not in top_stats['overall'][stat_category]:
top_stats['overall'][stat_category][buff_id] = {
'uptime_ms': 0,
'applied_counts': 0,
}
top_stats['player'][name_prof][stat_category][buff_id]['uptime_ms'] += conditionTime
top_stats['player'][name_prof][stat_category][buff_id]['applied_counts'] += appliedCounts
top_stats['fight'][fight_num][stat_category][buff_id]['uptime_ms'] += conditionTime