Ejemplo n.º 1
0
    def getShortName(self, name_str, district_code=None):
        """
        Extracts a short name like "Silicon Valley" from an event name like
        "Silicon Valley Regional sponsored by Google.org".

        See https://github.com/the-blue-alliance/the-blue-alliance-android/blob/master/android/src/test/java/com/thebluealliance/androidclient/test/helpers/EventHelperTest.java
        """
        district_keys = memcache.get(
            'EventHelper.getShortName():district_keys')
        if not district_keys:
            codes = set([
                d.id()[4:].upper()
                for d in District.query().fetch(keys_only=True)
            ])
            if district_code:
                codes.add(district_code.upper())
            district_keys = '|'.join(codes)
        memcache.set('EventHelper.getShortName():district_keys', district_keys,
                     60 * 60)

        # 2015+ districts
        # Numbered events with no name
        re_string = '({}) District Event (#\d+)'.format(district_keys)
        match = re.match(re_string, name_str)
        if match:
            return '{} {}'.format(
                match.group(1).strip(),
                match.group(2).strip())
        # The rest
        re_string = '(?:{}) District -?(.+)'.format(district_keys)
        match = re.match(re_string, name_str)
        if match:
            partial = match.group(1).strip()
            match2 = re.sub(r'(?<=[\w\s])Event\s*(?:[\w\s]*$)?', '', partial)
            return match2.strip()

        # 2014- districts
        # district championships, other districts, and regionals
        name_str = re.sub(r'\s?Event', '', name_str)
        match = re.match(
            r'\s*(?:MAR |PNW |)(?:FIRST Robotics|FRC|)(.+)(?:District|Regional|Region|Provincial|State|Tournament|FRC|Field)(?:\b)(?:[\w\s]+?(#\d*)*)?',
            name_str)

        if match:
            short = ''.join(match.groups(''))
            match = re.match(r'(.+)(?:FIRST Robotics|FRC)', short)
            if match:
                result = match.group(1).strip()
            else:
                result = short.strip()
            if result.startswith('FIRST'):
                result = result[5:]
            return result.strip()

        return name_str.strip()
Ejemplo n.º 2
0
    def getShortName(self, name_str, district_code=None):
        """
        Extracts a short name like "Silicon Valley" from an event name like
        "Silicon Valley Regional sponsored by Google.org".

        See https://github.com/the-blue-alliance/the-blue-alliance-android/blob/master/android/src/test/java/com/thebluealliance/androidclient/test/helpers/EventHelperTest.java
        """
        district_keys = memcache.get('EventHelper.getShortName():district_keys')
        if not district_keys:
            codes = set([d.id()[4:].upper() for d in District.query().fetch(keys_only=True)])
            if district_code:
                codes.add(district_code.upper())
            if 'MAR' in codes:  # MAR renamed to FMA in 2019
                codes.add('FMA')
            if 'TX' in codes:  # TX and FIT used interchangeably
                codes.add('FIT')
            district_keys = '|'.join(codes)
        memcache.set('EventHelper.getShortName():district_keys', district_keys, 60*60)

        # 2015+ districts
        # Numbered events with no name
        re_string = '({}) District Event (#\d+)'.format(district_keys)
        match = re.match(re_string, name_str)
        if match:
            return '{} {}'.format(match.group(1).strip(), match.group(2).strip())
        # The rest
        re_string = '(?:{}) District -?(.+)'.format(district_keys)
        match = re.match(re_string, name_str)
        if match:
            partial = match.group(1).strip()
            match2 = re.sub(r'(?<=[\w\s])Event\s*(?:[\w\s]*$)?', '', partial)
            return match2.strip()

        # 2014- districts
        # district championships, other districts, and regionals
        name_str = re.sub(r'\s?Event','', name_str)
        match = re.match(r'\s*(?:MAR |PNW |)(?:FIRST Robotics|FRC|)(.+)(?:District|Regional|Region|Provincial|State|Tournament|FRC|Field)(?:\b)(?:[\w\s]+?(#\d*)*)?', name_str)

        if match:
            short = ''.join(match.groups(''))
            match = re.match(r'(.+)(?:FIRST Robotics|FRC)', short)
            if match:
                result = match.group(1).strip()
            else:
                result = short.strip()
            if result.startswith('FIRST'):
                result = result[5:]
            return result.strip()

        return name_str.strip()
    def get(self, year=None):
        self._require_admin()

        if year:
            year = int(year)
        else:
            year = datetime.now().year

        districts = District.query(District.year == year).fetch(10000)

        self.template_values.update({
            "valid_years": self.VALID_YEARS,
            "selected_year": year,
            "districts": districts,
        })

        path = os.path.join(os.path.dirname(__file__),
                            '../../templates/admin/district_list.html')
        self.response.out.write(template.render(path, self.template_values))
Ejemplo n.º 4
0
 def get_districts_async():
     district_keys = yield District.query().order(-District.year).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)
Ejemplo n.º 5
0
 def get_districts_async():
     district_keys = yield District.query().order(-District.year).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)
Ejemplo n.º 6
0
 def _query_async(self):
     year = self._query_args[0]
     district_keys = yield District.query(
         District.year == year).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)
Ejemplo n.º 7
0
 def _query_async(self):
     abbreviation = self._query_args[0]
     district_keys = yield District.query(District.abbreviation.IN(get_equivalent_codes(abbreviation))).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)
Ejemplo n.º 8
0
 def _query_async(self):
     year = self._query_args[0]
     district_keys = yield District.query(District.year == year).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)
Ejemplo n.º 9
0
 def _query_async(self):
     abbreviation = self._query_args[0]
     district_keys = yield District.query(District.abbreviation == abbreviation).fetch_async(keys_only=True)
     districts = yield ndb.get_multi_async(district_keys)
     raise ndb.Return(districts)