Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix smashgg match order #176

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions scraper/smashgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ def __init__(self, path, included_phases):

self.event_dict = SmashGGScraper.get_event_dict(self.event_name, self.phase_name)

self.group_sets = []
for phase in self.included_phases:
self.group_sets.append(
SmashGGScraper.get_group_ids_from_phase(phase))

self.group_ids = []
for group_set in self.group_sets:
for group_id in group_set:
self.group_ids.append(group_id)
self.group_ids = SmashGGScraper.get_group_ids_from_phase_ids(self.included_phases)

self.group_dicts = [SmashGGScraper.get_group_dict(
group_id) for group_id in self.group_ids]
Expand Down Expand Up @@ -165,6 +157,7 @@ def get_smashgg_matches(self):
like how far into the tournament or how many matches were played.
"""
self.matches = []
grand_finals_matches = []
for group_dict in self.group_dicts:
for match in group_dict['entities']['sets']:
winner_id = match['winnerId']
Expand Down Expand Up @@ -197,7 +190,13 @@ def get_smashgg_matches(self):

smashgg_match = SmashGGMatch(
round_name, winner_id, loser_id, round_num, best_of)
self.matches.append(smashgg_match)

if match['isGF']:
grand_finals_matches.append(smashgg_match)
else:
self.matches.append(smashgg_match)

self.matches.extend(grand_finals_matches)

def get_group_ids(self):
group_ids = [str(group['id']).strip()
Expand Down Expand Up @@ -289,6 +288,22 @@ def get_group_ids_from_phase(phase_id):
phase_ids.append(group['id'])
return phase_ids

@staticmethod
def get_group_ids_from_phase_ids(phase_ids):
phase_raw_dict = {}
for phase_id in phase_ids:
phase_raw_dict[phase_id] = check_for_200(requests.get(PHASE_URL % phase_id)).json()

ordered_phase_ids = phase_raw_dict.keys()
ordered_phase_ids.sort(key=lambda phase_id: phase_raw_dict[phase_id]['entities']['phase']['phaseOrder'])

group_ids = []
for phase_id in ordered_phase_ids:
groups = phase_raw_dict[phase_id]['entities']['groups']
for group in groups:
group_ids.append(group['id'])
return group_ids

@staticmethod
def get_phase_ids(event_name, phase_name):
ids = []
Expand Down
23 changes: 17 additions & 6 deletions test/test_scraper/test_smashgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,35 @@ def test_get_players(self):
self.assertEquals(len(self.tournament2.get_players()), 75)

def test_get_matches(self):
self.assertEqual(len(self.tournament1.get_matches()), 731)
tournament_1_matches = self.tournament1.get_matches()
self.assertEqual(len(tournament_1_matches), 731)
# spot check that mang0 got double elim'd
mango_count = 0
for m in self.tournament1.get_matches():
for m in tournament_1_matches:
if m.loser == 'C9 | Mango':
mango_count += 1
print mango_count
self.assertEqual(2, mango_count, msg="mango didnt get double elim'd?")

self.assertEquals(len(self.tournament2.get_matches()), 361)
# Make sure grand finals is at the end
grand_finals = tournament_1_matches[-1]
self.assertEqual('TSM | Leffen', grand_finals.winner)
self.assertEqual('Liquid` | Hungrybox', grand_finals.loser)

tournament_2_matches = self.tournament2.get_matches()
self.assertEquals(len(tournament_2_matches), 361)
# spot check that Druggedfox was only in 5 matches, and that he won all of them
sami_count = 0
for m in self.tournament2.get_matches():
for m in tournament_2_matches:
if m.winner == 'Druggedfox':
sami_count += 1
self.assertFalse(m.loser == 'Druggedfox')
self.assertEqual(14, sami_count)

# Make sure grand finals is at the end
grand_finals = tournament_2_matches[-1]
self.assertEqual('Druggedfox', grand_finals.winner)
self.assertEqual('PG | ESAM', grand_finals.loser)

def test_get_date(self):
date = self.tournament1.get_date()
self.assertEqual(date.year, 2015)
Expand Down Expand Up @@ -176,4 +187,4 @@ def test_get_phasename_id_map(self):

def test_included_phases(self):
self.assertEqual(len(self.tournament2.group_dicts), 9)
self.assertEqual(len(self.tournament4.group_dicts), 9)
self.assertEqual(len(self.tournament4.group_dicts), 9)