class Candidate(CandidateBase):

    def __init__(self):
        self.sheet = Sheet()

    def get_all(self):
        cands = self.sheet.get_rows(configs.CANDIDATES_SHEET_ID, configs.CANDIDATES_SHEET_RANGE)
        return [{'id': cand[0], 'name': cand[1], 'email': cand[2]} for cand in cands]
Example #2
0
class Allocation:
    def __init__(self):
        self.sheet = Sheet()

    def generate_allocation(self, candidates):
        allocation = logics.get_random_allocation(candidates)
        return allocation

    def create_allocation(self, match, allocations):
        if not self.sheet.if_exists(configs.ALLOCATIONS_SHEET_ID, match['no']):
            response = self.sheet.create_sheet(configs.ALLOCATIONS_SHEET_ID,
                                               match['no'])

        values = [["Match Number", match['no'], '', '', 'Created Date Time']]
        values.append([
            "Teams", match["team1"] + ' - vs - ' + match["team2"], '', '',
            str(datetime.datetime.now())
        ])
        values.append(["No", "Email", "Name", "Player 1", "Player 2"])

        fdic = []
        for i in range(1, len(allocations) + 1):
            fdic.append([
                data for data in allocations
                if int(data['candidate']['id']) == i
            ][0])
        allocations = fdic

        for alloc in allocations:
            values.append([
                alloc['candidate']['id'], alloc['candidate']['email'],
                alloc['candidate']['name'], alloc['players'][0],
                alloc['players'][1]
            ])

        self.sheet.update_values(configs.ALLOCATIONS_SHEET_ID,
                                 match['no'] + "!A1", 'USER_ENTERED', values)
        return values

    def get_allocation(self, match):
        rows = self.sheet.get_rows(
            configs.ALLOCATIONS_SHEET_ID,
            "'" + match + "'!" + configs.ALLOCATIONS_GET_SHEET_RANGE_POSTFIX)
        allocations = []
        for row in rows:
            allocations.append({
                'no': row[0],
                'name': row[1],
                'email': row[2],
                'player1': row[3],
                'player2': row[4]
            })
        return allocations
Example #3
0
class Match:
    def __init__(self):
        self.sheet = Sheet()

    def get_all(self):
        vals = self.sheet.get_rows(configs.MATCHES_SHEET_ID,
                                   configs.MATCHES_SHEET_RANGE)
        matches = []
        for val in vals:
            matches.append({'no': val[0], 'team1': val[1], 'team2': val[2]})
        return matches

    def get(self, match_no):
        matches = self.get_all()
        return [match for match in matches if match['no'] == match_no][0]
class MatchResults:
    def __init__(self):
        self.sheet = Sheet()

    def get(self, match_no):
        vals = self.sheet.get_rows(
            configs.MATCH_RESULTS_SHEET_ID,
            "'" + match_no + "'" + configs.MATCH_RESULTS_SHEET_RANGE_POSTFIX)
        results = []
        for val in vals:
            results.append({
                'player': val[0],
                'player_name': val[1],
                'runs': val[2],
                'wickets': val[3]
            })
        return results