<commit_before>import datetime

from consts.district_type import DistrictType
from consts.event_type import EventType
from helpers.event_helper import EventHelper

from models.event import Event


class FMSAPIEventListParser(object):

    DATE_FORMAT_STR = "%Y-%m-%dT%H:%M:%S"

    def __init__(self, season):
        self.season = int(season)

    def parse(self, response):
        events = []
        for event in response['Events']:
            code = event['code'].lower()
            key = "{}{}".format(self.season, code)
            name = event['name']
            short_name = EventHelper.getShortName(name)
            event_type = EventHelper.parseEventType(event['type'])
            district_enum = EventHelper.parseDistrictName(event['districtCode'].lower()) if event['districtCode'] else DistrictType.NO_DISTRICT
            venue = event['venue']
            location = "{}, {}, {}".format(event['city'], event['stateprov'], event['country'])
            start = datetime.datetime.strptime(event['dateStart'], self.DATE_FORMAT_STR)
            end = datetime.datetime.strptime(event['dateEnd'], self.DATE_FORMAT_STR)

            # TODO read timezone from API

            # Do not read in CMP divisions, we'll add those manually
            if event_type in EventType.CMP_EVENT_TYPES:
                continue

            events.append(Event(
                id=key,
                name=name,
                short_name=short_name,
                event_short=code,
                event_type_enum=event_type,
                official=True,
                start_date=start,
                end_date=end,
                venue=venue,
                location=location,
                venue_address=None,  # FIRST API doesn't provide detailed venue address
                year=self.season,
                event_district_enum=district_enum
            ))
        return events
<commit_msg>Populate CMP events with FRC API<commit_after>import datetime
import logging

from consts.district_type import DistrictType
from consts.event_type import EventType
from helpers.event_helper import EventHelper

from models.event import Event


class FMSAPIEventListParser(object):

    DATE_FORMAT_STR = "%Y-%m-%dT%H:%M:%S"

    EVENT_TYPES = {
        'regional': EventType.REGIONAL,
        'districtevent': EventType.DISTRICT,
        'districtchampionship': EventType.DISTRICT_CMP,
        'championshipsubdivision': EventType.CMP_DIVISION,
        'championship': EventType.CMP_FINALS,
        'offseason': EventType.OFFSEASON,
    }

    EVENT_CODE_EXCEPTIONS = {
        'cmp-archimedes': ('arc', 'Archimedes'),  # (code, short_name)
        'cmp-carson': ('cars', 'Carson'),
        'cmp-carver': ('carv', 'Carver'),
        'cmp-curie': ('cur', 'Curie'),
        'cmp-galileo': ('gal', 'Galileo'),
        'cmp-hopper': ('hop', 'Hopper'),
        'cmp-newton': ('new', 'Newton'),
        'cmp-tesla': ('tes', 'Tesla'),
        'cmp': ('cmp', 'Einstein'),
    }

    def __init__(self, season):
        self.season = int(season)

    def parse(self, response):
        events = []
        for event in response['Events']:
            code = event['code'].lower()
            event_type = self.EVENT_TYPES.get(event['type'].lower(), None)
            if event_type is None:
                logging.warn("Event type '{}' not recognized!".format(event['type']))
                continue
            key = "{}{}".format(self.season, code)
            name = event['name']
            short_name = EventHelper.getShortName(name)
            district_enum = EventHelper.parseDistrictName(event['districtCode'].lower()) if event['districtCode'] else DistrictType.NO_DISTRICT
            venue = event['venue']
            location = "{}, {}, {}".format(event['city'], event['stateprov'], event['country'])
            start = datetime.datetime.strptime(event['dateStart'], self.DATE_FORMAT_STR)
            end = datetime.datetime.strptime(event['dateEnd'], self.DATE_FORMAT_STR)

            # TODO read timezone from API

            # Special cases for champs
            if code in self.EVENT_CODE_EXCEPTIONS:
                code, short_name = self.EVENT_CODE_EXCEPTIONS[code]
                if code == 'cmp':  # Einstein
                    name = '{} Field'.format(short_name)
                    start = end.replace(hour=0, minute=0, second=0, microsecond=0)  # Set to beginning of last day
                else:  # Divisions
                    name = '{} Division'.format(short_name)

            events.append(Event(
                id=key,
                name=name,
                short_name=short_name,
                event_short=code,
                event_type_enum=event_type,
                official=True,
                start_date=start,
                end_date=end,
                venue=venue,
                location=location,
                venue_address=None,  # FIRST API doesn't provide detailed venue address
                year=self.season,
                event_district_enum=district_enum
            ))
        return events

{'fraction_non_alphanumeric': 0.11605911330049261, 'fraction_numerical': 0.0007881773399014779, 'mean_word_length': 2.137206427688504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146332', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1370, 'n_words': 291}