def test_simple_region_ranking(self):
        self.process_ladder(league=League.GOLD,
                            members=[
                                gen_member(points=90),
                                gen_member(points=80),
                            ])

        self.process_ladder(league=League.SILVER,
                            members=[
                                gen_member(points=95),
                                gen_member(points=10),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(
            self.db.ranking.id,
            dict(region_count=4, region_rank=1, points=90, league=League.GOLD),
            dict(region_count=4, region_rank=2, points=80, league=League.GOLD),
            dict(region_count=4,
                 region_rank=3,
                 points=95,
                 league=League.SILVER),
            dict(region_count=4,
                 region_rank=4,
                 points=10,
                 league=League.SILVER),
        )
    def test_fetch_replaces_500_with_200_cache(self):
        ladder = self.db.create_ladder(bid=100,
                                       season=self.s16,
                                       strangeness=Ladder.MISSING,
                                       member_count=None,
                                       max_points=None)
        cache = self.db.create_cache(bid=100,
                                     status=500,
                                     ladder=ladder,
                                     updated=self.datetime(days=-2))

        self.mock_fetch_ladder(status=200,
                               members=[
                                   gen_member(bid=300, points=104),
                                   gen_member(bid=301, points=102)
                               ])

        self.refetch_missing()

        ladder.refresh_from_db()
        cache.refresh_from_db()

        self.assertEqual(Ladder.GOOD, ladder.strangeness)
        self.assertEqual(2, ladder.member_count)
        self.assertEqual(104, ladder.max_points)

        self.assertEqual(200, cache.status)
        self.assertEqual(0, cache.retry_count)
    def test_updating_with_members_at_end_or_beginning_or_mid_works(self):
        self.process_ladder(members=[
            gen_member(bid=302, points=40),
            gen_member(bid=304, points=20),
        ])

        self.process_ladder(members=[
            gen_member(bid=301, points=50),
            gen_member(bid=303, points=30),
            gen_member(bid=305, points=10),
        ])

        self.save_to_ranking()

        t1, t2, t3, t4, t5 = self.db.get_teams_by_member0_bids(
            301, 302, 303, 304, 305)

        self.assert_team_ranks(
            self.db.ranking.id,
            dict(team_id=t1, points=50),
            dict(team_id=t2, points=40),
            dict(team_id=t3, points=30),
            dict(team_id=t4, points=20),
            dict(team_id=t5, points=10),
        )
Beispiel #4
0
    def test_trigger_bug_insert_before_replace_will_make_double_insert(self):

        p1 = self.db.create_player(bid=301)
        t1 = self.db.create_team(member0=p1)

        p2 = self.db.create_player(bid=302)
        t2 = self.db.create_team(member0=p2)

        p3 = self.db.create_player(bid=303)
        t3 = self.db.create_team(member0=p3)

        self.process_ladder(members=[
            gen_member(bid=301),
            gen_member(bid=303),
        ])

        self.process_ladder(members=[
            gen_member(bid=302),
            gen_member(bid=303),
        ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(team_id=t1.id),
                               dict(team_id=t2.id),
                               dict(team_id=t3.id),
                               sort=False
                               )
Beispiel #5
0
    def test_ranking_world_region_league_tier_and_ladder_ranking_at_once_works_as_expected(self):
        self.process_ladder(region=Region.EU, league=League.SILVER,
                            members=[
                                gen_member(points=90),
                                gen_member(points=80),
                            ])

        self.process_ladder(region=Region.EU, league=League.GOLD,
                            members=[
                                gen_member(points=77),
                                gen_member(points=33),
                            ])

        self.process_ladder(region=Region.AM, league=League.GOLD,
                            members=[
                                gen_member(points=95),
                                gen_member(points=10),
                            ])

        self.process_ladder(region=Region.KR, league=League.GRANDMASTER,
                            members=[
                                gen_member(points=1),
                            ])

        self.process_ladder(region=Region.EU, league=League.SILVER, tier=1,
                            members=[
                                gen_member(points=90),
                                gen_member(points=80),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(world_rank=1,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    world_count=9, region_count=1, league_count=1, ladder_count=1,
                                    points=1, region=Region.KR, league=League.GRANDMASTER),
                               dict(world_rank=2,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    world_count=9, region_count=2, league_count=2, ladder_count=2,
                                    points=95, region=Region.AM, league=League.GOLD),
                               dict(world_rank=3,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    world_count=9, region_count=6, league_count=2, ladder_count=2,
                                    points=77, region=Region.EU, league=League.GOLD),
                               dict(world_rank=4,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    world_count=9, region_count=6, league_count=2, ladder_count=2,
                                    points=33, region=Region.EU, league=League.GOLD),
                               dict(world_rank=5,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    world_count=9, region_count=2, league_count=2, ladder_count=2,
                                    points=10, region=Region.AM, league=League.GOLD),
                               dict(world_rank=6,  region_rank=3,  league_rank=1,  ladder_rank=1, tier=0,
                                    world_count=9, region_count=6, league_count=4, ladder_count=2,
                                    points=90, region=Region.EU, league=League.SILVER),
                               dict(world_rank=7,  region_rank=4,  league_rank=2,  ladder_rank=2, tier=0,
                                    world_count=9, region_count=6, league_count=4, ladder_count=2,
                                    points=80, region=Region.EU, league=League.SILVER),
                               dict(world_rank=8,  region_rank=5,  league_rank=3,  ladder_rank=1, tier=1,
                                    world_count=9, region_count=6, league_count=4, ladder_count=2,
                                    points=90, region=Region.EU, league=League.SILVER),
                               dict(world_rank=9,  region_rank=6,  league_rank=4,  ladder_rank=2, tier=1,
                                    world_count=9, region_count=6, league_count=4, ladder_count=2,
                                    points=80, region=Region.EU, league=League.SILVER))
Beispiel #6
0
    def test_simple_ladder_ranking(self):
        self.process_ladder(members=[
            gen_member(points=90),
            gen_member(points=80),
        ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(ladder_count=2, ladder_rank=1, points=90),
                               dict(ladder_count=2, ladder_rank=2, points=80),
                               )
Beispiel #7
0
    def test_process_two_4v4_ladders_with_the_same_team_but_different_order_just_creates_one_team(self):
        self.process_ladder(mode=Mode.TEAM_4V4,
                            members=[gen_member(bid=301, race=Race.ZERG),
                                     gen_member(bid=302, race=Race.PROTOSS),
                                     gen_member(bid=303, race=Race.TERRAN),
                                     gen_member(bid=304, race=Race.RANDOM)])

        self.process_ladder(mode=Mode.TEAM_4V4,
                            members=[gen_member(bid=304, race=Race.RANDOM),
                                     gen_member(bid=303, race=Race.TERRAN),
                                     gen_member(bid=302, race=Race.PROTOSS),
                                     gen_member(bid=301, race=Race.ZERG)])

        self.assertEqual(1, len(self.db.all(Team)))

        p1 = self.db.get(Player, bid=301)
        p2 = self.db.get(Player, bid=302)
        p3 = self.db.get(Player, bid=303)
        p4 = self.db.get(Player, bid=304)
        t1 = self.db.all(Team)[0]

        self.assertEqual(1, len(self.db.all(Team)))
        self.assertEqual(Mode.TEAM_4V4, t1.mode)
        self.assertEqual(p1.id, t1.member0_id)
        self.assertEqual(p2.id, t1.member1_id)
        self.assertEqual(p3.id, t1.member2_id)
        self.assertEqual(p4.id, t1.member3_id)
        self.assertEqual(Race.ZERG,    t1.race0)
        self.assertEqual(Race.PROTOSS, t1.race1)
        self.assertEqual(Race.TERRAN,  t1.race2)
        self.assertEqual(Race.RANDOM,  t1.race3)
    def test_race3_is_not_overwritten__this_was_a_bug(self):
        self.db.create_season(id=29)
        self.db.create_ranking()

        self.process_ladder(mode=Mode.TEAM_4V4,
                            members=[
                                gen_member(race=Race.ZERG),
                                gen_member(race=Race.ZERG),
                                gen_member(race=Race.ZERG),
                                gen_member(race=Race.ZERG),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id, dict(race3=Race.ZERG))
Beispiel #9
0
 def test_categorize_as_nop_if_ceritain_time_good_points_and_no_ap(self):
     al = gen_api_ladder(members=[
         gen_member(points=1, join_time=self.datetime(days=-20)),
     ],
                         gd=False)
     self.assertEqual(Ladder.NOP,
                      get_strangeness(self.datetime(), al, ap=None))
Beispiel #10
0
 def test_categorize_as_genuine_strange_imediatly(self):
     al = gen_api_ladder(members=[
         gen_member(points=1.2, join_time=self.s16_time),
     ],
                         gd=False)
     self.assertEqual(Ladder.STRANGE,
                      get_strangeness(self.datetime(), al, ap=None))
Beispiel #11
0
    def process_ladder(self, load=False, save=False, region=Region.EU, fetch_time=None,
                       mode=Mode.TEAM_1V1, version=Version.HOTS, league=League.GOLD, season=None, tier=0,
                       members=None, **kwargs):
        """ Update a ranking building single member with kwargs or use members if set. """

        season = season or self.db.season
        fetch_time = fetch_time or utcnow()
        members = members or [gen_member(**kwargs)]

        if not getattr(self, 'cpp', None):
            self.cpp = sc2.RankingData(self.db.db_name, Enums.INFO)

        if load:
            self.load()

        self.cpp.update_with_ladder(0,  # bid
                                    0,  # source_id
                                    region,
                                    mode,
                                    league,
                                    tier,
                                    version,
                                    season.id,
                                    to_unix(fetch_time),
                                    fetch_time.date().isoformat(),
                                    Mode.team_size(mode),
                                    members)
        if save:
            self.save_to_ranking()
Beispiel #12
0
 def test_exception_if_ap_and_strange_points(self):
     al = gen_api_ladder(members=[
         gen_member(points=1.1, join_time=self.datetime(days=-7)),
     ],
                         gd=False)
     with self.assertRaises(Exception):
         get_strangeness(self.datetime(), al, ap=1)
Beispiel #13
0
    def test_team_is_updated_with_both_version_and_league_with_new_season_test_2(
            self):
        p1 = self.db.create_player(bid=301, race=Race.ZERG)

        t1 = self.db.create_team(mode=Mode.TEAM_1V1,
                                 season=self.s1,
                                 version=Version.WOL,
                                 league=League.GOLD,
                                 member0=p1,
                                 race0=Race.ZERG)

        self.db.create_ranking(season=self.s2)

        self.process_ladder(mode=Mode.TEAM_1V1,
                            season=self.s2,
                            version=Version.HOTS,
                            league=League.PLATINUM,
                            members=[gen_member(bid=301, race=Race.ZERG)])

        self.assertEqual(1, len(Team.objects.all()))

        t1 = self.db.get(Team, member0=self.db.get(Player, bid=301))

        self.assertEqual(self.s2, t1.season)
        self.assertEqual(Version.HOTS, t1.version)
        self.assertEqual(League.PLATINUM, t1.league)
    def test_same_player_in_two_teams_multiple_ladders_but_different_modes_and_both_are_in_ranking(
            self):
        self.process_ladder(mode=Mode.RANDOM_4V4,
                            members=[
                                gen_member(bid=301, points=20),
                                gen_member(bid=302, points=10),
                            ])

        self.process_ladder(mode=Mode.RANDOM_3V3,
                            members=[
                                gen_member(bid=301, points=10),
                                gen_member(bid=302, points=20),
                            ])

        self.save_to_ranking()

        t1, t2 = self.db.get_teams_by_member0_bids(301,
                                                   302,
                                                   mode=Mode.RANDOM_3V3)
        t3, t4 = self.db.get_teams_by_member0_bids(301,
                                                   302,
                                                   mode=Mode.RANDOM_4V4)

        self.assert_team_ranks(
            self.db.ranking.id,
            dict(team_id=t2,
                 region_count=2,
                 region_rank=1,
                 points=20,
                 mode=Mode.RANDOM_3V3),
            dict(team_id=t1,
                 region_count=2,
                 region_rank=2,
                 points=10,
                 mode=Mode.RANDOM_3V3),
            dict(team_id=t3,
                 region_count=2,
                 region_rank=1,
                 points=20,
                 mode=Mode.RANDOM_4V4),
            dict(team_id=t4,
                 region_count=2,
                 region_rank=2,
                 points=10,
                 mode=Mode.RANDOM_4V4),
        )
Beispiel #15
0
 def test_categorize_as_good_if_ap(self):
     al = gen_api_ladder(members=[
         gen_member(points=1, join_time=self.datetime(days=-7)),
     ],
                         gd=False)
     self.assertEqual(Ladder.GOOD, get_strangeness(self.datetime(),
                                                   al,
                                                   ap=1))
Beispiel #16
0
 def test_what_happens_if_low_member_count_and_random_strange_but_even_(
         self):
     al = gen_api_ladder(members=[
         gen_member(points=1, join_time=self.datetime(days=-20)),
     ],
                         gd=False)
     self.assertEqual(Ladder.NOP,
                      get_strangeness(self.datetime(), al, ap=None))
    def test_player_occurs_in_several_teams_in_the_same_ladder_creates_one_player(
            self):
        # See our friend drake (bid 5305519, realm 1, region 1) in ladder 164930.

        self.db.create_ranking()
        self.process_ladder(mode=Mode.TEAM_2V2,
                            members=[
                                gen_member(bid=301,
                                           realm=0,
                                           name="arne1",
                                           race=Race.TERRAN),
                                gen_member(bid=302,
                                           realm=0,
                                           name="arne2",
                                           race=Race.TERRAN),
                                gen_member(bid=303,
                                           realm=0,
                                           name="arne3",
                                           race=Race.TERRAN),
                                gen_member(bid=301,
                                           realm=0,
                                           name="arne1",
                                           race=Race.TERRAN),
                            ])

        self.assertEqual(3, len(Player.objects.all()))

        p1 = self.db.get(Player, bid=301)
        p2 = self.db.get(Player, bid=302)
        p3 = self.db.get(Player, bid=303)

        self.assertEqual(2, len(Team.objects.all()))

        t1, t2 = self.db.filter(Team,
                                member1_id__in=(p2.id, p3.id)).order_by('id')

        self.assertEqual(t1.member0_id, p1.id)
        self.assertEqual(t1.member1_id, p2.id)
        self.assertEqual(t2.member0_id, p1.id)
        self.assertEqual(t2.member1_id, p3.id)

        self.assertEqual('arne1', p1.name)
        self.assertEqual('arne2', p2.name)
        self.assertEqual('arne3', p3.name)
Beispiel #18
0
    def test_process_two_2v2_ladders_with_the_same_team_but_different_order_just_creates_one_team(self):
        self.process_ladder(mode=Mode.TEAM_2V2, members=[gen_member(bid=301, race=Race.ZERG),
                                                         gen_member(bid=302, race=Race.PROTOSS)])

        self.assertEqual(1, len(self.db.all(Team)))

        p1 = self.db.get(Player, bid=301)
        p2 = self.db.get(Player, bid=302)
        t1 = self.db.all(Team)[0]

        self.assertEqual(Mode.TEAM_2V2, t1.mode)
        self.assertEqual(p1.id, t1.member0_id)
        self.assertEqual(p2.id, t1.member1_id)
        self.assertEqual(None,  t1.member2_id)
        self.assertEqual(None,  t1.member3_id)
        self.assertEqual(Race.ZERG,     t1.race0)
        self.assertEqual(Race.PROTOSS,  t1.race1)
        self.assertEqual(Race.UNKNOWN,  t1.race2)
        self.assertEqual(Race.UNKNOWN,  t1.race3)
Beispiel #19
0
    def test_region_ranking_does_rank_calculation_correctly_when_teams_have_same_points(self):
        self.process_ladder(members=[
            gen_member(points=90),
            gen_member(points=90),
        ])

        self.process_ladder(members=[
            gen_member(points=90),
            gen_member(points=10),
        ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(region_rank=1, world_rank=1, points=90),
                               dict(region_rank=1, world_rank=1, points=90),
                               dict(region_rank=1, world_rank=1, points=90),
                               dict(region_rank=4, world_rank=4, points=10),
                               )
Beispiel #20
0
    def test_same_random_2v2__can_not_have_multiple_rankings_with_different_races(self):
        
        self.process_ladder(league=League.SILVER,
                            mode=Mode.RANDOM_2V2,
                            members=[
                                gen_member(bid=1, mmr=40, race=Race.TERRAN),
                            ])

        self.process_ladder(league=League.GOLD,
                            mode=Mode.RANDOM_2V2,
                            members=[
                                gen_member(bid=1, mmr=90, race=Race.ZERG),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(
            self.db.ranking.id,
            dict(region_count=1, region_rank=1, mmr=90, race0=Race.ZERG, league=League.GOLD),
        )
Beispiel #21
0
    def test_simple_world_ranking(self):
        self.process_ladder(region=Region.EU, league=League.GOLD,
                            members=[
                                gen_member(points=90),
                                gen_member(points=80),
                            ])

        self.process_ladder(region=Region.AM, league=League.GOLD,
                            members=[
                                gen_member(points=95),
                                gen_member(points=10),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(world_count=4, world_rank=1, points=95),
                               dict(world_count=4, world_rank=2, points=90),
                               dict(world_count=4, world_rank=3, points=80),
                               dict(world_count=4, world_rank=4, points=10),
                               )
Beispiel #22
0
    def test_same_1v1_can_have_multiple_rankings_with_different_races_among_other_players(self):
        self.process_ladder(league=League.SILVER,
                            members=[
                                gen_member(bid=2, mmr=50, race=Race.ZERG),
                                gen_member(bid=1, mmr=40, race=Race.TERRAN),
                                gen_member(bid=3, mmr=30, race=Race.RANDOM),
                            ])

        self.process_ladder(league=League.GOLD,
                            members=[
                                gen_member(bid=1, mmr=90, race=Race.ZERG),
                                gen_member(bid=4, mmr=80, race=Race.PROTOSS),
                                gen_member(bid=5, mmr=70, race=Race.TERRAN),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(
            self.db.ranking.id,
            dict(region_count=6, region_rank=1, mmr=90, race0=Race.ZERG,    race3=9, league=League.GOLD),
            dict(region_count=6, region_rank=2, mmr=80, race0=Race.PROTOSS, race3=9, league=League.GOLD),
            dict(region_count=6, region_rank=3, mmr=70, race0=Race.TERRAN,  race3=9, league=League.GOLD),
            dict(region_count=6, region_rank=4, mmr=50, race0=Race.ZERG,    race3=9, league=League.SILVER),
            dict(region_count=6, region_rank=5, mmr=40, race0=Race.TERRAN,  race3=8, league=League.SILVER),
            dict(region_count=6, region_rank=6, mmr=30, race0=Race.RANDOM,  race3=9, league=League.SILVER),
        )
Beispiel #23
0
    def test_same_team_in_multiple_ladders_select_later_added_instance_and_disregards_times(self):
        # Given this, the ranker will have to rank ladders in fetch order to prevent overwriting data when teams
        # change ladder due to promotion/demotion.

        self.process_ladder(league=League.PLATINUM,
                            fetch_time=self.datetime(days=-200),
                            members=[
                                gen_member(bid=301,
                                           race=Race.ZERG,
                                           join_time=int(self.unix_time(days=-410))),
                                gen_member(bid=302,
                                           race=Race.TERRAN,
                                           join_time=int(self.unix_time(days=-400))),
                                gen_member(bid=303,
                                           race=Race.PROTOSS,
                                           join_time=int(self.unix_time(days=-400)),
                                           points=20,
                                           wins=50),
                                gen_member(bid=304,
                                           race=Race.RANDOM,
                                           join_time=int(self.unix_time(days=-400)),
                                           points=10,
                                           wins=40,
                                           losses=10),
                            ])
        
        self.process_ladder(league=League.GOLD,
                            fetch_time=self.datetime(days=-330),
                            members=[
                                gen_member(bid=302,
                                           race=Race.TERRAN,
                                           join_time=int(self.unix_time(days=-410))),
                                gen_member(bid=303,
                                           race=Race.PROTOSS,
                                           join_time=int(self.unix_time(days=-410)),
                                           points=20,
                                           wins=60),
                                gen_member(bid=304,
                                           race=Race.RANDOM,
                                           join_time=int(self.unix_time(days=-410)),
                                           points=10,
                                           wins=40,
                                           losses=20),
                            ])

        self.save_to_ranking()

        t1, t2, t3, t4 = self.db.get_teams_by_member0_bids(301, 302, 303, 304)

        self.assert_team_ranks(self.db.ranking.id,
                               dict(team_id=t1, region_count=4, region_rank=1, league=League.PLATINUM),
                               dict(team_id=t2, region_count=4, region_rank=2, league=League.GOLD),
                               dict(team_id=t3, region_count=4, region_rank=3, league=League.GOLD, wins=60),
                               dict(team_id=t4, region_count=4, region_rank=4, league=League.GOLD, wins=40, losses=20),
                               )
Beispiel #24
0
    def test_different_versions_are_ranked_separately(self):
        self.process_ladder(version=Version.HOTS,
                            members=[
                                gen_member(points=20),
                                gen_member(points=10),
                            ])

        self.process_ladder(version=Version.WOL,
                            members=[
                                gen_member(points=21),
                                gen_member(points=11),
                            ])

        self.process_ladder(version=Version.LOTV,
                            members=[
                                gen_member(points=22),
                                gen_member(points=12),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(region_count=2, region_rank=1, world_rank=1, points=21, version=Version.WOL),
                               dict(region_count=2, region_rank=2, world_rank=2, points=11, version=Version.WOL),
                               dict(region_count=2, region_rank=1, world_rank=1, points=20, version=Version.HOTS),
                               dict(region_count=2, region_rank=2, world_rank=2, points=10, version=Version.HOTS),
                               dict(region_count=2, region_rank=1, world_rank=1, points=22, version=Version.LOTV),
                               dict(region_count=2, region_rank=2, world_rank=2, points=12, version=Version.LOTV),
                               )
Beispiel #25
0
    def test_same_team_in_multiple_ladders_but_different_versions_and_all_are_in_the_ranking(self):
        self.process_ladder(version=Version.HOTS,
                            members=[
                                gen_member(bid=301, points=20),
                                gen_member(bid=302, points=10),
                            ])

        self.process_ladder(version=Version.WOL,
                            members=[
                                gen_member(bid=301, points=10),
                                gen_member(bid=302, points=20),
                            ])

        self.process_ladder(version=Version.LOTV,
                            members=[
                                gen_member(bid=301, points=40),
                                gen_member(bid=302, points=30),
                            ])

        self.save_to_ranking()

        t1, t2 = self.db.get_teams_by_member0_bids(301, 302)

        self.assert_team_ranks(self.db.ranking.id,
                               dict(team_id=t2, region_count=2, region_rank=1, points=20, version=Version.WOL),
                               dict(team_id=t1, region_count=2, region_rank=2, points=10, version=Version.WOL),
                               dict(team_id=t1, region_count=2, region_rank=1, points=20, version=Version.HOTS),
                               dict(team_id=t2, region_count=2, region_rank=2, points=10, version=Version.HOTS),
                               dict(team_id=t1, region_count=2, region_rank=1, points=40, version=Version.LOTV),
                               dict(team_id=t2, region_count=2, region_rank=2, points=30, version=Version.LOTV),
                               )
Beispiel #26
0
 def test_non_existent_4v4_team_is_created(self):
     self.process_ladder(mode=Mode.TEAM_4V4,
                         members=[gen_member(bid=301, race=Race.ZERG),
                                  gen_member(bid=302, race=Race.PROTOSS),
                                  gen_member(bid=303, race=Race.TERRAN),
                                  gen_member(bid=304, race=Race.TERRAN)])
     
     p1 = self.db.get(Player, bid=301)
     p2 = self.db.get(Player, bid=302)
     p3 = self.db.get(Player, bid=303)
     p4 = self.db.get(Player, bid=304)
     t1 = self.db.all(Team)[0]
     self.assertEqual(1, len(self.db.all(Team)))
     self.assertEqual(Mode.TEAM_4V4, t1.mode)
     self.assertEqual(p1.id, t1.member0_id)
     self.assertEqual(p2.id, t1.member1_id)
     self.assertEqual(p3.id, t1.member2_id)
     self.assertEqual(p4.id, t1.member3_id)
     self.assertEqual(Race.ZERG,    t1.race0)
     self.assertEqual(Race.PROTOSS, t1.race1)
     self.assertEqual(Race.TERRAN,  t1.race2)
     self.assertEqual(Race.TERRAN,  t1.race3)
Beispiel #27
0
    def test_trigger_insert_replace_and_add_at_the_same_time(self):

        p1 = self.db.create_player(bid=301)
        t1 = self.db.create_team(member0=p1)

        p2 = self.db.create_player(bid=302)
        t2 = self.db.create_team(member0=p2)

        p3 = self.db.create_player(bid=303)
        t3 = self.db.create_team(member0=p3)

        p4 = self.db.create_player(bid=304)
        t4 = self.db.create_team(member0=p4)

        p5 = self.db.create_player(bid=305)
        t5 = self.db.create_team(member0=p5)

        p6 = self.db.create_player(bid=306)
        t6 = self.db.create_team(member0=p6)

        self.process_ladder(members=[
            gen_member(bid=302, points=10),
            gen_member(bid=305),
        ])

        self.process_ladder(members=[
            gen_member(bid=301),
            gen_member(bid=302, points=20),
            gen_member(bid=303),
            gen_member(bid=304),
            gen_member(bid=306),
        ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(team_id=t1.id),
                               dict(team_id=t2.id, points=20),
                               dict(team_id=t3.id),
                               dict(team_id=t4.id),
                               dict(team_id=t5.id),
                               dict(team_id=t6.id),
                               sort=False
                               )
Beispiel #28
0
    def test_refetch_past_seasons_will_refetch_ladder_and_ranking_will_be_updated(
            self):
        p1 = self.db.create_player(name="arne")
        t1 = self.db.create_team()

        l = self.db.create_ladder(bid=100,
                                  season=self.s15,
                                  max_points=20,
                                  updated=self.datetime(days=-30))

        c = self.db.create_cache(bid=100)
        r = self.db.create_ranking(season=self.s15,
                                   data_time=self.datetime(days=-21))

        self.db.create_ranking_data(data=[
            dict(team_id=t1.id, points=20, data_time=self.unix_time(days=-30))
        ])
        self.db.update_ranking_stats()

        al = gen_api_ladder(data=[dict(team_id=t1.id, points=40)], bid=100)

        fetch_time = utcnow()
        self.mock_fetch_ladder(fetch_time=fetch_time,
                               members=[gen_member(bid=p1.bid, points=40)])

        self.refetch_past_seasons()

        self.bnet.fetch_ladder.assert_called_once_with(self.s15.id,
                                                       Region.EU,
                                                       100,
                                                       timeout=20)

        l.refresh_from_db()
        r.refresh_from_db()

        self.assertTrue(abs(fetch_time - l.updated) < timedelta(hours=1))
        self.assertEqual(40, l.max_points)
        self.assertEqual({c.id}, {c.id for c in r.sources.all()})
        self.assert_team_ranks(r.id, dict(points=40))
        self.assertEqual(self.s15.end_time(), r.data_time)
Beispiel #29
0
    def test_update_of_version_to_later_version_is_updated_within_same_season(
            self):
        p1 = self.db.create_player(bid=301, race=Race.ZERG)

        t1 = self.db.create_team(mode=Mode.TEAM_1V1,
                                 season=self.s1,
                                 version=Version.WOL,
                                 league=League.PLATINUM,
                                 member0=p1,
                                 race0=Race.ZERG)

        self.process_ladder(mode=Mode.TEAM_1V1,
                            season=self.s1,
                            version=Version.HOTS,
                            league=League.GOLD,
                            members=[gen_member(bid=301, race=Race.ZERG)])

        t1 = self.db.get(Team, member0=self.db.get(Player, bid=301))

        self.assertEqual(self.s1, t1.season)
        self.assertEqual(Version.HOTS, t1.version)
        self.assertEqual(League.GOLD, t1.league)
Beispiel #30
0
    def test_gm_is_using_points_before_season_28(self):
        self.db.create_season(id=27)
        self.db.create_ranking()

        self.process_ladder(league=League.GRANDMASTER, region=Region.EU,
                            members=[
                                gen_member(points=80),
                                gen_member(points=10),
                            ])

        self.process_ladder(league=League.GRANDMASTER, region=Region.KR,
                            members=[
                                gen_member(points=99),
                                gen_member(points=70),
                                gen_member(points=70),
                            ])

        self.process_ladder(league=League.GRANDMASTER, region=Region.AM,
                            members=[
                                gen_member(points=200),
                                gen_member(points=98),
                            ])

        self.save_to_ranking()

        self.assert_team_ranks(self.db.ranking.id,
                               dict(world_rank=1,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    points=200, region=Region.AM),
                               dict(world_rank=2,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    points=99, region=Region.KR),
                               dict(world_rank=3,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    points=98, region=Region.AM),
                               dict(world_rank=4,  region_rank=1,  league_rank=1,  ladder_rank=1,
                                    points=80, region=Region.EU),
                               dict(world_rank=5,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    points=70, region=Region.KR),
                               dict(world_rank=5,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    points=70, region=Region.KR),
                               dict(world_rank=7,  region_rank=2,  league_rank=2,  ladder_rank=2,
                                    points=10, region=Region.EU))