Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 def test_get_player_name(self):
     with open(self.FILE) as fi:
         lines = fi.readlines()
     self.assertEqual(Parser.get_player_name(lines), "Redfantom")