-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_top_stats_detailed.py
executable file
·137 lines (116 loc) · 7.89 KB
/
parse_top_stats_detailed.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
#!/usr/bin/env python3
# parse_top_stats_detailed.py outputs detailed top stats in arcdps logs as parsed by Elite Insights.
# Copyright (C) 2021 Freya Fleckenstein
#
# 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 argparse
import os.path
from os import listdir
import sys
from enum import Enum
import importlib
import xlwt
from parse_top_stats_tools import *
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='This reads two arcdps top stats json files and computes improvement from the first to the second.')
parser.add_argument('input_file1', help='First .json file generated by the arcdps_top_stats_parser')
parser.add_argument('input_file2', help='Second .json file generated by the arcdps_top_stats_parser')
parser.add_argument('-x', '--xls_output', dest="xls_output_filename", help="xls file to write the computed top stats to")
parser.add_argument('-j', '--json_output', dest="json_output_filename", help="json file to write the computed top stats to")
parser.add_argument('-l', '--log_file', dest="log_file", help="Logging file with all the output")
parser.add_argument('-c', '--config_file', dest="config_file", help="Config file with all the settings", default="parser_config_detailed")
args = parser.parse_args()
if not os.path.isdir(args.input_directory):
print("Directory ",args.input_directory," is not a directory or does not exist!")
sys.exit()
filename1 = os.path.basename(input_file1)
filename1 = os.path.splitext(filename1)
filename2 = os.path.basename(input_file2)
filename2 = os.path.splitext(filename2)
if args.xls_output_filename is None:
args.output_filename = filename1+"_"+filename2+"_improvement.xls"
if args.json_output_filename is None:
args.json_output_filename = filename1+"_"+filename2+"_improvement.json"
if args.log_file is None:
args.log_file = "log_"+filename1+"_"+filename2+"_improvement.txt"
parser_config = importlib.import_module("parser_configs."+args.config_file , package=None)
config = fill_config(parser_config)
output = None
if 'txt' in config.files_to_write:
output = open(args.output_filename, "w")
log = open(args.log_file, "w")
players = compare_stat_data(args, config, log)
if "xls" in config.files_to_write:
# create xls file if it doesn't exist
book = xlwt.Workbook(encoding="utf-8")
book.add_sheet("fights overview")
book.save(args.xls_output_filename)
print_string = "Welcome to the CARROT AWARDS!\n"
myprint(output, print_string, config)
# print overall stats
overall_squad_stats = get_overall_squad_stats(fights, config)
overall_raid_stats = get_overall_raid_stats(fights)
total_fight_duration = get_total_fight_duration_in_hms(overall_raid_stats['used_fights_duration'])
if 'console' in config.files_to_write or 'txt' in config.files_to_write:
print_total_squad_stats(fights, overall_squad_stats, overall_raid_stats, total_fight_duration, found_healing, found_barrier, config, output)
if 'console' in config.files_to_write or 'txt' in config.files_to_write:
print_fights_overview(fights, overall_squad_stats, overall_raid_stats, config, output)
if 'xls' in config.files_to_write:
write_fights_overview_xls(fights, overall_squad_stats, overall_raid_stats, config, args.xls_output_filename)
# print top x players for all stats. If less then x
# players, print all. If x-th place doubled, print all with the
# same amount of top x achieved.
num_used_fights = overall_raid_stats['num_used_fights']
top_total_stat_players = {key: list() for key in config.stats_to_compute}
top_consistent_stat_players = {key: list() for key in config.stats_to_compute}
top_average_stat_players = {key: list() for key in config.stats_to_compute}
top_percentage_stat_players = {key: list() for key in config.stats_to_compute}
percentage_comparison_val = {key: 0 for key in config.stats_to_compute}
top_late_players = {key: list() for key in config.stats_to_compute}
top_jack_of_all_trades_players = {key: list() for key in config.stats_to_compute}
for stat in config.stats_to_compute:
if (stat == 'heal' and not found_healing) or (stat == 'barrier' and not found_barrier):
continue
top_consistent_stat_players[stat] = get_top_players(players, config, stat, StatType.CONSISTENT)
top_total_stat_players[stat] = get_top_players(players, config, stat, StatType.TOTAL)
top_average_stat_players[stat] = get_top_players(players, config, stat, StatType.AVERAGE)
top_percentage_stat_players[stat],percentage_comparison_val[stat] = get_top_percentage_players(players, config, stat, StatType.PERCENTAGE, num_used_fights, top_consistent_stat_players[stat])
if 'console' in config.files_to_write or 'txt' in config.files_to_write:
for stat in config.stats_to_compute:
myprint(output, config.stat_names[stat].upper()+" AWARDS\n", config)
if stat == 'dist':
write_sorted_top_percentage(players, top_percentage_stat_players[stat], percentage_comparison_val[stat], config, num_used_fights, stat, output)
elif stat == 'dmg_taken':
write_sorted_top_consistent_or_avg(players, top_average_stat_players[stat], config, num_used_fights, stat, StatType.AVERAGE, output)
else:
write_sorted_top_consistent_or_avg(players, top_consistent_stat_players[stat], config, num_used_fights, stat, StatType.CONSISTENT, output)
write_sorted_total(players, top_total_stat_players[stat], config, total_fight_duration, stat, output)
write_sorted_top_consistent_or_avg(players, top_average_stat_players[stat], config, num_used_fights, stat, StatType.AVERAGE, output)
write_sorted_top_percentage(players, top_percentage_stat_players[stat], percentage_comparison_val[stat], config, num_used_fights, stat, output)
if 'json' in config.files_to_write:
write_to_json(overall_raid_stats, overall_squad_stats, fights, players, top_total_stat_players, top_average_stat_players, top_consistent_stat_players, top_percentage_stat_players, top_late_players, top_jack_of_all_trades_players, args.json_output_filename)
if 'xls' in config.files_to_write:
for stat in config.stats_to_compute:
if stat == 'dist':
write_stats_xls(players, top_percentage_stat_players[stat], stat, args.xls_output_filename, config)
elif 'dmg_taken' in stat:
write_stats_xls(players, top_average_stat_players[stat], stat, args.xls_output_filename, config)
elif 'heal' in stat and stat != 'heal_from_regen' and found_healing:
write_stats_xls(players, top_total_stat_players[stat], stat, args.xls_output_filename, config)
elif stat == 'barrier' and found_barrier:
write_stats_xls(players, top_total_stat_players[stat], stat, args.xls_output_filename, config)
elif stat == 'deaths':
write_stats_xls(players, top_consistent_stat_players[stat], stat, args.xls_output_filename, config)
else:
write_stats_xls(players, top_total_stat_players[stat], stat, args.xls_output_filename, config)