예제 #1
0
    def get(self, event_key):
        event = Event.get_by_id(event_key)
        matchstats_dict = MatchstatsHelper.calculate_matchstats(event.matches, event.year)

        if event.year == 2016:
            organized_matches = MatchHelper.organizeMatches(event.matches)
            match_predictions, match_prediction_stats = PredictionHelper.get_match_predictions(organized_matches['qm'])
            ranking_predictions, ranking_prediction_stats = PredictionHelper.get_ranking_predictions(organized_matches['qm'], match_predictions)

            matchstats_dict['match_predictions'] = match_predictions
            matchstats_dict['match_prediction_stats'] = match_prediction_stats
            matchstats_dict['ranking_predictions'] = ranking_predictions
            matchstats_dict['ranking_prediction_stats'] = ranking_prediction_stats

        if any([v != {} for v in matchstats_dict.values()]):
            event.matchstats_json = json.dumps(matchstats_dict)
            EventManipulator.createOrUpdate(event)
        else:
            logging.warn("Matchstat calculation for {} failed!".format(event_key))

        template_values = {
            'matchstats_dict': matchstats_dict,
        }

        path = os.path.join(os.path.dirname(__file__), '../templates/math/event_matchstats_do.html')
        self.response.out.write(template.render(path, template_values))
예제 #2
0
    def get(self, event_key):
        event = Event.get_by_id(event_key)
        matchstats_dict = MatchstatsHelper.calculate_matchstats(
            event.matches, event.year)

        if event.year == 2016:
            organized_matches = MatchHelper.organizeMatches(event.matches)
            match_predictions, match_prediction_stats = PredictionHelper.get_match_predictions(
                organized_matches['qm'])
            ranking_predictions, ranking_prediction_stats = PredictionHelper.get_ranking_predictions(
                organized_matches['qm'], match_predictions)

            matchstats_dict['match_predictions'] = match_predictions
            matchstats_dict['match_prediction_stats'] = match_prediction_stats
            matchstats_dict['ranking_predictions'] = ranking_predictions
            matchstats_dict[
                'ranking_prediction_stats'] = ranking_prediction_stats

        if any([v != {} for v in matchstats_dict.values()]):
            event.matchstats_json = json.dumps(matchstats_dict)
            EventManipulator.createOrUpdate(event)
        else:
            logging.warn(
                "Matchstat calculation for {} failed!".format(event_key))

        template_values = {
            'matchstats_dict': matchstats_dict,
        }

        path = os.path.join(os.path.dirname(__file__),
                            '../templates/math/event_matchstats_do.html')
        self.response.out.write(template.render(path, template_values))
예제 #3
0
    def get(self, event_key):
        event = Event.get_by_id(event_key)
        matchstats_dict = MatchstatsHelper.calculate_matchstats(
            event.matches, event.year)
        if any([v != {} for v in matchstats_dict.values()]):
            pass
        else:
            logging.warn(
                "Matchstat calculation for {} failed!".format(event_key))
            matchstats_dict = None

        predictions_dict = None
        if event.year in {
                2016, 2017, 2018, 2019, 2020
        } and event.event_type_enum in EventType.SEASON_EVENT_TYPES or event.enable_predictions:
            sorted_matches = MatchHelper.play_order_sort_matches(event.matches)
            match_predictions, match_prediction_stats, stat_mean_vars = PredictionHelper.get_match_predictions(
                sorted_matches)
            ranking_predictions, ranking_prediction_stats = PredictionHelper.get_ranking_predictions(
                sorted_matches, match_predictions)

            predictions_dict = {
                'match_predictions': match_predictions,
                'match_prediction_stats': match_prediction_stats,
                'stat_mean_vars': stat_mean_vars,
                'ranking_predictions': ranking_predictions,
                'ranking_prediction_stats': ranking_prediction_stats
            }

        event_insights = EventInsightsHelper.calculate_event_insights(
            event.matches, event.year)

        event_details = EventDetails(
            id=event_key,
            matchstats=matchstats_dict,
            predictions=predictions_dict,
            insights=event_insights,
        )
        EventDetailsManipulator.createOrUpdate(event_details)

        template_values = {
            'matchstats_dict': matchstats_dict,
        }

        if 'X-Appengine-Taskname' not in self.request.headers:  # Only write out if not in taskqueue
            path = os.path.join(os.path.dirname(__file__),
                                '../templates/math/event_matchstats_do.html')
            self.response.out.write(template.render(path, template_values))
예제 #4
0
    def get(self, event_key):
        event = Event.get_by_id(event_key)
        matchstats_dict = MatchstatsHelper.calculate_matchstats(event.matches, event.year)
        if any([v != {} for v in matchstats_dict.values()]):
            pass
        else:
            logging.warn("Matchstat calculation for {} failed!".format(event_key))
            matchstats_dict = None

        predictions_dict = None
        if event.year in {2016, 2017, 2018} and event.event_type_enum in EventType.SEASON_EVENT_TYPES or event.enable_predictions:
            sorted_matches = MatchHelper.play_order_sort_matches(event.matches)
            match_predictions, match_prediction_stats, stat_mean_vars = PredictionHelper.get_match_predictions(sorted_matches)
            ranking_predictions, ranking_prediction_stats = PredictionHelper.get_ranking_predictions(sorted_matches, match_predictions)

            predictions_dict = {
                'match_predictions': match_predictions,
                'match_prediction_stats': match_prediction_stats,
                'stat_mean_vars': stat_mean_vars,
                'ranking_predictions': ranking_predictions,
                'ranking_prediction_stats': ranking_prediction_stats
            }

        event_insights = EventInsightsHelper.calculate_event_insights(event.matches, event.year)

        event_details = EventDetails(
            id=event_key,
            matchstats=matchstats_dict,
            predictions=predictions_dict,
            insights=event_insights,
        )
        EventDetailsManipulator.createOrUpdate(event_details)

        template_values = {
            'matchstats_dict': matchstats_dict,
        }

        if 'X-Appengine-Taskname' not in self.request.headers:  # Only write out if not in taskqueue
            path = os.path.join(os.path.dirname(__file__), '../templates/math/event_matchstats_do.html')
            self.response.out.write(template.render(path, template_values))
    def compute_f1_score(self, dataset):
        if dataset == 'train':
            x = self.data.x_train
            y_true = np.argmax(self.data.y_train, axis=1)
        elif dataset == 'cv':
            x = self.data.x_val
            y_true = np.argmax(self.data.y_val, axis=1)
        elif dataset == 'test':
            x = self.data.x_test
            y_true = np.argmax(self.data.y_test, axis=1)

        x_batch = dps.preprocess_imagebatch(self.data.x_train[0:500], [100, 100])
        output = self.forward_propogate(x_batch)
        y_preds = PredictionHelper.predict(output)

        f1score = f1_score(y_true[0:500], y_preds, average='weighted')

        return f1score