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 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)
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)