Exemplo n.º 1
0
 def update_files(self):
     """Update the Calendar with the new files"""
     self.clear_data_widgets()
     self._dates.clear()
     folder = variables.settings["parsing"]["path"]
     if not os.path.exists(folder):
         messagebox.showerror("Error",
             "The specified CombatLogs folder does not exist. Please "
             "choose a different folder.")
         folder = filedialog.askdirectory()
         variables.settings.write_settings({"parsing": {"path": folder}})
         return self.update_files()
     files = [f for f in os.listdir(folder) if Parser.get_gsf_in_file(f)]
     self.create_splash(len(files))
     match_count: Dict[datetime: int] = DateKeyDict()
     for file in files:
         date = Parser.parse_filename(file)
         if date is None:  # Failed to parse
             continue
         if date not in match_count:
             match_count[date] = 0
         match_count[date] += Parser.count_matches(file)
         if date not in self._dates:
             self._dates[date] = list()
         self._dates[date].append(file)
         self._splash.increment()
     self._calendar.update_heatmap(match_count)
     self.destroy_splash()
Exemplo n.º 2
0
 def update_files(self, silent=False):
     """
     Function that checks files found in the in the settings
     specified folder for GSF matches and if those are found in a
     file, it gets added to the listbox. Provides error handling.
     """
     self.file_tree.delete(*self.file_tree.get_children())
     self.clear_data_widgets()
     self.main_window.ship_frame.ship_label_var.set("")
     try:
         old_cwd = os.getcwd()
         os.chdir(variables.settings["parsing"]["path"])
         os.chdir(old_cwd)
     except OSError:
         tkinter.messagebox.showerror("Error",
                                      "The CombatLogs folder found in the settings file is not valid. Please "
                                      "choose another folder.")
         folder = tkinter.filedialog.askdirectory(title="CombatLogs folder")
         variables.settings.write_settings({'parsing': {'path': folder}})
         variables.settings.read_settings()
     combatlogs_folder = variables.settings["parsing"]["path"]
     file_list = os.listdir(combatlogs_folder)
     if not silent:
         splash_screen = SplashScreen(self.main_window, len(file_list), title="Loading files")
     else:
         splash_screen = None
     if len(file_list) > 100:
         tkinter.messagebox.showinfo("Suggestion", "Your CombatLogs folder contains a lot of CombatLogs, {0} to be "
                                                   "precise. How about moving them to a nice archive folder? This "
                                                   "will speed up some processes "
                                                   "significantly.".format(len(file_list)))
     self.file_tree.insert("", tk.END, iid="all", text="All CombatLogs")
     file_list = list(reversed(sorted(file_list)) if not self.ascending else sorted(file_list))
     if self.main_window.splash is not None and self.main_window.splash.winfo_exists():
         self.main_window.splash.update_max(len(file_list))
     for number, file in enumerate(file_list):
         if not Parser.get_gsf_in_file(file):
             continue
         file_string = Parser.parse_filename(file)
         if file_string is None:
             continue
         self.file_string_dict[file_string] = file
         number += 1
         if splash_screen is not None:
             splash_screen.increment()
             splash_screen.update()
         self.insert_file(file_string)
         if self.main_window.splash is not None and self.main_window.splash.winfo_exists():
             self.main_window.splash.increment()
     if splash_screen is not None:
         splash_screen.destroy()
     return
Exemplo n.º 3
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()
Exemplo n.º 4
0
 def test_get_gsf_in_file(self):
     self.assertTrue(Parser.get_gsf_in_file(self.FILE))