podlaczenie do servera

This commit is contained in:
unknown 2024-01-07 17:35:33 +01:00
parent 7f68677a3b
commit edde8cf6be
2 changed files with 77 additions and 78 deletions

View File

@ -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 = []
@ -250,15 +262,10 @@ const Hero = () => {
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 */}
<div className="top-bar">
{/* new version */}
<div className="dropdown">
<button onClick={() => setIsOpen(!isOpen)} className="dropbtn">
Część ciała
</button>
{isOpen && (
<div className="cho-dropdown_body_part">
<a a href="#">Noga Prawa</a>
<a a href="#">Noga Lewa</a>
<a a href="#">Głowa</a>
<a a href="#">Inna</a>
</div>
)}
</div>
<form className="dropdown" id = "bodyPartList">
<select className="dropbtn">
<option value = "prawa">Noga Prawa</option>
<option value = "lewa">Noga Lewa</option>
<option value = "glowa">Głowa</option>
<option value = "inna" >Inna</option>
</select>
</form>
<div className="dropdown">
<button onClick={toggleDropdown} className="dropbtn">Technika strzału</button>
{isOpen && (
<div className="cho-dropdown_technique_name">
<a href="#"> Zwykły </a>
<a href="#"> Wolej </a>
<a href="#"> Półwolej </a>
<a href="#"> Lob </a>
<a href="#"> Szczupak </a>
<a href="#"> Kopnięcie z góry </a>
<a href="#"> Piętka </a>
</div>
)}
</div>
<form className="dropdown" id = "shootTypeList">
<select className="dropbtn">
<option value="zwykly"> Zwykły </option>
<option value = "voley"> Wolej </option>
<option value = "pol-voley"> Półwolej </option>
<option value = "lob"> Lob </option>
<option value = "szczupak"> Szczupak </option>
<option value = "z_gory"> Kopnięcie z góry </option>
<option value = "pietka"> Piętka </option>
</select>
</form>
<div className="dropdown">
<button onClick={toggleDropdown} className="dropbtn">Typ akcji</button>
{isOpen && (
<div className="cho-dropdown_type_name">
<a href="#"> Atak Pozycyjny </a>
<a href="#"> Rzut Wolny </a>
<a href="#"> Rzut Karny </a>
<a href="#"> Rzut Rozny </a>
<a href="#"> Rozpoczęcie </a>
</div>
)}
</div>
<form className="dropdown" id = "actionTypeList">
<select className="dropbtn">
<option value = "pozycyjny"> Atak Pozycyjny </option>
<option value = "wolny"> Rzut Wolny </option>
<option value = "karny"> Rzut Karny </option>
<option value= "rozny"> Rzut Rozny </option>
<option value="rozpoczecie"> Rozpoczęcie </option>
</select>
</form>
<div className="dropdown">
<button onClick={toggleDropdown} className="dropbtn">Pozycja strzelającego</button>
{isOpen && (
<div className="cho-dropdown_position_name">
<a href="#"> Bramkarz </a>
<a href="#"> Obrońca </a>
<a href="#"> Pomocnik </a>
<a href="#"> Napastnik </a>
</div>
)}
</div>
<form className="dropdown" id = "possitionList">
<select className="dropbtn">
<option value= "napastnik" > Napastnik </option>
<option value = "bramkarz"> Bramkarz </option>
<option value = "obronca"> Obrońca </option>
<option value = "pomocnik"> Pomocnik </option>
</select>
</form>
<div className="cho-minute">
<label htmlFor="gameMinute" className="label-large"></label>

View File

@ -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<x>&<y>")
@ -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 = x, y = y)
dist = loc2distance(x = x, y = y)
angle = loc2angle(x = shooter[0], y = shooter[1])
dist = loc2distance(x = shooter[0], y = shooter[1])
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)