Esempio n. 1
0
    def setUpClass(cls):
        pass
        cls.sheet = StandingsSheet(gsheet_id=TestStandingsSheet.the_gsheet_id)

        cls.loop.run_until_complete(cls.sheet.initialize(wks_name='Standings'))

        match_1_sheetinfo = MatchGSheetInfo(wks_id=0, row=0)
        match_2_sheetinfo = MatchGSheetInfo(wks_id=0, row=1)

        cls.match_1 = TestStandingsSheet.loop.run_until_complete(
            cls._get_match(r1_name='yjalexis',
                           r2_name='macnd',
                           time=datetime.datetime(year=2069,
                                                  month=4,
                                                  day=20,
                                                  hour=4,
                                                  minute=20),
                           cawmentator_name='incnone',
                           gsheet_info=match_1_sheetinfo))
        cls.match_2 = TestStandingsSheet.loop.run_until_complete(
            cls._get_match(r1_name='elad',
                           r2_name='wilarseny',
                           time=None,
                           cawmentator_name=None,
                           gsheet_info=match_2_sheetinfo))
Esempio n. 2
0
async def make_match_from_raw_db_data(row: list) -> Match:
    match_id = int(row[0])
    if match_id in match_library:
        return match_library[match_id]

    match_info = MatchInfo(race_info=await racedb.get_race_info_from_type_id(
        int(row[1])) if row[1] is not None else RaceInfo(),
                           ranked=bool(row[9]),
                           is_best_of=bool(row[10]),
                           max_races=int(row[11]))

    sheet_info = MatchGSheetInfo()
    sheet_info.wks_id = row[14]
    sheet_info.row = row[15]

    new_match = Match(commit_fn=matchdb.write_match,
                      match_id=match_id,
                      match_info=match_info,
                      racer_1_id=int(row[2]),
                      racer_2_id=int(row[3]),
                      suggested_time=row[4],
                      finish_time=row[16],
                      r1_confirmed=bool(row[5]),
                      r2_confirmed=bool(row[6]),
                      r1_unconfirmed=bool(row[7]),
                      r2_unconfirmed=bool(row[8]),
                      cawmentator_id=row[12],
                      channel_id=int(row[13]) if row[13] is not None else None,
                      gsheet_info=sheet_info,
                      autogenned=bool(row[17]))

    await new_match.initialize()
    match_library[new_match.match_id] = new_match
    return new_match
Esempio n. 3
0
    async def get_matches(self, **kwargs):
        """Read racer names and match types from the GSheet; create corresponding matches.

        Parameters
        ----------
        kwargs:
            Parameters to be passed to matchutil.make_match for every match made.

        Returns
        -------
        list[Match]
            The list of created Matches.
        """
        console.debug('get_matches begin...')
        await self.column_data.refresh_footer()

        matches = []
        self._not_found_matches = []
        register_match_ids = self.column_data.match_id is not None and 'register' in kwargs and kwargs[
            'register']
        match_ids = []

        async with Spreadsheets() as spreadsheets:
            value_range = await self.column_data.get_values(spreadsheets)
            console.debug('get_matches: Got values from spreadsheets.')

            if 'values' not in value_range:
                console.debug('get_matches: Values is empty.')
                return matches
            else:
                console.debug('get_matches: Values: {0}'.format(
                    value_range['values']))

            for row_idx, row_values in enumerate(value_range['values']):
                try:
                    racer_1_name = row_values[self.column_data.racer_1].rstrip(
                        ' ')
                    racer_2_name = row_values[self.column_data.racer_2].rstrip(
                        ' ')
                except IndexError:
                    console.warning(
                        'Failed to make match from sheet row: <{}>'.format(
                            row_values))
                    continue

                if not racer_1_name or not racer_2_name:
                    continue

                match_id = None
                if register_match_ids:
                    try:
                        match_id = int(row_values[self.column_data.match_id])
                    except ValueError:
                        pass

                # if racer_1_name[0] not in string.ascii_letters or racer_2_name[0] not in string.ascii_letters:
                #     self._not_found_matches.append('{0}-{1}'.format(racer_1_name, racer_2_name))
                #     continue

                console.debug('get_matches: Creating {0}-{1}'.format(
                    racer_1_name, racer_2_name))

                racer_1 = await userlib.get_user(any_name=racer_1_name,
                                                 register=True)
                racer_2 = await userlib.get_user(any_name=racer_2_name,
                                                 register=True)
                if racer_1 is None or racer_2 is None:
                    console.warning(
                        'Couldn\'t find racers for match {0}-{1}.'.format(
                            racer_1_name, racer_2_name))
                    self._not_found_matches.append('{0}-{1}'.format(
                        racer_1_name, racer_2_name))
                    continue

                sheet_info = MatchGSheetInfo()
                sheet_info.wks_id = self.wks_id
                sheet_info.row = row_idx

                kwarg_copy = kwargs.copy()
                if self.column_data.type is not None:
                    match_info = kwarg_copy[
                        'match_info'] if 'match_info' in kwargs else matchinfo.MatchInfo(
                        )
                    try:
                        parsed_args = shlex.split(
                            row_values[self.column_data.type])

                        for arg in parsed_args:
                            try:
                                attr, value = arg.split('=')
                            except ValueError:
                                continue
                            setattr(match_info, attr, int(value))

                        kwarg_copy['match_info'] = match_info
                    except IndexError:
                        pass

                new_match = await matchutil.make_match(
                    update=True,
                    match_id=match_id,
                    racer_1_id=racer_1.user_id,
                    racer_2_id=racer_2.user_id,
                    gsheet_info=sheet_info,
                    **kwarg_copy)
                if new_match is None:
                    self._not_found_matches.append('{0}-{1}'.format(
                        racer_1_name, racer_2_name))
                    continue

                matches.append(new_match)
                console.debug('get_matches: Created {0}-{1}'.format(
                    new_match.racer_1.rtmp_name, new_match.racer_2.rtmp_name))

                if register_match_ids:
                    match_ids.append([new_match.match_id])

        if register_match_ids:
            ids_range = self.column_data.get_range_for_column(
                self.column_data.match_id)
            await self.column_data.update_cells(sheet_range=ids_range,
                                                values=match_ids,
                                                raw_input=True)

        console.debug('get_matches: Returning Matches=<{}>'.format(matches))
        return matches