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


Python Parser.parse_file方法代码示例

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


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

示例1: test_on_parsed_line

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_file [as 别名]
  def test_on_parsed_line(self):
    lines = [
      "FEATURE TYPE:  ## ADHOC",
      "true",
      "bleep",
    ]
    parser = Parser()

    parsed_lines = []
    def on_parsed_line(indent, content):
      parsed_lines.append(content.line())

    parser.parse_file(lines, on_parsed_line=on_parsed_line)

    self.assertEqual(["FEATURE TYPE:  ## ADHOC"], parsed_lines)
开发者ID:calestar,项目名称:experiments,代码行数:17,代码来源:test_parser_basis.py

示例2: test_parse_file_stats

# 需要导入模块: from parsing.parser import Parser [as 别名]
# 或者: from parsing.parser.Parser import parse_file [as 别名]
  def test_parse_file_stats(self):
    lines = [
      "true", "Using complex purge",
      "bloop", "bleep",
      "FEATURE TYPE:  ## ADHOC",
    ]
    parser = Parser()

    stats = parser.parse_file(lines)

    self.assertEqual(5, stats['nb_read'])
    self.assertEqual(1, stats['nb_parsed'])
    self.assertEqual(2, stats['nb_skipped'])
开发者ID:calestar,项目名称:experiments,代码行数:15,代码来源:test_parser_basis.py

示例3: file_statistics

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

示例4: filter

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


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