diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/football-match-predictor.py b/football-match-predictor.py index 6d06880..b9d598c 100644 --- a/football-match-predictor.py +++ b/football-match-predictor.py @@ -102,8 +102,8 @@ print(data) # Pre processing -input_filter = ['home_encoded', 'away_encoded', 'HS', - 'AS', 'HST', 'AST', 'HTCT', 'ATCT', 'HR', 'AR'] +input_filter = ['home_encoded', 'away_encoded', 'HTHG', 'HTAG', 'HS', + 'AS', 'HST', 'AST', 'HR', 'AR'] output_filter = ['FTR'] cols_to_consider = input_filter + output_filter @@ -120,11 +120,12 @@ away_encoded_mapping = dict( zip(encoder.classes_, encoder.transform(encoder.classes_).tolist())) data['away_encoded'] = away_encoded -htg_df = data[['HTHG', 'HTAG']] -cs_data = derive_clean_sheet(htg_df) -cs_df = pd.DataFrame(cs_data, columns=['HTCT', 'ATCT']) +# Deriving Clean Sheet +# htg_df = data[['HTHG', 'HTAG']] +# cs_data = derive_clean_sheet(htg_df) +# cs_df = pd.DataFrame(cs_data, columns=['HTCS', 'ATCS']) -data = pd.concat([data, cs_df], axis=1) +# data = pd.concat([data, cs_df], axis=1) data = data[cols_to_consider] diff --git a/server/api/__init__.py b/server/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/api/admin.py b/server/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/server/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/server/api/apps.py b/server/api/apps.py new file mode 100644 index 0000000..d87006d --- /dev/null +++ b/server/api/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + name = 'api' diff --git a/server/api/migrations/__init__.py b/server/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/api/models.py b/server/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/server/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/server/api/tests.py b/server/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/server/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/server/api/urls.py b/server/api/urls.py new file mode 100644 index 0000000..e646cee --- /dev/null +++ b/server/api/urls.py @@ -0,0 +1,22 @@ +"""server URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include +from . import views + +urlpatterns = [ + path('predict', views.index), +] diff --git a/server/api/views.py b/server/api/views.py new file mode 100644 index 0000000..5761868 --- /dev/null +++ b/server/api/views.py @@ -0,0 +1,65 @@ +from django.shortcuts import render +from django.http import HttpResponse, HttpRequest, JsonResponse +from os import path +from joblib import dump, load +from time import time +import pandas as pd +import numpy as np +import json + +# Create your views here. +def index(request: HttpRequest): + + result = { + 'success': False, + 'data': {}, + 'msg': '', + } + + classifierModels = { + 'lr': 'lr_classifier.model', + 'nb': 'nb_classifier.model', + 'rf': 'rf_classifier.model', + } + + selectedClassifier = request.GET['classifier'] + + if selectedClassifier not in classifierModels: + return HttpResponse(json.dumps(result)) + + exportedModelFilePath = path.abspath(path.dirname( + __name__)) + '/../exportedModels/' + classifierModels[selectedClassifier] + # print(exportMetaDataFilePath) + + X = pd.DataFrame({ + 'home_encoded': request.GET['homeTeam'], + 'away_encoded': request.GET['awayTeam'], + 'HTHG': request.GET['homeGoals'], + 'HTAG': request.GET['awayGoals'], + 'HS': request.GET['homeShots'], + 'AS': request.GET['awayShots'], + 'HST': request.GET['homeShotsOnTarget'], + 'AST': request.GET['awayShotsOnTarget'], + 'HR': request.GET['homeRedCards'], + 'AR': request.GET['awayRedCards'], + }, index = [0]) + + if path.exists(exportedModelFilePath): + clf = load(exportedModelFilePath) + # print(exportMetaData) + + start = time() + pred_probs = clf.predict_proba(X)[0] + + y = dict(zip(clf.classes_, pred_probs)) + end = time() + print("Made Predictions in {:2f} seconds".format(end-start)) + + print("Result: ") + print(y) + + result['data']['homeWin'] = y['H'] + result['data']['draw'] = y['D'] + result['data']['awayWin'] = y['A'] + + return JsonResponse(result) diff --git a/server/server/settings.py b/server/server/settings.py index bea2503..df6c373 100644 --- a/server/server/settings.py +++ b/server/server/settings.py @@ -32,6 +32,7 @@ ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'web.apps.WebConfig', + 'api.apps.ApiConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/server/server/urls.py b/server/server/urls.py index eac365d..c1d0345 100644 --- a/server/server/urls.py +++ b/server/server/urls.py @@ -19,4 +19,5 @@ from django.urls import path, include urlpatterns = [ # path('admin/', admin.site.urls), path('', include('web.urls')), + path('api/', include('api.urls')), ] diff --git a/server/web/static/web/flat-card-image.jpg b/server/web/static/web/flat-card-image.jpg new file mode 100644 index 0000000..c6be69e Binary files /dev/null and b/server/web/static/web/flat-card-image.jpg differ diff --git a/server/web/static/web/index.css b/server/web/static/web/index.css index 1ac2942..ff6b99b 100644 --- a/server/web/static/web/index.css +++ b/server/web/static/web/index.css @@ -44,4 +44,18 @@ form.predictionForm table tr { .btn:hover { background-color: #333; +} + +.prob-container { + height: 100%; +} + +.prob-container .prob-title { + color: white; + line-height: 36px; +} + +.prob-container .prob-value { + color: white; + font-size: 24px; } \ No newline at end of file diff --git a/server/web/templates/web/index.html b/server/web/templates/web/index.html index 5d5f5b8..7c1a103 100644 --- a/server/web/templates/web/index.html +++ b/server/web/templates/web/index.html @@ -32,12 +32,18 @@
+
+ + Select Half-Time Stats +
+ + + + + + + + + + + + + + +
- {% for team, index in home_teams.items %} @@ -48,7 +54,7 @@
- {% for team, index in away_teams.items %} @@ -58,14 +64,113 @@
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+

+ +
+
+
+ +
+ Home Win +
+ 33.3% +
+
+ Draw +
+ 33.3% +
+
+ Away Win +
+ 33.3% +
+
+ +
+
@@ -75,7 +180,7 @@ style="text-decoration: underline;" href="https://github.com/AzeeSoft/football-match-predictor" target="blank" - > + > View Source on GitHub diff --git a/server/web/views.py b/server/web/views.py index e25dfdc..ebc61b1 100644 --- a/server/web/views.py +++ b/server/web/views.py @@ -8,7 +8,7 @@ import json def index(request): exportMetaDataFilePath = path.abspath(path.dirname(__name__)) + '/../exportedModels/metaData.json' - print(exportMetaDataFilePath) + # print(exportMetaDataFilePath) exportMetaData = { 'home_teams': {}, @@ -17,7 +17,7 @@ def index(request): if path.exists(exportMetaDataFilePath): exportMetaDataFile = open(exportMetaDataFilePath, 'r') exportMetaData = json.load(exportMetaDataFile) - print(exportMetaData) + # print(exportMetaData) template = loader.get_template('web/index.html') context = {