ranking.py 文件源码

python
阅读 44 收藏 0 点赞 0 评论 0

项目:croissance 作者: biosustain 项目源码 文件源码
def rank_phases(phases, weights, thresholds):
    values = {}
    scores = []

    for attribute, weight in weights.items():
        values[attribute] = [getattr(phase, attribute) for phase in phases]

    for phase in phases:
        scores.append((sum(weight * score([thresholds[attribute]] + values[attribute], getattr(phase, attribute))
                           for attribute, weight in weights.items()) / sum(weights.values()),
                       phase))

    ranked_phases = []
    for rank, phase in sorted(scores, key=itemgetter(0), reverse=True):
        phase.attributes['rank'] = rank
        ranked_phases.append(phase)

    return ranked_phases
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号