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


Python Driver.set_points方法代码示例

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


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

示例1: calc_points

# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import set_points [as 别名]
    def calc_points(self, drivers, season_data):

        if not season_data.is_score_points(self.stype):
            raise LookupError("Points should be awarded, but can't find them in season configuration")

        # add an entry to the dictionary, if it's not there
        for entry in self.data:
            driver_name, driver_classes = self.get_driver_name_and_classes(entry["driver_name"], season_data)

            # determine and store canonical name
            entry["driver_name_canonical"] = driver_name

            # add an entry to the dictionary, if it's not there
            driver = Driver(driver_name)
            if not driver in drivers:
                drivers[driver] = driver
            else:
                driver = drivers[driver]

            # add discovered classes to the driver
            driver.add_classes(driver_classes)

        # apply all stored point adjustments
        self.apply_point_adjustments()

        # process the actual points
        for entry in self.data:

            # look up driver
            driver = drivers[Driver(entry["driver_name_canonical"])]

            # determine driver position
            position = entry["pos"]

            # if points were overwritten as a part of post-race adjustments, then assign this exact value
            if "points" in entry:
                driver.set_points(self, entry["points"], entry["status"], "non_droppable" in entry)
                continue

            # assign points based on the status & position
            if entry["status"] == 'OK':
                # this is a regular finish
                points = season_data.get_driver_points(self.stype, position)
                entry["points"] = points
                driver.set_points(self, points, entry["status"], "non_droppable" in entry)

            elif entry["status"] == 'DNS':
                # DNS is 'did not start'
                # person gets 0 points always. he stays on the rankings, but it creates a gap in points
                entry["points"] = 0
                driver.set_points(self, 0, entry["status"], "non_droppable" in entry)

            elif entry["status"] == 'DNF':
                # DNF is 'did not finish'
                # we just assign points in order in this case
                # i.e. someone who crashed on lap 5 gets less points vs. someone who crashed on lap 6
                points = season_data.get_driver_points(self.stype, position)
                entry["points"] = points
                driver.set_points(self, points, entry["status"], "non_droppable" in entry)

            elif entry["status"] == 'DQ':
                # DQ - by default it's zero points
                # it can be overwritten later by the admin
                entry["points"] = 0
                driver.set_points(self, 0, entry["status"], "non_droppable" in entry)

            else:
                # unknown driver status
                raise LookupError("Unknown driver status while assigning points: " + str(entry["status"]))
开发者ID:,项目名称:,代码行数:71,代码来源:


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