Dodanie wszystkich zmiennych z modelu do apki oraz ich obsługa

This commit is contained in:
LukaszChrostowski 2024-01-11 20:10:52 +01:00
parent f93d8c5c67
commit 412dd57577
3 changed files with 66 additions and 23 deletions

View File

@ -8,9 +8,41 @@ const Hero = () => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [gameMinute, setGameMinute] = useState(''); const [gameMinute, setGameMinute] = useState('');
const [firstShot, setfirstShot] = useState('');
const [oneOnOne, SetoneOnOne] = useState('');
const [afterAirDuel, SetafterAirDuele] = useState('');
const [openGoal, SetOpenGoal] = useState('');
const [afterDribbling, SetafterDribbling] = useState('');
const [redirect, SetRedirect] = useState('');
const toggleDropdown = () => setIsOpen(!isOpen); const toggleDropdown = () => setIsOpen(!isOpen);
const handleMinuteChange = (e) => setGameMinute(e.target.value); const handleMinuteChange = (e) => setGameMinute(e.target.value);
const handleFirstShotChange = (event) => {
setfirstShot(event.target.checked);
};
const handleOneOnOneChange = (event) => {
SetoneOnOne(event.target.checked);
};
const handleAfterAirDuelChange = (event) => {
SetafterAirDuele(event.target.checked);
};
const handleOpenGoalChange = (event) => {
SetOpenGoal(event.target.checked);
};
const handleAfterDribblingChange = (event) => {
SetafterDribbling(event.target.checked);
};
const handleRedirectChange = (event) => {
SetRedirect(event.target.checked);
};
const [data, setData] = useState(""); const [data, setData] = useState("");
//zmienne globalne //zmienne globalne
//zmienna mówiąca który przycisk jest aktywny, jest ona wykorzystywana //zmienna mówiąca który przycisk jest aktywny, jest ona wykorzystywana
@ -73,6 +105,7 @@ const Hero = () => {
setNumberOfStrikers(0) setNumberOfStrikers(0)
setNumberOfGoalkeppers(0) setNumberOfGoalkeppers(0)
setNumberOfShooters(0) setNumberOfShooters(0)
setGameMinute('')
} }
@ -242,9 +275,9 @@ const Hero = () => {
///Dziwny Blad ///Dziwny Blad
loadPlayers() loadPlayers()
if (number_of_shooters == 1) { if (number_of_shooters == 1) {
console.log('Wysyłanie wartości: ', bodyPart, technique); console.log('Wysyłanie wartości: ', bodyPart, technique, actionType, shooterPossition, gameMinute, firstShot);
// Użyj backticksów zamiast zwykłych cudzysłowów // Użyj backticksów zamiast zwykłych cudzysłowów
fetch(`http://127.0.0.1:5000/get_model?shooter=${shooter}&goalkeeper=${goalkeeper}&defenders=${defenders}&strickers=${stricers}&bodyPart=${bodyPart}&technique=${technique}&actionType=${actionType}&shooterPossition=${shooterPossition}`).then( fetch(`http://127.0.0.1:5000/get_model?shooter=${shooter}&goalkeeper=${goalkeeper}&defenders=${defenders}&strickers=${stricers}&bodyPart=${bodyPart}&technique=${technique}&actionType=${actionType}&shooterPossition=${shooterPossition}&gameMinute=${gameMinute}&shot_first_time=${firstShot}&shot_one_on_one=${oneOnOne}&shot_aerial_won=${afterAirDuel}&shot_open_goal=${openGoal}&shot_follows_dribble=${afterDribbling}&shot_redirect=${redirect}`).then(
res => res.json() res => res.json()
).then( ).then(
data => { data => {
@ -265,8 +298,6 @@ const Hero = () => {
/* Funkcja dodająca listener do boiska*/ /* Funkcja dodająca listener do boiska*/
function boiskoListener(ev){ function boiskoListener(ev){
ev.preventDefault() ev.preventDefault()
@ -440,34 +471,32 @@ const Hero = () => {
<div className="additional-parameters"> <div className="additional-parameters">
<h3>Parametry strzału</h3> <h3>Parametry strzału</h3>
<label> <label>
<input type="checkbox" id="firstShot" /> <input type="checkbox" id="firstShot" onChange={handleFirstShotChange} />
Pierwszy w meczu Pierwszy w meczu
</label> </label>
<label> <label>
<input type="checkbox" id="oneOnOne" /> <input type="checkbox" id="oneOnOne" onChange={handleOneOnOneChange} />
Akcja sam na sam Akcja sam na sam
</label> </label>
<label> <label>
<input type="checkbox" id="afterAirDuel" /> <input type="checkbox" id="afterAirDuel" onChange={handleAfterAirDuelChange} />
Po pojedynku powietrznym Po pojedynku powietrznym
</label> </label>
<label> <label>
<input type="checkbox" id="openGoal" /> <input type="checkbox" id="openGoal" onChange={handleOpenGoalChange} />
Na pustą bramkę Na pustą bramkę
</label> </label>
<label> <label>
<input type="checkbox" id="afterDribbling" /> <input type="checkbox" id="afterDribbling" onChange={handleAfterDribblingChange} />
Poprzedzony dryblingiem Poprzedzony dryblingiem
</label> </label>
<label> <label>
<input type="checkbox" id="ricochet" /> <input type="checkbox" id="redirect" onChange={handleRedirectChange} />
Rykoszet Rykoszet
</label> </label>
</div> </div>
{/* <div className="ChoosingPlayer"> {/* <div className="ChoosingPlayer">
<button className="cho-one_on_one" id = "bbt8">Sam na sam</button> <button className="cho-one_on_one" id = "bbt8">Sam na sam</button>
</div> </div>

View File

@ -31,6 +31,15 @@ def get_model():
acionType = request.args.get('actionType') acionType = request.args.get('actionType')
minute = request.args.get('gameMinute') minute = request.args.get('gameMinute')
position_name = request.args.get('shooterPossition') position_name = request.args.get('shooterPossition')
gameMinute = request.args.get('gameMinute')
shot_first_time = request.args.get('shot_first_time')
shot_one_on_one = request.args.get('shot_one_one')
shot_aerial_won = request.args.get('shot_aerial_won')
shot_open_goal = request.args.get('shot_open_goal')
shot_follows_dribble = request.args.get('shot_follows_dribble')
shot_redirect = request.args.get('shot_redirect')
shooter_x, shooter_y = shooter.split(',') shooter_x, shooter_y = shooter.split(',')
@ -81,6 +90,9 @@ def get_model():
atakujacy_lista = konwertujDoListy(atakujacy) atakujacy_lista = konwertujDoListy(atakujacy)
atakujacy_macierz = zmienWMaciez(atakujacy_lista) atakujacy_macierz = zmienWMaciez(atakujacy_lista)
if gameMinute == "":
gameMinute = 1 # to change
print("wspolrzedne obroncow: ", obroncy) print("wspolrzedne obroncow: ", obroncy)
print("wspolrzedne atakujacych: ", atakujacy) print("wspolrzedne atakujacych: ", atakujacy)
@ -114,6 +126,8 @@ def get_model():
print("Posortowani obroncy: ", posortowani_obroncy) print("Posortowani obroncy: ", posortowani_obroncy)
print("Posortowani atakujacy: ", posortowani_atakujacy) print("Posortowani atakujacy: ", posortowani_atakujacy)
number_of_players_opponents = np.sum(~np.isnan(posortowani_obroncy).all(axis=1))
number_of_players_teammates = np.sum(~np.isnan(posortowani_atakujacy).all(axis=1))
## add angle, match minutes and number of players ## add angle, match minutes and number of players
@ -142,22 +156,22 @@ def get_model():
print("bramkarz:", goalkepper_x, goalkepper_y) print("bramkarz:", goalkepper_x, goalkepper_y)
# MODEL XGBOOST # MODEL XGBOOST
response = xgboost_predict_proba(minute=1, response = xgboost_predict_proba(minute=gameMinute,
position_name=position_name, position_name=position_name,
shot_body_part_name=body_part, shot_body_part_name=body_part,
shot_technique_name=technique, shot_technique_name=technique,
shot_type_name=acionType, shot_type_name=acionType,
shot_first_time=False, shot_first_time=shot_first_time,
shot_one_on_one=False, shot_one_on_one=shot_one_on_one,
shot_aerial_won=False, shot_aerial_won=shot_aerial_won,
shot_deflected=False, shot_deflected=False,
shot_open_goal=False, shot_open_goal=shot_open_goal,
shot_follows_dribble=False, shot_follows_dribble=shot_follows_dribble,
shot_redirect=False, shot_redirect=shot_redirect,
shot_kick_off=False, shot_kick_off=False,
x1=shooter_x, y1=shooter_y, x1=shooter_x, y1=shooter_y,
number_of_players_opponents=0, number_of_players_opponents=number_of_players_opponents,
number_of_players_teammates=0, number_of_players_teammates=number_of_players_teammates,
angle=angle, distance=dist, angle=angle, distance=dist,
x_player_opponent_Goalkeeper=goalkepper_x, y_player_opponent_Goalkeeper=goalkepper_y, x_player_opponent_Goalkeeper=goalkepper_x, y_player_opponent_Goalkeeper=goalkepper_y,
x_player_opponent_1=posortowani_obroncy[0][0], y_player_opponent_1=posortowani_obroncy[0][1], x_player_opponent_1=posortowani_obroncy[0][0], y_player_opponent_1=posortowani_obroncy[0][1],