From edde8cf6be8f9db74671cf5733cd8f688639e98e Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 7 Jan 2024 17:35:33 +0100 Subject: [PATCH] podlaczenie do servera --- app/src/components/Hero.jsx | 117 ++++++++++++++++----------------- app/src/flask-server/server.py | 38 ++++++----- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/app/src/components/Hero.jsx b/app/src/components/Hero.jsx index 55709af..47fdcb1 100644 --- a/app/src/components/Hero.jsx +++ b/app/src/components/Hero.jsx @@ -38,7 +38,7 @@ const Hero = () => { var bodyPart = ""; var technique = ""; var actionType = ""; - var possition = ""; + var shooterPossition = ""; //zamiana procentowych pozycji na kartezyjskie function konwerturX(x){ @@ -115,6 +115,18 @@ const Hero = () => { function loadPlayers(){ var players = document.querySelectorAll('.player') + + //zgranie informacji z list + var bodyPartList = document.getElementById('bodyPartList') + var actionTypeList = document.getElementById('actionTypeList') + var possitionList = document.getElementById('possitionList') + var shootTypeList = document.getElementById('shootTypeList') + + bodyPart = bodyPartList.value + actionType = actionTypeList.value + shooterPossition = possitionList.value + technique = shootTypeList.value + // wyczyszczenie list zawierajacych lokalizacje zawodnikow defenders = [] stricers = [] @@ -249,16 +261,11 @@ const Hero = () => { function sentQuestion() { loadPlayers() - - var ball = document.querySelector('.football'); - - if (ball) { + + if (numer_od_shooters > 0) { // Użyj backticksów zamiast zwykłych cudzysłowów - //console.log('Wysyłanie wartości: ', ball); - shooterX = konwerturX(ball.style.left) - shooterY = konwetujY(ball.style.top) - console.log('Wysyłanie wartości: ', shooterX, shooterY); - fetch(`http://127.0.0.1:5000/get_model?x=${shooter[0]}&y=${shooter[1]}`).then( + + fetch(`http://127.0.0.1:5000/get_model?shooter=${shooter}&goalkeeper=${goalkeeper}&defenders=${defenders}&strickers=${stricers}&bodyPart=4${bodyPart}&technique=${technique}&actionType=${actionType}&shooterPossition=${shooterPossition}`).then( res => res.json() ).then( data => { @@ -357,62 +364,50 @@ const Hero = () => { {/* Listy zwijane */}
- {/* new version */} -
- - {isOpen && ( -
- Noga Prawa - Noga Lewa - Głowa - Inna -
- )} -
+ +
+ +
-
- - {isOpen && ( -
- Zwykły - Wolej - Półwolej - Lob - Szczupak - Kopnięcie z góry - Piętka -
- )} -
+
+ +
-
- - {isOpen && ( -
- Atak Pozycyjny - Rzut Wolny - Rzut Karny - Rzut Rozny - Rozpoczęcie -
- )} -
+
+ +
-
- - {isOpen && ( -
- Bramkarz - Obrońca - Pomocnik - Napastnik -
- )} -
+ +
+ +
diff --git a/app/src/flask-server/server.py b/app/src/flask-server/server.py index 0e07f2c..6df0442 100644 --- a/app/src/flask-server/server.py +++ b/app/src/flask-server/server.py @@ -20,12 +20,13 @@ def loc2distance(x, y): def loc2locdistance(x1, y1, x2, y2): return math.sqrt((x1 - x2)**2 + (y1 - y2)**2) - -# model Api -# @app.route("/members") -# def members(): -# return{"members":["Member1","Member2","Member3"]} - +#Konwertuje string zawierajacy liczby odzielone , i konwertuje do float +def konwertujDoListy(listaString): + listaString = listaString.split(",") + listaFloat = [] + for elem in listaString: + listaFloat.append(float(elem)) + return listaFloat # zapytanie o regresje logistyczną na podstawie pozycji piłki # @app.route("/LRegresion&") @@ -79,19 +80,24 @@ def get_model(): # x = int(x[0:2]) # y = int(y[0:2]) - x = request.args.get('x', type=float) - y = request.args.get('y', type=float) + shooter = request.args.get('shooter') + shooter = konwertujDoListy(shooter) + + print("wprowadzone dane:") + print("x strzelca: " + str(shooter[0])) + print("y strzelca: " + str(shooter[1])) + ## change model on xgboost ## add angle, match minutes and number of players + + angle = loc2angle(x = shooter[0], y = shooter[1]) + dist = loc2distance(x = shooter[0], y = shooter[1]) - angle = loc2angle(x = x, y = y) - dist = loc2distance(x = x, y = y) - - if y is None and x is None: + if shooter[0] is None and shooter[1] is None: return jsonify({"error": "Brak wymaganych parametrów"}), 400 - response = LogisticRegression_predict_proba(position_x=x, - position_y=y, + response = LogisticRegression_predict_proba(position_x=shooter[0], + position_y=shooter[1], distance_to_goalM = dist, angle = angle, match_minute=13, @@ -99,13 +105,11 @@ def get_model(): Number_Intervening_Teammates=0, isFoot=1, isHead=0) - #print(x) - #print(y) + #print(response) res = str(response) #return {"response":res} return jsonify({"response":res}) - # uruchomienie serwera if __name__ == "__main__": app.run(debug = True) \ No newline at end of file