def get(self):
        suggestions = Suggestion.query().filter(
            Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
            Suggestion.target_model == "offseason-event")

        year = datetime.now().year
        year_events_future = EventListQuery(year).fetch_async()
        last_year_events_future = EventListQuery(year - 1).fetch_async()
        events_and_ids = [self._create_candidate_event(suggestion) for suggestion in suggestions]

        year_events = year_events_future.get_result()
        year_offseason_events = [e for e in year_events if e.event_type_enum == EventType.OFFSEASON]
        last_year_events = last_year_events_future.get_result()
        last_year_offseason_events = [e for e in last_year_events if e.event_type_enum == EventType.OFFSEASON]

        similar_events = [self._get_similar_events(event[1], year_offseason_events) for event in events_and_ids]
        similar_last_year = [self._get_similar_events(event[1], last_year_offseason_events) for event in events_and_ids]

        self.template_values.update({
            'success': self.request.get("success"),
            'event_key': self.request.get("event_key"),
            'events_and_ids': events_and_ids,
            'similar_events': similar_events,
            'similar_last_year': similar_last_year,
        })
        self.response.out.write(
            jinja2_engine.render('suggestions/suggest_offseason_event_review_list.html', self.template_values))
    def test_event_updated(self):
        affected_refs = {
            'key': {ndb.Key(Event, '2015casj'),
                    ndb.Key(Event, '2015cama')},
            'year': {2014, 2015},
            'district_key':
            {ndb.Key(District, '2015fim'),
             ndb.Key(District, '2014mar')}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.event_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 10)
        self.assertTrue(EventQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventQuery('2015cama').cache_key in cache_keys)
        self.assertTrue(EventListQuery(2014).cache_key in cache_keys)
        self.assertTrue(EventListQuery(2015).cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2015fim').cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2014mar').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc254').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc604').cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc604', 2015).cache_key in cache_keys)
示例#3
0
    def categorize_offseasons(cls, year, first_events_offseasons):
        """
        Takes a list of offseason events from FIRST and sorts them in to two groups -
        events that directly or indirectly match TBA events, and events that do not
        match existing TBA events.

        Returns a tuple of events (TBA/FIRST event tuples, new FIRST events)
        """
        year_events_future = EventListQuery(year).fetch_async()
        year_events = year_events_future.get_result()
        tba_events_offseasons = [e for e in year_events if e.is_offseason]

        matched_events = []
        new_events = []

        for first_event in first_events_offseasons:
            tba_event = next((e for e in tba_events_offseasons
                              if cls.is_direct_match(e, first_event)
                              or cls.is_maybe_match(e, first_event)), None)
            if tba_event:
                matched_events.append((tba_event, first_event))
            else:
                new_events.append(first_event)

        return (matched_events, new_events)
示例#4
0
    def get(self, year):
        self._require_admin()
        year = int(year)
        events = EventListQuery(year).fetch()
        events_by_type = defaultdict(list)
        for event in events:
            if event.event_type_enum in self.TYPE_MAP.keys() or event.event_type_enum in self.TYPE_MAP.values():
                events_by_type[event.event_type_enum].append(event)

        output = ""
        for from_type, to_type in self.TYPE_MAP.iteritems():
            for event in events_by_type[to_type]:
                divisions = []
                for candidate_division in events_by_type[from_type]:
                    if candidate_division.end_date.date() == event.end_date.date() and candidate_division.district_key == event.district_key:
                        candidate_division.parent_event = event.key
                        divisions.append(candidate_division.key)
                        output += "Event {} is the parent of {}<br/>".format(event.key_name, candidate_division.key_name)
                        EventManipulator.createOrUpdate(candidate_division)

                event.divisions = divisions
                if divisions:
                    output += "Divisions {} added to {}<br/>".format(event.division_keys_json, event.key_name)
                EventManipulator.createOrUpdate(event)
        self.response.out.write(output)
示例#5
0
def event_updated(affected_refs):
    event_keys = _filter(affected_refs['key'])
    years = _filter(affected_refs['year'])
    event_district_keys = _filter(affected_refs['district_key'])

    event_team_keys_future = EventTeam.query(EventTeam.event.IN([event_key for event_key in event_keys])).fetch_async(None, keys_only=True)
    events_future = ndb.get_multi_async(event_keys)

    queries_and_keys = []
    for event_key in event_keys:
        queries_and_keys.append((EventQuery(event_key.id())))
        queries_and_keys.append(EventDivisionsQuery(event_key.id()))

    for year in years:
        queries_and_keys.append((EventListQuery(year)))

    for event_district_key in event_district_keys:
        queries_and_keys.append((DistrictEventsQuery(event_district_key.id())))

    for et_key in event_team_keys_future.get_result():
        team_key = et_key.id().split('_')[1]
        year = int(et_key.id()[:4])
        queries_and_keys.append((TeamEventsQuery(team_key)))
        queries_and_keys.append((TeamYearEventsQuery(team_key, year)))

    events_with_parents = filter(lambda e: e.get_result() is not None and e.get_result().parent_event is not None, events_future)
    parent_keys = set([e.get_result().parent_event for e in events_with_parents])
    for parent_key in parent_keys:
        queries_and_keys.append((EventDivisionsQuery(parent_key.id())))

    return queries_and_keys
    def test_district_updated(self):
        affected_refs = {
            'key': {ndb.Key(District, '2016ne')},
            'year': {2015, 2016},
            'abbreviation': {'ne', 'chs'}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.district_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 11)
        self.assertTrue(DistrictsInYearQuery(2015).cache_key in cache_keys)
        self.assertTrue(DistrictsInYearQuery(2016).cache_key in cache_keys)
        self.assertTrue(DistrictHistoryQuery('ne').cache_key in cache_keys)
        self.assertTrue(DistrictHistoryQuery('chs').cache_key in cache_keys)
        self.assertTrue(DistrictQuery('2016ne').cache_key in cache_keys)
        self.assertTrue(TeamDistrictsQuery('frc604').cache_key in cache_keys)

        # Necessary because APIv3 Event models include the District model
        self.assertTrue(EventQuery('2016necmp').cache_key in cache_keys)
        self.assertTrue(EventListQuery(2016).cache_key in cache_keys)
        self.assertTrue(DistrictEventsQuery('2016ne').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc125').cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc125', 2016).cache_key in cache_keys)
 def _render(self, year, model_type=None):
     events, self._last_modified = EventListQuery(int(year)).fetch(
         dict_version=3, return_updated=True)
     if model_type is not None:
         events = filter_event_properties(events, model_type)
     return json.dumps(events,
                       ensure_ascii=True,
                       indent=True,
                       sort_keys=True)
    def _render(self, year=None):
        if self.year < 1992 or self.year > datetime.now().year + 1:
            self._errors = json.dumps(
                {"404": "No events found for %s" % self.year})
            self.abort(404)

        events = EventListQuery(self.year).fetch()

        event_list = [ModelToDict.eventConverter(event) for event in events]

        return json.dumps(event_list, ensure_ascii=True)
示例#9
0
 def get(self, year):
     self._require_admin()
     year = int(year)
     events = EventListQuery(year).fetch()
     for event in events:
         if not event.playoff_type:
             if event.year == 2015 and event.key_name not in self.EXCEPTIONS_2015:
                 event.playoff_type = PlayoffType.AVG_SCORE_8_TEAM
             else:
                 event.playoff_type = PlayoffType.BRACKET_8_TEAM
         EventManipulator.createOrUpdate(event)
     self.response.out.write("Update {} events".format(len(events)))
示例#10
0
    def get(self):
        suggestions = Suggestion.query().filter(
            Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
            Suggestion.target_model == "offseason-event")

        year = datetime.now().year
        year_events_future = EventListQuery(year).fetch_async()
        last_year_events_future = EventListQuery(year - 1).fetch_async()
        events_and_ids = [self._create_candidate_event(suggestion) for suggestion in suggestions]

        year_events = year_events_future.get_result()
        year_offseason_events = [e for e in year_events if e.event_type_enum == EventType.OFFSEASON]
        last_year_events = last_year_events_future.get_result()
        last_year_offseason_events = [e for e in last_year_events if e.event_type_enum == EventType.OFFSEASON]

        similar_events = [self._get_similar_events(event[1], year_offseason_events) for event in events_and_ids]
        similar_last_year = [self._get_similar_events(event[1], last_year_offseason_events) for event in events_and_ids]

        self.template_values.update({
            'success': self.request.get("success"),
            'event_key': self.request.get("event_key"),
            'events_and_ids': events_and_ids,
            'similar_events': similar_events,
            'similar_last_year': similar_last_year,
        })
        self.response.out.write(
            jinja2_engine.render('suggestions/suggest_offseason_event_review_list.html', self.template_values))
示例#11
0
    def _render(self, model_type=None):
        futures = []
        for year in tba_config.VALID_YEARS:
            futures.append(EventListQuery(year).fetch_async(dict_version=3, return_updated=True))

        events = []
        for future in futures:
            partial_events, last_modified = future.get_result()
            events += partial_events
            if self._last_modified is None or last_modified > self._last_modified:
                self._last_modified = last_modified

        if model_type is not None:
            events = filter_event_properties(events, model_type)
        return json.dumps(events, ensure_ascii=True, indent=True, sort_keys=True)
示例#12
0
    def categorize_offseasons(cls, year, first_events):
        """
        Takes a list of sync-enabled offseasons from FIRST and sorts them
        Returns a tuple of events (linked to TBA, candidates to link, new)
        """
        year_events_future = EventListQuery(year).fetch_async()
        year_events = year_events_future.get_result()
        year_offseasons = [
            e for e in year_events if e.event_type_enum == EventType.OFFSEASON
            or e.event_type_enum == EventType.PRESEASON
        ]

        matched_events = []
        likely_matched_events = []
        new_events = []

        logging.info("Categorizing {} events from FIRST".format(
            len(first_events)))
        for event in first_events:
            matching_tba_event_by_key = next(
                (e for e in year_offseasons if cls.is_direct_match(e, event)),
                None)
            if matching_tba_event_by_key:
                matched_events.append((matching_tba_event_by_key, event))
                continue

            likely_match = next(
                (e for e in year_offseasons if cls.is_maybe_match(e, event)),
                None)
            if likely_match:
                likely_matched_events.append((likely_match, event))
                continue

            new_events.append(event)

        return (matched_events, likely_matched_events, new_events)
示例#13
0
def event_updated(affected_refs):
    event_keys = filter(None, affected_refs['key'])
    years = filter(None, affected_refs['year'])
    event_district_keys = filter(None, affected_refs['event_district_key'])

    event_team_keys_future = EventTeam.query(EventTeam.event.IN([event_key for event_key in event_keys])).fetch_async(None, keys_only=True)

    queries_and_keys = []
    for year in years:
        queries_and_keys.append((EventListQuery(year)))

    for event_district_key in event_district_keys:
        queries_and_keys.append((DistrictEventsQuery(event_district_key)))

    for et_key in event_team_keys_future.get_result():
        team_key = et_key.id().split('_')[1]
        year = int(et_key.id()[:4])
        queries_and_keys.append((TeamEventsQuery(team_key)))
        queries_and_keys.append((TeamYearEventsQuery(team_key, year)))

    return queries_and_keys