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


Python Timer.checkpoint方法代码示例

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


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

示例1: calculateModifiedAttributes

# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import checkpoint [as 别名]
    def calculateModifiedAttributes(self, targetFit=None, withBoosters=False, dirtyStorage=None):
        timer = Timer(u'Fit: {}, {}'.format(self.ID, self.name), logger)
        logger.debug("Starting fit calculation on: %r, withBoosters: %s", self, withBoosters)

        shadow = False
        if targetFit:
            logger.debug("Applying projections to target: %r", targetFit)
            projectionInfo = self.getProjectionInfo(targetFit.ID)
            logger.debug("ProjectionInfo: %s", projectionInfo)
            if self == targetFit:
                copied = self  # original fit
                shadow = True
                self = copy.deepcopy(self)
                self.fleet = copied.fleet
                logger.debug("Handling self projection - making shadow copy of fit. %r => %r", copied, self)
                # we delete the fit because when we copy a fit, flush() is
                # called to properly handle projection updates. However, we do
                # not want to save this fit to the database, so simply remove it
                eos.db.saveddata_session.delete(self)

        if self.fleet is not None and withBoosters is True:
            logger.debug("Fleet is set, gathering gang boosts")
            self.gangBoosts = self.fleet.recalculateLinear(withBoosters=withBoosters)
            timer.checkpoint("Done calculating gang boosts for %r"%self)
        elif self.fleet is None:
            self.gangBoosts = None

        # If we're not explicitly asked to project fit onto something,
        # set self as target fit
        if targetFit is None:
            targetFit = self
            projected = False
        else:
            projected = True

        # If fit is calculated and we have nothing to do here, get out

        # A note on why projected fits don't get to return here. If we return
        # here, the projection afflictions will not be run as they are
        # intertwined into the regular fit calculations. So, even if the fit has
        # been calculated, we need to recalculate it again just to apply the
        # projections. This is in contract to gang boosts, which are only
        # calculated once, and their items are then looped and accessed with
        #     self.gangBoosts.iteritems()
        # We might be able to exit early in the fit calculations if we separate
        # projections from the normal fit calculations. But we must ensure that
        # projection have modifying stuff applied, such as gang boosts and other
        # local modules that may help
        if self.__calculated and not projected:
            logger.debug("Fit has already been calculated and is not projected, returning: %r", self)
            return

        # Mark fit as calculated
        self.__calculated = True

        for runTime in ("early", "normal", "late"):
            # Items that are unrestricted. These items are run on the local fit
            # first and then projected onto the target fit it one is designated
            u = [
                (self.character, self.ship),
                self.drones,
                self.boosters,
                self.appliedImplants,
                self.modules
            ]

            # Items that are restricted. These items are only run on the local
            # fit. They are NOT projected onto the target fit. # See issue 354
            r = [(self.mode,), self.projectedDrones, self.projectedModules]

            # chain unrestricted and restricted into one iterable
            c = chain.from_iterable(u+r)

            # We calculate gang bonuses first so that projected fits get them
            if self.gangBoosts is not None:
                self.__calculateGangBoosts(runTime)

            for item in c:
                # Registering the item about to affect the fit allows us to
                # track "Affected By" relations correctly
                if item is not None:
                    # apply effects locally
                    self.register(item)
                    item.calculateModifiedAttributes(self, runTime, False)

                    if projected is True and item not in chain.from_iterable(r):
                        # apply effects onto target fit
                        for _ in xrange(projectionInfo.amount):
                            targetFit.register(item, origin=self)
                            item.calculateModifiedAttributes(targetFit, runTime, True)

            timer.checkpoint('Done with runtime: %s'%runTime)

        # Only apply projected fits if fit it not projected itself.
        if not projected:
            for fit in self.projectedFits:
                if fit.getProjectionInfo(self.ID).active:
                    fit.calculateModifiedAttributes(self, withBoosters=withBoosters, dirtyStorage=dirtyStorage)

        timer.checkpoint('Done with fit calculation')
#.........这里部分代码省略.........
开发者ID:meldi44,项目名称:Pyfa,代码行数:103,代码来源:fit.py


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