integracja na labach

This commit is contained in:
Szymon Obst 2023-12-12 18:42:33 +01:00
parent 9e2beafb90
commit c099e92132
6 changed files with 36 additions and 20 deletions

8
app/package-lock.json generated
View File

@ -33,7 +33,7 @@
"post": "^0.0.1", "post": "^0.0.1",
"postcss": "^8.4.32", "postcss": "^8.4.32",
"tailwindcss": "^3.3.5", "tailwindcss": "^3.3.5",
"vite": "^5.0.0" "vite": "^5.0.8"
} }
}, },
"node_modules/@aashutoshrathi/word-wrap": { "node_modules/@aashutoshrathi/word-wrap": {
@ -5290,9 +5290,9 @@
} }
}, },
"node_modules/vite": { "node_modules/vite": {
"version": "5.0.5", "version": "5.0.8",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.0.5.tgz", "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.8.tgz",
"integrity": "sha512-OekeWqR9Ls56f3zd4CaxzbbS11gqYkEiBtnWFFgYR2WV8oPJRRKq0mpskYy/XaoCL3L7VINDhqqOMNDiYdGvGg==", "integrity": "sha512-jYMALd8aeqR3yS9xlHd0OzQJndS9fH5ylVgWdB+pxTwxLKdO1pgC5Dlb398BUxpfaBxa4M9oT7j1g503Gaj5IQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"esbuild": "^0.19.3", "esbuild": "^0.19.3",

View File

@ -36,6 +36,6 @@
"post": "^0.0.1", "post": "^0.0.1",
"postcss": "^8.4.32", "postcss": "^8.4.32",
"tailwindcss": "^3.3.5", "tailwindcss": "^3.3.5",
"vite": "^5.0.0" "vite": "^5.0.8"
} }
} }

View File

@ -6,10 +6,8 @@ import { navLinks } from "../constants";
import { logo, menu, close } from "../assets"; import { logo, menu, close } from "../assets";
const Hero = () => { const Hero = () => {
const [data,setData] = useState([{}]) const [data,setData] = useState([{}])
// Reset Boiska // Reset Boiska
function resetField() { function resetField() {
var footballField = document.getElementById('footballField'); var footballField = document.getElementById('footballField');
@ -21,30 +19,25 @@ const Hero = () => {
} }
// Wysłanie zapytania do serwera // Wysłanie zapytania do serwera
function sentQuestion() { function sentQuestion() {
var ball = document.querySelector('.football'); var ball = document.querySelector('.football');
if (ball) { if (ball) {
var x = ball.style.left; var x = ball.style.left;
var y = ball.style.top; var y = ball.style.top;
var query = "http://localhost:5000/LRegresion" + x + "&" + y
var query = "/LRegresion" + x + "&" + y fetch(query).then(
alert(query)
fetch("/LRegresion").then(
res => res.json res => res.json
).then( ).then(
data => { data => {
setData(data) setData(data)
console.log(data)`` console.log(data)
} }
) )
} else { } else {
alert('Piłka nie jest obecnie na boisku.'); alert('Piłka nie jest obecnie na boisku.');
} }
} }
/* Funkcja dodająca listener do boiska*/ /* Funkcja dodająca listener do boiska*/
function boiskoListener(){ function boiskoListener(){
var x = event.clientX - footballField.getBoundingClientRect().left; var x = event.clientX - footballField.getBoundingClientRect().left;
var y = event.clientY - footballField.getBoundingClientRect().top; var y = event.clientY - footballField.getBoundingClientRect().top;
@ -63,7 +56,7 @@ const Hero = () => {
useEffect(()=>{ useEffect(()=>{
var footballField = document.getElementById('footballField'); var footballField = document.getElementById('footballField');
footballField.addEventListener('click', boiskoListener) footballField.addEventListener('click', boiskoListener)
},[]); });
/*zwracany komponent zawierajacy boisko*/ /*zwracany komponent zawierajacy boisko*/

View File

@ -0,0 +1,13 @@
from joblib import load
import pandas as pd
# Funkcja zwraca prawdopodobieństwo zdobycia gola
def LogisticRegression_predict_proba(position_x, position_y, distance_to_goalM, angle, match_minute, Number_Intervening_Opponents, Number_Intervening_Teammates, isFoot, isHead):
model = load('regresja_logistyczna.joblib')
X_new = pd.DataFrame(columns=['position_x', 'position_y', 'distance_to_goalM', 'angle','match_minute', 'Number_Intervening_Opponents','Number_Intervening_Teammates', 'isFoot', 'isHead'])
X_new.loc[len(X_new.index)] = [position_x, position_y, distance_to_goalM, angle, match_minute, Number_Intervening_Opponents, Number_Intervening_Teammates, isFoot, isHead]
return model.predict_proba(X_new)[0][1].round(2)
#kolejne modele

View File

@ -1,5 +1,7 @@
from flask import Flask from flask import Flask
from flask_cors import CORS from flask_cors import CORS
from modele.modele import LogisticRegression_predict_proba
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
@ -9,10 +11,18 @@ CORS(app)
def members(): def members():
return{"members":["Member1","Member2","Member3"]} return{"members":["Member1","Member2","Member3"]}
# zapytanie o regresje logistyczną na podstawie pozycji piłki
@app.route("/LRegresion<x>&<y>") @app.route("/LRegresion<x>&<y>")
def LRegresion(x,y): def LRegresion(x,y):
num = x+y
return str(num) x = int(x[0:2])
y = int(y[0:2])
response = LogisticRegression_predict_proba(9.23, -2.24, 9.5, 13.67, 13, 3, 0, 1, 0)
return {"response":[str(response),"proces"]}
# uruchomienie serwera
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug = True) app.run(debug = True)