本文整理汇总了Python中parsing.parser.Parser.read_file方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.read_file方法的具体用法?Python Parser.read_file怎么用?Python Parser.read_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parsing.parser.Parser
的用法示例。
在下文中一共展示了Parser.read_file方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_spawn
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def parse_spawn(self, elements):
"""
Either starts the parsing of ALL spawns found in the specified
match or just one of them and displays the results in the other
frames accordingly.
"""
self.clear_data_widgets()
self.main_window.middle_frame.statistics_numbers_var.set("")
self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.")
file_name, match_index, spawn_index = elements[0], int(elements[1]), int(elements[2])
lines = Parser.read_file(file_name)
player_list = Parser.get_player_id_list(lines)
player_name = Parser.get_player_name(lines)
file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list)
match = file_cube[match_index]
spawn = match[spawn_index]
results = list(spawnstats.spawn_statistics(
file_name, spawn, spawn_timings[match_index][spawn_index]))
results[1] = Parser.parse_player_reaction_time(spawn, player_name)
orig = len(results[1])
results[1] = ScreenParser.build_spawn_events(
file_name, match_timings[::2][match_index], spawn_timings[match_index][spawn_index], spawn, player_name)
print("[FileFrame] ScreenParser built {} events. Total: {}".format(len(results[1]) - orig, len(results[1])))
self.update_widgets_spawn(*results)
arguments = (file_name, match_timings[::2][match_index], spawn_timings[match_index][spawn_index])
string = FileHandler.get_features_string(*arguments)
self.main_window.middle_frame.screen_label_var.set(string)
self.main_window.middle_frame.update_timeline(
file_name, match_index, spawn_index, match_timings, spawn_timings, file_cube)
示例2: parse_spawn
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def parse_spawn(self, file: str, match_i: int, spawn_i: int):
"""
Either starts the results of ALL spawns found in the specified
match or just one of them and displays the results in the other
frames accordingly.
"""
print("[FileFrame] Parsing '{}', match {}, spawn {}".format(file, match_i, spawn_i))
self.main_window.middle_frame.statistics_numbers_var.set("")
self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.")
lines = Parser.read_file(file)
player_list = Parser.get_player_id_list(lines)
player_name = Parser.get_player_name(lines)
file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list)
match = file_cube[match_i]
spawn = match[spawn_i]
results = list(spawnstats.spawn_statistics(
file, spawn, spawn_timings[match_i][spawn_i]))
results[1] = Parser.parse_player_reaction_time(spawn, player_name)
orig = len(results[1])
results[1] = ScreenParser.build_spawn_events(
file, match_timings[::2][match_i], spawn_timings[match_i][spawn_i], spawn, player_name)
print("[FileFrame] ScreenParser built {} events. Total: {}".format(len(results[1]) - orig, len(results[1])))
self.update_widgets_spawn(*results)
arguments = (file, match_timings[::2][match_i], spawn_timings[match_i][spawn_i])
string = FileHandler.get_features_string(*arguments)
self.main_window.middle_frame.screen_label_var.set(string)
self.main_window.middle_frame.update_timeline(
file, match_i, spawn_i, match_timings, spawn_timings, file_cube)
match_timing = datetime.combine(Parser.parse_filename(file).date(), match_timings[::2][match_i].time())
self.main_window.middle_frame.scoreboard.update_match(match_timing)
示例3: file_statistics
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def file_statistics(file_name, sharing_db=None):
"""
Puts the statistics found in a file_cube from
Parser.split_combatlog() into a format that is usable by the
FileFrame to display them to the user
"""
lines = Parser.read_file(file_name)
player_list = Parser.get_player_id_list(lines)
file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list)
# Read sharing_db
lines = Parser.read_file(file_name, sharing_db)
name = Parser.get_player_name(lines)
(abilities_dict, dmg_d, dmg_t, dmg_s, healing, hitcount, critcount,
crit_luck, enemies, enemy_dmg_d, enemy_dmg_t, ships, uncounted) = \
Parser.parse_file(file_cube, player_list)
total = 0
start = None
for timing in match_timings:
if start is not None:
total += (timing - start).total_seconds()
start = None
continue
start = timing
minutes, seconds = divmod(total, 60)
stat_string = "{name}\n{enemies} enemies\n{dmg_d}\n{dmg_t}\n{dmg_r:.1f} : 1.0\n" \
"{dmg_s}\n{healing}\n{hitcount}\n{critcount}\n{crit_luck:.2f}\n" \
"{deaths}\n{minutes}:{seconds:.0f}\n{dps:.1f}"
stat_string = stat_string.format(
name=name,
enemies=len([enemy for enemy in enemies if enemy in enemy_dmg_t and enemy_dmg_t[enemy] > 0]),
dmg_d=dmg_d,
dmg_t=dmg_t,
dmg_r=dmg_d / dmg_t if dmg_t != 0 else 0,
dmg_s=dmg_s,
healing=healing,
hitcount=hitcount,
critcount=critcount,
crit_luck=critcount / hitcount if hitcount != 0 else 0,
deaths=sum(len(match) for match in file_cube),
minutes=minutes,
seconds=seconds,
dps=dmg_d / total,
)
return abilities_dict, stat_string, ships, enemies, enemy_dmg_d, enemy_dmg_t, uncounted
示例4: test_get_effects_ability_eligible
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def test_get_effects_ability_eligible(self):
with open(self.FILE) as fi:
lindex = fi.readlines()
index = lindex.index(self.EFFECT)
no_effect = lindex.index(self.LINE)
lines = Parser.read_file(self.FILE)
player = Parser.get_player_id_list(lines)
line = Parser.line_to_dictionary(lines[index], player)
effect = Parser.get_effects_ability(line, lines, "2963000049645")
self.assertIsInstance(effect, dict)
self.assertTrue(len(effect) > 0)
# Tests get_effects_eligible
self.assertFalse(Parser.get_effects_ability(lines[no_effect], lines, "2963000048240"))
示例5: spawn_statistics
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def spawn_statistics(file_name, spawn, spawn_timing, sharing_db=None):
"""Build strings to show in the StatsFrame"""
# Retrieve required data
lines = Parser.read_file(file_name, sharing_db)
player_numbers = Parser.get_player_id_list(lines)
(abilities_dict, dmg_t, dmg_d, healing, dmg_s, enemies, critcount,
crit_luck, hitcount, ships_list, enemy_dmg_d, enemy_dmg_t) = \
Parser.parse_spawn(spawn, player_numbers)
name = Parser.get_player_name(lines)
# Build the statistics string
stat_string = "{name}\n{enemies} enemies\n{dmg_d}\n{dmg_t}\n{dmg_r:.1f} : 1.0\n" \
"{dmg_s}\n{healing}\n{hitcount}\n{critcount}\n{crit_luck:.2f}\n" \
"{deaths}\n{minutes}:{seconds:.0f}\n{dps:.1f}"
start = spawn_timing
finish = Parser.line_to_dictionary(spawn[-1])["time"]
delta = finish - start
minutes, seconds = divmod(delta.total_seconds(), 60)
killsassists = sum(True if enemy_dmg_t[enemy] > 0 else False for enemy in enemies if enemy in enemy_dmg_t)
stat_string = stat_string.format(
name=name,
enemies=killsassists,
dmg_d=dmg_d,
dmg_t=dmg_t,
dmg_r=dmg_d / dmg_t if dmg_t != 0 else 0,
dmg_s=dmg_s,
healing=healing,
hitcount=hitcount,
critcount=critcount,
crit_luck=critcount / hitcount if hitcount != 0 else 0,
deaths="-",
minutes=minutes,
seconds=seconds,
dps=dmg_d / delta.total_seconds() if delta.total_seconds() != 0 else 0
)
# Build the components list
components = {key: "" for key in abilities.component_types}
for component in [ability for ability in abilities_dict.keys() if ability in abilities.components]:
for type in components.keys():
if component not in getattr(abilities, type):
continue
# Dual primary/secondary weapons
if components[type] != "":
components[type] += " / {}".format(component)
break
components[type] = component
break
components = [components[category] for category in abilities.component_types]
# Return
return name, spawn, abilities_dict, stat_string, ships_list, components, enemies, enemy_dmg_d, enemy_dmg_t
示例6: parse_file
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def parse_file(self, file_name):
"""
Function either sets the file and calls add_matches to add the
matches found in the file to the matches_listbox, or starts the
parsing of all files found in the specified folder and displays
the results in the other frames.
"""
self.clear_data_widgets()
self.main_window.middle_frame.statistics_numbers_var.set("")
self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.")
lines = Parser.read_file(file_name)
player_list = Parser.get_player_id_list(lines)
file_cube, _, _ = Parser.split_combatlog(lines, player_list)
results = filestats.file_statistics(file_name)
self.update_widgets(*results)
示例7: get_spawn
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def get_spawn(self):
"""
Get the spawn from the selection in the file_tree
:return: list of event strings, player_list, spawn timing and
match timing
"""
selection = self.file_tree.selection()[0]
elements = selection.split(" ")
if len(elements) is not 3:
tkinter.messagebox.showinfo("Requirement", "Please select a spawn to view the events of.")
return
lines = Parser.read_file(elements[0])
player_list = Parser.get_player_id_list(lines)
file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list)
match_index, spawn_index = int(elements[1]), int(elements[2])
return (file_cube[match_index][spawn_index], player_list, spawn_timings[match_index][spawn_index],
match_timings[match_index])
示例8: parse_match
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def parse_match(self, file: str, match_i: int):
"""
Either adds sets the match and calls add_spawns to add the
spawns found in the match or starts the results of all files
found in the specified file and displays the results in the
other frames.
"""
print("[FileFrame] Parsing file '{}', match {}".format(file, match_i))
self.main_window.middle_frame.statistics_numbers_var.set("")
self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.")
lines = Parser.read_file(file)
player_list = Parser.get_player_id_list(lines)
file_cube, match_timings, _ = Parser.split_combatlog(lines, player_list)
player_name = Parser.get_player_name(lines)
match = file_cube[match_i]
results = matchstats.match_statistics(file, match, match_timings[::2][match_i])
self.update_widgets(*results)
match_list = Parser.build_spawn_from_match(match)
self.main_window.middle_frame.time_view.insert_spawn(match_list, player_name)
match_timing = datetime.combine(Parser.parse_filename(file).date(), match_timings[::2][match_i].time())
self.main_window.middle_frame.scoreboard.update_match(match_timing)
示例9: parse_match
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def parse_match(self, elements: list):
"""
Either adds sets the match and calls add_spawns to add the
spawns found in the match or starts the parsing of all files
found in the specified file and displays the results in the
other frames.
:param elements: specifies file and match
"""
self.clear_data_widgets()
self.main_window.middle_frame.statistics_numbers_var.set("")
self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.")
file_name, match_index = elements[0], int(elements[1])
lines = Parser.read_file(file_name)
player_list = Parser.get_player_id_list(lines)
file_cube, match_timings, _ = Parser.split_combatlog(lines, player_list)
player_name = Parser.get_player_name(lines)
match = file_cube[match_index]
results = matchstats.match_statistics(file_name, match, match_timings[::2][match_index])
self.update_widgets(*results)
match_list = Parser.build_spawn_from_match(match)
self.main_window.middle_frame.time_view.insert_spawn(match_list, player_name)
示例10: filter
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def filter(self, search=False):
"""
Go through all file filters and apply them to the list of files
in the CombatLogs folder. Insert them into the file_frame
file_tree widget when the file passed the filters.
:param search: if search is True, the function will calculate
the amount of files found and ask the user whether the
results should be displayed first
"""
# logs, matches or spawns
results = []
files = os.listdir(variables.settings["parsing"]["path"])
files_done = 0
splash = SplashScreen(self, len(files))
# Clear the widgets in the file frame
self.window.file_select_frame.file_string_dict.clear()
self.window.file_select_frame.clear_data_widgets()
self.window.file_select_frame.file_tree.delete(*self.window.file_select_frame.file_tree.get_children())
# Start looping over the files in the CombatLogs folder
for file_name in files:
# Set passed to True. Will be set to False in some filter code
passed = True
# Update the SplashScreen progress bar
files_done += 1
splash.update_max(files_done)
# If the file does not end with .txt, it's not a CombatLog
if not file_name.endswith(".txt") or not Parser.get_gsf_in_file(file_name):
continue
# Open the CombatLog
lines = Parser.read_file(file_name)
# Parse the CombatLog to get the data to filter against
player_list = Parser.get_player_id_list(lines)
file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list)
(abilities, damagedealt, damagetaken, selfdamage, healing, _, _, _, _,
enemy_dmg_d, enemy_dmg_t, _, _) = Parser.parse_file(file_cube, player_list)
matches = len(file_cube)
damagedealt, damagetaken, selfdamage, healing = (
damagedealt / matches,
damagetaken / matches,
selfdamage / matches,
healing / matches
)
# If Ship filters are enabled, check file against ship filters
if self.filter_type_vars["Ships"].get() is True:
print("Ships filters are enabled")
if not self.check_ships_file(self.ships_intvars, abilities):
print("Continuing in file {0} because of Ships".format(file_name))
continue
# If the Components filters are enabled, check against Components filters
if self.filter_type_vars["Components"].get() is True:
print("Components filters are enabled")
for dictionary in self.comps_vars:
if not self.check_components(dictionary, abilities):
# Passed is applied here as "continue" will not work inside this for loop
passed = False
break
if not passed:
print("Continuing in file {0} because of Components".format(file_name))
continue
if self.filter_type_vars["Date"].get() is True:
print("Date filters are enabled")
date = Parser.parse_filename(file_name)
if not date:
print("Continuing in file {0} because the filename could not be parsed".format(file_name))
continue
if self.start_date_widget.selection > date:
print("Continuing in file {0} because of the start date".format(file_name))
continue
if self.end_date_widget.selection < date:
print("Continuing in file {0} because of the end date".format(file_name))
continue
enemies = sum(True if dmg > 0 else False for dmg in enemy_dmg_d.values())
killassists = sum(True if dmg > 0 else False for dmg in enemy_dmg_t.values())
if self.filter_type_vars["Statistics"].get() is True:
for (scale_type, scale_max), (_, scale_min) in \
zip(self.statistics_scales_max.items(), self.statistics_scales_min.items()):
value = locals()[scale_type]
min, max = scale_min.value, scale_max.value
condition = min <= value <= max if max > min else min <= value
if condition is False:
continue
results.append(file_name)
print("Amount of results: {0}".format(len(results)))
print("Results: {0}".format(results))
splash.destroy()
if search and len(results) is not 0:
print("Search is enabled")
if not tkinter.messagebox.askyesno("Search results",
"With the filters you specified, %s results were found. Would you like "
"to view them?" % len(results)):
return
if len(results) == 0:
tkinter.messagebox.showinfo("Search results",
"With the filters you specified, no results were found.")
return
#.........这里部分代码省略.........
示例11: test_get_player_id_list
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def test_get_player_id_list(self):
lines = Parser.read_file(self.FILE)
ids = Parser.get_player_id_list(lines)
self.assertIsInstance(ids, list)
self.assertGreater(len(ids), 0)
示例12: test_get_abilities_dict
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def test_get_abilities_dict(self):
lines = Parser.read_file(self.FILE)
player = Parser.get_player_id_list(lines)
abilities = Parser.get_abilities_dict(lines, player)
self.assertIsInstance(abilities, dict)
示例13: test_read_file
# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import read_file [as 别名]
def test_read_file(self):
lines = Parser.read_file(self.FILE)
self.assertIsInstance(lines, list)
self.assertIsInstance(lines[0], dict)