当前位置: 首页>>代码示例>>Python>>正文


Python Parser.parse_filename方法代码示例

本文整理汇总了Python中parsing.parser.Parser.parse_filename方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse_filename方法的具体用法?Python Parser.parse_filename怎么用?Python Parser.parse_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在parsing.parser.Parser的用法示例。


在下文中一共展示了Parser.parse_filename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_files

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [as 别名]
 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()
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:30,代码来源:file.py

示例2: parse_spawn

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [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)
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:32,代码来源:file.py

示例3: update_files

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [as 别名]
 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
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:54,代码来源:fileframe.py

示例4: get_spawn_dictionary

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [as 别名]
    def get_spawn_dictionary(data: dict, file_name: str, match_dt: datetime, spawn_dt: datetime):
        """
        Function to get the data dictionary for a spawn based on a file
        name, match datetime and spawn datetime. Uses a lot of code to
        make the searching as reliable as possible.
        """
        if data is None:
            data = FileHandler.get_data_dictionary()
        print("[FileHandler] Spawn data requested for: {}/{}/{}".format(file_name, match_dt.time(), spawn_dt.time()))
        # First check if the file_name is available
        if file_name not in data:
            return "Not available for this file.\n\nScreen results results are only available for spawns in files " \
                   "which were spawned while screen results was enabled and real-time results was running."

        file_dt = Parser.parse_filename(file_name)
        if file_dt is None:
            return "Not available for this file.\n\nScreen results results are not supported for file names which do " \
                   "not match the original Star Wars - The Old Republic CombatLog file name format."
        file_dict = data[file_name]
        # Next up comes the checking of datetimes, which is slightly more complicated due to the fact that even equal
        # datetime objects with the == operators, are not equal with the 'is' operator
        # Also, for backwards compatibility, different datetimes must be supported in this searching process
        # Datetimes always have a correct time, but the date is not always the same as the filename date
        # If this is the case, the date is actually set to January 1 1900, the datetime default
        # Otherwise the file name of the CombatLog must have been altered
        match_dict = None
        for key, value in file_dict.items():
            if key.hour == match_dt.hour and key.minute == match_dt.minute:
                match_dict = value
        if match_dict is None:
            return "Not available for this match\n\nScreen results results are only available for spawns " \
                   "in matches which were spawned while screen results was enabled and real-time results " \
                   "was running"
        # Now a similar process starts for the spawns, except that seconds matter here.
        spawn_dict = None
        for key, value in match_dict.items():
            if key is None:
                # If the key is None, something weird is going on, but we do not want to throw any data away
                # This may be caused by a bug in the ScreenParser
                # For now, we reset key to a sensible value, specifically the first moment the data was recorded, if
                # that's possible. If not, we'll skip it.
                try:
                    key = list(value[list(value.keys())[0]].keys())[0]
                except (KeyError, ValueError, IndexError):
                    continue
            if key.hour == spawn_dt.hour and key.minute == spawn_dt.minute and key.second == spawn_dt.second:
                spawn_dict = value
        if spawn_dict is None:
            return "Not available for this spawn\n\nScreen results results are not available for spawns which " \
                   "were not  spawned while screen results was enabled and real-time results were running."
        print("[FileHandler] Retrieved a spawn dictionary.")
        return spawn_dict
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:54,代码来源:filehandler.py

示例5: parse_match

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [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)
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:23,代码来源:file.py

示例6: sort_file

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [as 别名]
def sort_file(file_name: str) -> float:
    """Function to convert file name to time """
    r: datetime = Parser.parse_filename(file_name)
    if r is not None:
        return r.timestamp()
    return 0.0
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:8,代码来源:logstalker.py

示例7: filter

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [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
#.........这里部分代码省略.........
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:103,代码来源:filters.py

示例8: test_parse_filename

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_filename [as 别名]
 def test_parse_filename(self):
     result = Parser.parse_filename("combat_2017-12-26_11_27_00_541263.txt")
     self.assertIsInstance(result, datetime)
     dt = {"year": 2017, "month": 12, "day": 26, "hour": 11, "minute": 27, "second": 00}
     for key, value in dt.items():
         self.assertEqual(getattr(result, key), value)
开发者ID:RedFantom,项目名称:GSF-Parser-Public,代码行数:8,代码来源:test_parser.py


注:本文中的parsing.parser.Parser.parse_filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。