Пример #1
0
def process_members(config,
                    clan,
                    warlog,
                    current_war,
                    member_history,
                    war_readiness_map={}):
    """ Process member list, adding calculated meta-data for rendering of
    status in the clan member table. """

    # calculate the number of days since the donation last sunday, for
    # donation tracking purposes:
    days_from_donation_reset = config['crtools']['timestamp'].isoweekday()
    if days_from_donation_reset > 7 or days_from_donation_reset <= 0:
        days_from_donation_reset = 1

    # process members with results from the API
    factory = MemberFactory(config=config,
                            clan=clan,
                            current_war=current_war,
                            warlog=warlog,
                            member_history=member_history,
                            days_from_donation_reset=days_from_donation_reset)
    members_processed = []
    for member_src in clan.member_list:
        war_readiness = war_readiness_map.get(member_src.tag)
        members_processed.append(
            factory.get_processed_member(member_src, war_readiness))

    return members_processed
def test_calc_donation_status(tmpdir):
    config_file = tmpdir.mkdir('test_calc_donation_status').join('config.ini')
    config_file.write('''
[Score]
max_donations_bonus=40
min_donations_daily=10
''')
    config = load_config_file(config_file.realpath())

    factory = MemberFactory(config, None, None, None)

    assert factory.calc_donation_status(1000, 100, 6) == 'good'
    assert factory.calc_donation_status(0, 0, 6) == 'bad'
    assert factory.calc_donation_status(0, 5, 6) == 'ok'
    assert factory.calc_donation_status(0, 0, 0) == 'normal'
def test_calc_activity_status():
    config = load_config_file(False)

    factory = MemberFactory(config, None, None, None)

    assert factory.calc_activity_status(0) == 'good'
    assert factory.calc_activity_status(-1) == 'good'
    assert factory.calc_activity_status(1) == 'na'
    assert factory.calc_activity_status(3) == 'normal'
    assert factory.calc_activity_status(7) == 'ok'
    assert factory.calc_activity_status(400) == 'bad'
Пример #4
0
def test_get_suggestions_nosuggestions(tmpdir):
    config_file = tmpdir.mkdir('test_get_suggestions').join('testfile')
    config_file.write(
        __config_file_score__ +
        '\nthreshold_demote=-999999\nthreshold_promote=9999999\nmin_clan_size={}'
        .format(crtools.MAX_CLAN_SIZE))
    config = load_config_file(config_file.realpath())

    war = ProcessedCurrentWar(
        config=config, current_war=pyroyale.WarCurrent(state='notInWar'))
    factory = MemberFactory(config=config,
                            member_history=history.get_member_history(
                                __fake_clan__.member_list,
                                config['crtools']['timestamp'], '{}', war),
                            current_war=war,
                            clan=__fake_clan__,
                            warlog=pyroyale.WarLog(items=[]))

    members = []
    for i in range(0, crtools.MAX_CLAN_SIZE):
        member = factory.get_processed_member(
            pyroyale.ClanMember(tag="#AAAAAA",
                                name="LeaderPerson",
                                role="leader",
                                exp_level=13,
                                trophies=9999,
                                donations=9999,
                                arena=pyroyale.Arena(id=54000012,
                                                     name='Legendary Arena'),
                                last_seen="20190802T154619.000Z"))
        member.safe = True
        members.append(member)

    suggestions = crtools.get_suggestions(config, members,
                                          __fake_clan__.required_trophies)

    assert len(suggestions) == 1
    assert suggestions[-1] == config['strings']['suggestionNone']
Пример #5
0
def process_members(config, clan, warlog, current_war, member_history):
    """ Process member list, adding calculated meta-data for rendering of
    status in the clan member table. """

    # calculate the number of days since the donation last sunday, for
    # donation tracking purposes:
    now = datetime.utcnow()
    days_from_donation_reset = now.isoweekday()
    if days_from_donation_reset > 7 or days_from_donation_reset <= 0:
        days_from_donation_reset = 1

    # process members with results from the API
    factory = MemberFactory(config=config,
                            clan=clan,
                            current_war=current_war,
                            warlog=warlog,
                            member_history=member_history,
                            days_from_donation_reset=days_from_donation_reset,
                            now=now)
    members_processed = []
    for member_src in clan.member_list:
        members_processed.append(factory.get_processed_member(member_src))

    return members_processed
def test_calc_member_status(tmpdir):
    config_file = tmpdir.mkdir('test_calc_member_status').join('config.ini')
    config_file.write('''
[Score]
threshold_promote=100
threshold_warn=10
''')
    config = load_config_file(config_file.realpath())

    factory = MemberFactory(config, None, None, None)

    assert factory.calc_member_status(-1, False) == 'bad'
    assert factory.calc_member_status(5, False) == 'ok'
    assert factory.calc_member_status(10, False) == 'normal'
    assert factory.calc_member_status(100, False) == 'good'
    assert factory.calc_member_status(100, True) == 'normal'
def test_get_role_label():
    config = load_config_file(False)

    factory = MemberFactory(config, None, None, None)

    vacation_end = 999999999999999999

    assert factory.get_role_label(
        'member', 0, 'good', MemberVacation(tag='#AAA'), True,
        False) == config['strings']['roleBlacklisted']
    assert factory.get_role_label(
        'leader', 100, 'bad', MemberVacation(tag='#AAA'), True,
        False) == config['strings']['roleBlacklisted']
    assert factory.get_role_label('leader', 100, 'bad',
                                  MemberVacation(tag='#AAA'), False,
                                  False) == config['strings']['roleVacation']
    assert factory.get_role_label(
        'leader', 100, 'bad', None, False,
        False) == config['strings']['roleInactive'].format(days=100)

    assert factory.get_role_label('leader', 0, 'good', None, False,
                                  False) == config['strings']['roleLeader']
    assert factory.get_role_label('coLeader', 0, 'good', None, False,
                                  False) == config['strings']['roleCoLeader']
    assert factory.get_role_label('elder', 0, 'good', None, False,
                                  False) == config['strings']['roleElder']
    assert factory.get_role_label('member', 0, 'good', None, False,
                                  False) == config['strings']['roleMember']

    assert factory.get_role_label('leader', 0, 'good', None, False,
                                  True) == config['strings']['roleNoPromote']