Exemple #1
0
def _reCalcBestParameters(targetCache):
    raise targetCache or AssertionError
    bestParamsDict = {}
    for vcParamData in targetCache:
        params = vcParamData.getParams()
        for pKey, pVal in params.iteritems():
            if isinstance(pVal, (tuple, list)):
                if pKey in bestParamsDict:
                    rateParamsList = rateParameterState(
                        pKey, bestParamsDict[pKey], pVal)
                    for idx, (state, diff) in enumerate(rateParamsList):
                        if state == PARAM_STATE.WORSE:
                            maxVals = bestParamsDict[pKey]
                            if idx == len(maxVals):
                                maxVals.append(pVal[idx])
                            else:
                                maxVals[idx] = pVal[idx]

                else:
                    bestParamsDict[pKey] = list(pVal)
            elif pKey in bestParamsDict:
                state, diff = rateParameterState(pKey, bestParamsDict[pKey],
                                                 pVal)
                if state == PARAM_STATE.WORSE:
                    bestParamsDict[pKey] = pVal
            else:
                bestParamsDict[pKey] = pVal

    return bestParamsDict
def _reCalcBestParameters(targetCache):
    raise targetCache or AssertionError
    bestParamsDict = {}
    for vcParamData in targetCache:
        params = vcParamData.getParams()
        for pKey, pVal in params.iteritems():
            if isinstance(pVal, (tuple, list)):
                if pKey in bestParamsDict:
                    rateParamsList = rateParameterState(pKey, bestParamsDict[pKey], pVal)
                    for idx, (state, diff) in enumerate(rateParamsList):
                        if state == PARAM_STATE.WORSE:
                            maxVals = bestParamsDict[pKey]
                            if idx == len(maxVals):
                                maxVals.append(pVal[idx])
                            else:
                                maxVals[idx] = pVal[idx]

                else:
                    bestParamsDict[pKey] = list(pVal)
            elif pKey in bestParamsDict:
                state, diff = rateParameterState(pKey, bestParamsDict[pKey], pVal)
                if state == PARAM_STATE.WORSE:
                    bestParamsDict[pKey] = pVal
            else:
                bestParamsDict[pKey] = pVal

    return bestParamsDict
    def getPenalties(self, vehicle):
        crew, emptySlots, otherVehicleSlots = functions.extractCrewDescrs(vehicle, replaceNone=False)
        crewFactors = items_utils.getCrewAffectedFactors(vehicle.descriptor, crew)
        result = {}
        currParams = self.getParamsDict(True)
        for slotId, factors in crewFactors.iteritems():
            for factor, factorValue in factors.iteritems():
                if factor in _FACTOR_TO_SKILL_PENALTY_MAP:
                    oldFactor = copy.copy(self.__factors[factor])
                    self.__factors[factor] = _universalSum(oldFactor, factorValue)
                    params = _FACTOR_TO_SKILL_PENALTY_MAP[factor]
                    for paramName in params:
                        paramPenalties = result.setdefault(paramName, {})
                        if slotId not in emptySlots:
                            newValue = getattr(self, paramName)
                            if newValue is None:
                                continue
                            state = rateParameterState(paramName, currParams[paramName], newValue)
                            if isinstance(currParams[paramName], collections.Iterable):
                                states, deltas = zip(*state)
                                if findFirst(lambda v: v == PARAM_STATE.WORSE, states):
                                    paramPenalties[slotId] = deltas
                            elif state[0] == PARAM_STATE.WORSE:
                                paramPenalties[slotId] = state[1]
                        paramPenalties[slotId] = 0

                    self.__factors[factor] = oldFactor

        roles = vehicle.descriptor.type.crewRoles
        for paramName, penalties in result.items():
            result[paramName] = [ _PenaltyInfo(roles[slotId][0], value, slotId in otherVehicleSlots) for slotId, value in penalties.iteritems() ]

        return {k:v for k, v in result.iteritems() if v}