def calc_derived_member_stats(self, member):
        member.current_war = WarParticipation(self.config, member,
                                              self.current_war)
        member.warlog = []
        for war in self.warlog.items:
            member.warlog.append(WarParticipation(self.config, member, war))

        score_calc = ScoreCalculator(self.config)

        member.donation_score = score_calc.get_member_donations_score(member)

        # calculate score based on war participation
        member.war_score = 0
        for war in member.warlog:
            member.war_score += war.score

        # get member score
        member.score = member.war_score + member.donation_score

        # members on the safe list can't have a score below zero
        if member.safe and member.score < 0:
            member.score = 0

        # calculate the number of daily donations, and the donation status
        # based on threshold set in config
        member.donation_status = self.calc_donation_status(
            member.donation_score, member.donations_daily,
            self.days_from_donation_reset)

        member.status = self.calc_member_status(member.score,
                                                member.no_promote)

        member.activity_status = self.calc_activity_status(
            member.days_inactive)

        member.role_label = self.get_role_label(member.tag, member.role,
                                                member.days_inactive,
                                                member.activity_status,
                                                member.vacation,
                                                member.blacklist,
                                                member.no_promote)

        if member.trophies >= self.clan.required_trophies:
            member.trophies_status = 'normal'
        else:
            member.trophies_status = 'ok'

        member.arena_league_label = self.config['strings'][
            'league-' + member.arena_league['id']]

        # Figure out whether member is on the leadership team by role
        member.leadership = member.role == 'leader' or member.role == 'coLeader'

        self.calc_recent_war_stats(member)
Example #2
0
def test_war_score(tmpdir):

    config_file = tmpdir.mkdir('test_war_score').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    calc = ScoreCalculator(config)

    war_complete = ProcessedCurrentWar(config=config,
                                       current_war=__fake_current_war__)
    war_complete.status = 'na'
    war_complete.battles_played = 1
    war_complete.wins = 1
    war_complete.collection_day_battles_played = 3
    war_complete.collection_battle_wins = 2
    war_complete.collection_battle_losses = 0
    assert calc.get_war_score(war_complete) == 24

    war_incomplete = ProcessedCurrentWar(config=config,
                                         current_war=__fake_current_war__)
    war_incomplete.status = 'na'
    war_incomplete.battles_played = 0
    war_incomplete.wins = 0
    war_incomplete.collection_day_battles_played = 3
    war_incomplete.collection_battle_wins = 2
    war_incomplete.collection_battle_losses = 0
    assert calc.get_war_score(war_incomplete) == -26

    war_na = WarParticipation(config=config,
                              member=ProcessedMember(__fake_member_list__[4]),
                              war=__fake_war__)
    assert calc.get_war_score(war_na) == -1

    war_new = WarParticipation(config=config,
                               member=ProcessedMember(__fake_member_list__[4]),
                               war=__fake_war__)
    war_new.status = 'not-in-clan'
    assert calc.get_war_score(war_new) == 0