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 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)
Exemplo n.º 4
0
 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])
Exemplo n.º 5
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.º 6
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.º 7
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.º 8
0
 def _process_new_file(self):
     """Backlog only the lines of a match that are match lines"""
     print("[LogStalker] Processing new file.")
     lines = self.read_file(self.path, 0)
     if len(lines) == 0:
         return
     player_list = Parser.get_player_id_list(lines)
     file_cube, _, _ = Parser.split_combatlog(lines, player_list)
     if len(file_cube) == 0:
         print("[LogStalker] No matches in this file")
         self._read_so_far = len(lines)
         return
     last_line = file_cube[-1][-1][-1]
     if last_line["time"] == lines[-1]["time"]:
         print("[LogStalker] Match still active")
         # Last line is still a match line
         match_len = sum(len(spawn) for spawn in file_cube[-1])
         self._read_so_far = len(lines) - match_len
         return
     # Last line is no longer a match
     print("[LogStalker] Last line is not a match event")
     self._read_so_far = len(lines)
Exemplo n.º 9
0
    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

        for file_name in results:
            datetime_obj = Parser.parse_filename(file_name)
            string = datetime_obj.strftime("%Y-%m-%d   %H:%M") if datetime_obj is not None else file_name
            print("Setting file string {0} to match file_name {1}".format(string, file_name))
            self.window.file_select_frame.file_string_dict[string] = file_name
            self.window.file_select_frame.insert_file(string)
        self.destroy()