Esempio n. 1
0
    def submit_team_form_valid(self, form):
        if self.request.is_ajax():
            engine = self.get_engine()
            blue_team = form.cleaned_data['blue_team'].name
            red_team = form.cleaned_data['red_team'].name
            team_predictor_values = form.cleaned_data['team_predictor_values']
            team_game_range = form.cleaned_data['team_game_range']
            print('predictor value {}'.format(team_predictor_values))
            predict = PredictTeamWin(engine, predictor_stats=team_predictor_values,
                                     game_range=team_game_range)
            predict_single_game = predict.predict_on_single_game(blue_team, red_team)

            topTen = TopTenTeamService(engine)

            if predict.is_loaded:
                top_teams = topTen.top_ten_teams()

            #just to test it
            #top_teams = topTen.top_ten_teams()
            #TopTenTeamsView().top_ten_view()

            morris_chart_data = []
            print('making morris chart')
            for k, v in predict_single_game.items():
                single_chart_point = {'label': k, 'value': v}
                morris_chart_data.append(single_chart_point)
            response_object = {'data': morris_chart_data}
            return JsonResponse(response_object)
        else:
            return HttpResponseRedirect(self.get_success_url())
Esempio n. 2
0
    def submit_team_form_valid(self, form):
        if self.request.is_ajax():
            engine = self.get_engine()
            blue_team = form.cleaned_data['blue_team'].name
            red_team = form.cleaned_data['red_team'].name
            team_predictor_values = form.cleaned_data['team_predictor_values']
            team_game_range = form.cleaned_data['team_game_range']
            print('predictor value {}'.format(team_predictor_values))
            predict = PredictTeamWin(engine,
                                     predictor_stats=team_predictor_values,
                                     game_range=team_game_range)
            predict_single_game = predict.predict_on_single_game(
                blue_team, red_team)

            topTen = TopTenTeamService(engine)

            if predict.is_loaded:
                top_teams = topTen.top_ten_teams()

            #just to test it
            #top_teams = topTen.top_ten_teams()
            #TopTenTeamsView().top_ten_view()

            morris_chart_data = []
            print('making morris chart')
            for k, v in predict_single_game.items():
                single_chart_point = {'label': k, 'value': v}
                morris_chart_data.append(single_chart_point)
            response_object = {'data': morris_chart_data}
            return JsonResponse(response_object)
        else:
            return HttpResponseRedirect(self.get_success_url())
Esempio n. 3
0
    def top_ten_teams(self):
        all_teams_dict = Team.objects.all().values('name')
        all_teams = [x['name'] for x in all_teams_dict]
        #all_teams = Team.objects.all().values_list('name', flat = True)
        print('this is the team name {}'.format(all_teams))

        top_ten = {}
        for team in all_teams:
            top_ten[team] = 0

        engine = self.engine
        predict = PredictTeamWin(engine)

        k = 0
        for blue_team in all_teams[:-1]:
            print('{}. team : {}'.format(k, blue_team))
            k += 1
            for red_team in all_teams[all_teams.index(blue_team) + 1:]:
                predict_single_game = predict.predict_on_single_game(
                    blue_team, red_team)
                blue_prob = predict_single_game.get(blue_team)
                red_prob = predict_single_game.get(red_team)
                if blue_prob > red_prob:
                    top_ten[blue_team] += 1
                else:
                    if red_prob > blue_prob:
                        top_ten[red_team] += 1
                    else:
                        top_ten[red_team] += +0.5
                        top_ten[blue_team] += 0.5
                # 2nd round: change the sides
                #
                predict_single_game = predict.predict_on_single_game(
                    red_team, blue_team)
                blue_prob = predict_single_game.get(blue_team)
                red_prob = predict_single_game.get(red_team)
                if blue_prob > red_prob:
                    top_ten[blue_team] += 1
                else:
                    if red_prob > blue_prob:
                        top_ten[red_team] += 1
                    else:
                        top_ten[red_team] += 0.5
                        top_ten[blue_team] += 0.5

        sorted_teams_and_wins = sorted(top_ten.items(),
                                       key=operator.itemgetter(1),
                                       reverse=True)  #tuples
        #print("top ten sorted : --- {}".format(sorted_teams_and_wins))
        a = range(1, len(sorted_teams_and_wins) + 1)
        tt = zip(sorted_teams_and_wins, a)

        #delete all records 1st:
        TopTenTeam.objects.all().delete()

        for item, r in tt:
            t10 = TopTenTeam.objects.create(name=item[0],
                                            score=item[1],
                                            rank=r)
Esempio n. 4
0
    def top_ten_teams(self):
        all_teams_dict = Team.objects.all().values('name')
        all_teams = [x['name'] for x in all_teams_dict]
        #all_teams = Team.objects.all().values_list('name', flat = True)
        print('this is the team name {}'.format(all_teams))

        top_ten = {}
        for team in all_teams:
            top_ten[team] = 0;

        engine = self.engine
        predict = PredictTeamWin(engine)

        k=0
        for blue_team in all_teams[: -1]:
            print('{}. team : {}'.format(k, blue_team))
            k += 1
            for red_team in all_teams[all_teams.index(blue_team) + 1 :]:
                predict_single_game = predict.predict_on_single_game(blue_team, red_team)
                blue_prob = predict_single_game.get(blue_team)
                red_prob = predict_single_game.get(red_team)
                if blue_prob > red_prob:
                    top_ten[blue_team] += 1
                else:
                    if red_prob > blue_prob:
                        top_ten[red_team] += 1
                    else:
                        top_ten[red_team] += + 0.5
                        top_ten[blue_team] += 0.5
                # 2nd round: change the sides
                #
                predict_single_game = predict.predict_on_single_game(red_team, blue_team)
                blue_prob = predict_single_game.get(blue_team)
                red_prob = predict_single_game.get(red_team)
                if blue_prob > red_prob:
                    top_ten[blue_team] += 1
                else:
                    if red_prob > blue_prob:
                        top_ten[red_team] += 1
                    else:
                        top_ten[red_team] += 0.5
                        top_ten[blue_team] += 0.5

        sorted_teams_and_wins = sorted(top_ten.items(),  key=operator.itemgetter(1), reverse=True) #tuples
        #print("top ten sorted : --- {}".format(sorted_teams_and_wins))
        a = range(1, len(sorted_teams_and_wins) + 1)
        tt = zip(sorted_teams_and_wins, a)

        #delete all records 1st:
        TopTenTeam.objects.all().delete()

        for item, r in tt:
            t10 = TopTenTeam.objects.create(name = item[0], score = item[1], rank = r)
Esempio n. 5
0
 def get_context_data(self, **kwargs):
     context = super(TeamPredictions, self).get_context_data()
     databases = getattr(settings, "DATABASES", None)
     database = databases['default']
     engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(database['USER'], database['PASSWORD'],
                                                                 database['HOST'], database['PORT'],
                                                                 database['NAME']), echo=False)
     predict = PredictTeamWin(engine,  'SK TELECOM T1', 'COUNTER LOGIC GAMING')
     predict_single_game = predict.predict_on_single_game()
     winning_percent = predict_single_game['SK TELECOM T1']
     context['team_name'] = 'SK TELECOM T1'
     context['winning_percent'] = winning_percent
     return context
Esempio n. 6
0
 def get_context_data(self, **kwargs):
     context = super(TeamPredictions, self).get_context_data()
     databases = getattr(settings, "DATABASES", None)
     database = databases['default']
     engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(
         database['USER'], database['PASSWORD'], database['HOST'],
         database['PORT'], database['NAME']),
                            echo=False)
     predict = PredictTeamWin(engine, 'SK TELECOM T1',
                              'COUNTER LOGIC GAMING')
     predict_single_game = predict.predict_on_single_game()
     winning_percent = predict_single_game['SK TELECOM T1']
     context['team_name'] = 'SK TELECOM T1'
     context['winning_percent'] = winning_percent
     return context