This commit is contained in:
= 2020-05-25 16:18:10 +02:00
parent ad89f08846
commit 25ad949b3a
3 changed files with 132 additions and 199 deletions

View File

@ -1,98 +1,64 @@
FUNCTION_BLOCK prediction
VAR_INPUT
goalkeeperForm: REAL;
formationAgainstForm: REAL;
shootsOnTargetAverage: REAL;
possessionAverage: REAL;
goalsAverage: REAL;
goalsLostAverage: REAL;
redCardsAverage: REAL;
penaltyAreaEntriesAverage: REAL;
penaltiesAverage: REAL;
lastMatchesResultAverage: REAL;
lastMatchesResultBetweenAverage: REAL;
team1Form: REAL;
team1GoalsAverage: REAL;
team1GoalsLostAverage: REAL;
team2Form: REAL;
team2GoalsAverage: REAL;
team2GoalsLostAverage: REAL;
END_VAR
VAR_OUTPUT
prediction : REAL;
END_VAR
FUZZIFY goalkeeperForm
TERM zla := (0, 1)(50, 1) (70, 0);
TERM dobra := (70, 0) (80,1) (90,0);
TERM znakomita := (90, 0) (100, 1);
FUZZIFY team1Form
TERM bardzo_slaba := (0, 1) (25, 0);
TERM slaba := (20, 0) (35,1) (50,0);
TERM srednia := (45, 0) (55, 1) (65, 0);
TERM dobra := (60, 0) (75, 1) (90, 1);
TERM bardzo_dobra := (85, 0) (90, 1) (100, 1);
END_FUZZIFY
FUZZIFY formationAgainstForm
TERM zla := (0, 0)(30, 1) (40, 0);
TERM przecietna := (35, 0) (50,1) (70,0);
TERM dobra := (70, 0) (100, 1);
FUZZIFY team2Form
TERM bardzo_slaba := (0, 1) (25, 0);
TERM slaba := (20, 0) (35,1) (50,0);
TERM srednia := (45, 0) (55, 1) (65, 0);
TERM dobra := (60, 0) (75, 1) (90, 1);
TERM bardzo_dobra := (85, 0) (90, 1) (100, 1);
END_FUZZIFY
FUZZIFY shootsOnTargetAverage
TERM malo := (0, 1)(2, 1) (4, 0);
TERM przecietnie := (3, 0) (5,1) (7,0);
TERM duzo := (7, 0) (10, 1)(30, 1);
END_FUZZIFY
FUZZIFY possessionAverage
TERM malo := (30, 1) (40, 0);
TERM przecietnie := (40, 0) (50,1) (60,0);
TERM duzo := (60, 0) (100, 1);
END_FUZZIFY
FUZZIFY goalsAverage
FUZZIFY team1GoalsAverage
TERM malo := (0, 1) (1, 0);
TERM przecietnie := (1, 0) (1.5,1) (2,0);
TERM srednio := (1, 0) (1.5,1) (2,0);
TERM duzo := (2, 0) (3, 1) (10, 1);
END_FUZZIFY
FUZZIFY goalsLostAverage
FUZZIFY team2GoalsAverage
TERM malo := (0, 1) (1, 0);
TERM przecietnie := (1, 0) (1.5,1) (2,0);
TERM srednio := (1, 0) (1.5,1) (2,0);
TERM duzo := (2, 0) (3, 1) (10, 1);
END_FUZZIFY
FUZZIFY redCardsAverage
TERM malo := (0, 1) (0.1, 0);
TERM przecietnie := (0.1, 0) (0.2,1) (0.3,0);
TERM duzo := (0.3, 0) (0.4, 1)(1, 1);
FUZZIFY team1GoalsLostAverage
TERM malo := (0, 1) (1, 0);
TERM srednio := (1, 0) (1.5,1) (2,0);
TERM duzo := (2, 0) (3, 1) (10, 1);
END_FUZZIFY
FUZZIFY penaltyAreaEntriesAverage
TERM rzadko := (0, 1) (5, 0);
TERM przecietnie := (5, 0) (9,1) (13,0);
TERM czesto := (13, 0) (20, 1);
FUZZIFY team2GoalsLostAverage
TERM malo := (0, 1) (1, 0);
TERM srednio := (1, 0) (1.5,1) (2,0);
TERM duzo := (2, 0) (3, 1) (10, 1);
END_FUZZIFY
FUZZIFY penaltiesAverage
TERM malo := (0, 1) (0.1, 0);
TERM przecietnie := (0.1, 0) (0.2,1) (0.3,0);
TERM duzo := (0.3, 0) (0.4, 1) (1 , 1) (5, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultAverage
TERM bardzo_slabo := (0, 1) (3, 0);
TERM slabo := (3, 1) (4, 0);
TERM przecietnie := (4, 0) (5,1) (6,1);
TERM dobrze := (6, 0) (8, 1);
TERM bardzo_dobrze := (8, 0) (9, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultBetweenAverage
TERM bardzo_slabo := (0, 1) (3, 0);
TERM slabo := (3, 1) (4, 0);
TERM przecietnie := (4, 0) (5,1) (6,1);
TERM dobrze := (6, 0) (8, 1);
TERM bardzo_dobrze := (8, 0) (9, 1);
END_FUZZIFY
DEFUZZIFY prediction
TERM przegrana := (-1,1) (0,0);
TERM remis := (-0.2,0) (0,1) (0.2,0);
TERM wygrana := (0,0) (1,1);
DEFAULT := 10;
TERM team1 := (-100,1) (-70, 1) (0,0);
TERM remis := (-20,0) (0,1) (20,0);
TERM team2 := (0,0) (70, 1) (100,1);
DEFAULT := 0;
END_DEFUZZIFY
RULEBLOCK No1
@ -100,54 +66,60 @@ RULEBLOCK No1
ACT : MIN;
ACCU : MAX;
RULE 1: IF team1Form IS bardzo_slaba AND team2Form is bardzo_slaba THEN prediction is team1;
RULE 2: IF team1Form IS slaba AND team2Form is bardzo_slaba THEN prediction is team1;
RULE 3: IF team1Form IS srednia AND team2Form is bardzo_slaba THEN prediction is team1;
RULE 4: IF team1Form IS dobra AND team2Form is bardzo_slaba THEN prediction is team1;
RULE 5: IF team1Form IS bardzo_dobra AND team2Form is bardzo_slaba THEN prediction is team1;
RULE 1: IF shootsOnTargetAverage IS duzo THEN prediction IS wygrana;
RULE 1: IF shootsOnTargetAverage IS przecietnie THEN prediction IS remis;
RULE 2: IF shootsOnTargetAverage IS malo THEN prediction IS przegrana;
/*
RULE 1: IF possessionAverage IS duzo AND shootsOnTargetAverage IS duzo THEN prediction IS wygrana;
RULE 2: IF lastMatchesResultBetweenAverage IS slabo OR lastMatchesResultBetweenAverage IS przecietnie OR lastMatchesResultBetweenAverage IS dobrze THEN prediction IS remis;
RULE 3: IF goalkeeperForm IS zla AND possessionAverage IS malo THEN prediction IS przegrana;
RULE 4: IF goalkeeperForm IS dobra AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 5: IF formationAgainstForm IS zla AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 6: IF lastMatchesResultAverage IS bardzo_slabo OR lastMatchesResultBetweenAverage IS bardzo_slabo THEN prediction IS przegrana;
RULE 7: IF goalsAverage IS malo AND goalsLostAverage IS duzo THEN prediction IS przegrana;
RULE 8: IF redCardsAverage IS duzo AND penaltiesAverage IS duzo AND formationAgainstForm IS zla THEN prediction IS przegrana;
RULE 9: IF redCardsAverage IS duzo AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 10: IF lastMatchesResultAverage IS slabo AND formationAgainstForm IS zla THEN prediction IS przegrana;
RULE 11: IF lastMatchesResultBetweenAverage IS slabo AND formationAgainstForm IS zla THEN prediction IS przegrana;
RULE 12: IF lastMatchesResultAverage IS przecietnie AND formationAgainstForm IS zla AND possessionAverage IS malo THEN prediction IS przegrana;
RULE 13: IF lastMatchesResultBetweenAverage IS przecietnie AND formationAgainstForm IS zla AND possessionAverage IS malo THEN prediction IS przegrana;
RULE 14: IF lastMatchesResultAverage IS slabo OR lastMatchesResultBetweenAverage IS slabo THEN prediction IS przegrana;
RULE 15: IF penaltyAreaEntriesAverage IS czesto AND formationAgainstForm IS zla THEN prediction IS przegrana;
RULE 16: IF goalsAverage IS malo AND penaltiesAverage IS duzo THEN prediction IS przegrana;
RULE 17: IF goalsAverage IS malo AND goalsLostAverage IS duzo THEN prediction IS przegrana;
RULE 18: IF possessionAverage IS malo AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 19: IF formationAgainstForm IS przecietna AND goalkeeperForm IS zla AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 20: IF penaltiesAverage IS malo AND goalsLostAverage IS duzo AND goalsAverage IS malo THEN prediction IS przegrana;
RULE 21: IF shootsOnTargetAverage IS przecietnie AND goalsLostAverage IS duzo OR shootsOnTargetAverage IS przecietnie AND goalkeeperForm IS zla THEN prediction IS przegrana;
RULE 22: IF redCardsAverage IS przecietnie AND possessionAverage IS malo AND goalkeeperForm IS zla THEN prediction IS przegrana;
RULE 6: IF team1Form IS bardzo_slaba AND team2Form is slaba THEN prediction is remis;
RULE 7: IF team1Form IS slaba AND team2Form is slaba THEN prediction is team1;
RULE 8: IF team1Form IS srednia AND team2Form is slaba THEN prediction is team1;
RULE 9: IF team1Form IS dobra AND team2Form is slaba THEN prediction is team1;
RULE 10: IF team1Form IS bardzo_dobra AND team2Form is slaba THEN prediction is team1;
RULE 11: IF team1Form IS bardzo_slaba AND team2Form is srednia THEN prediction is team2;
RULE 12: IF team1Form IS slaba AND team2Form is srednia THEN prediction is remis;
RULE 13: IF team1Form IS srednia AND team2Form is srednia THEN prediction is team1;
RULE 14: IF team1Form IS dobra AND team2Form is srednia THEN prediction is team1;
RULE 15: IF team1Form IS bardzo_dobra AND team2Form is srednia THEN prediction is team1;
RULE 16: IF team1Form IS bardzo_slaba AND team2Form is dobra THEN prediction is team2;
RULE 17: IF team1Form IS slaba AND team2Form is dobra THEN prediction is team2;
RULE 18: IF team1Form IS srednia AND team2Form is dobra THEN prediction is remis;
RULE 19: IF team1Form IS dobra AND team2Form is dobra THEN prediction is team1;
RULE 20: IF team1Form IS bardzo_dobra AND team2Form is dobra THEN prediction is team1;
RULE 21: IF team1Form IS bardzo_slaba AND team2Form is bardzo_dobra THEN prediction is team2;
RULE 22: IF team1Form IS slaba AND team2Form is bardzo_dobra THEN prediction is team2;
RULE 23: IF team1Form IS srednia AND team2Form is bardzo_dobra THEN prediction is team2;
RULE 24: IF team1Form IS dobra AND team2Form is bardzo_dobra THEN prediction is remis;
RULE 25: IF team1Form IS bardzo_dobra AND team2Form is bardzo_dobra THEN prediction is team1;
RULE 26: IF team1GoalsAverage IS malo AND team2GoalsAverage is malo THEN prediction is remis;
RULE 27: IF team1GoalsAverage IS srednio AND team2GoalsAverage is malo THEN prediction is team1;
RULE 28: IF team1GoalsAverage IS duzo AND team2GoalsAverage is malo THEN prediction is team1;
RULE 29: IF team1GoalsAverage IS malo AND team2GoalsAverage is srednio THEN prediction is team2;
RULE 30: IF team1GoalsAverage IS srednio AND team2GoalsAverage is srednio THEN prediction is remis;
RULE 31: IF team1GoalsAverage IS duzo AND team2GoalsAverage is srednio THEN prediction is team1;
RULE 32: IF team1GoalsAverage IS malo AND team2GoalsAverage is duzo THEN prediction is team2;
RULE 33: IF team1GoalsAverage IS srednio AND team2GoalsAverage is duzo THEN prediction is team2;
RULE 34: IF team1GoalsAverage IS duzo AND team2GoalsAverage is duzo THEN prediction is remis;
RULE 35: IF team1GoalsLostAverage IS malo AND team2GoalsLostAverage is malo THEN prediction is remis;
RULE 36: IF team1GoalsLostAverage IS srednio AND team2GoalsLostAverage is malo THEN prediction is team2;
RULE 37: IF team1GoalsLostAverage IS duzo AND team2GoalsLostAverage is malo THEN prediction is team2;
RULE 38: IF team1GoalsLostAverage IS malo AND team2GoalsLostAverage is srednio THEN prediction is team1;
RULE 39: IF team1GoalsLostAverage IS srednio AND team2GoalsLostAverage is srednio THEN prediction is remis;
RULE 40: IF team1GoalsLostAverage IS duzo AND team2GoalsLostAverage is srednio THEN prediction is team2;
RULE 41: IF team1GoalsLostAverage IS malo AND team2GoalsLostAverage is duzo THEN prediction is team1;
RULE 42: IF team1GoalsLostAverage IS srednio AND team2GoalsLostAverage is duzo THEN prediction is team1;
RULE 43: IF team1GoalsLostAverage IS duzo AND team2GoalsLostAverage is duzo THEN prediction is remis;
RULE 21: IF goalkeeperForm IS znakomita AND penaltiesAverage IS duzo OR goalkeeperForm IS dobra AND penaltiesAverage IS duzo THEN prediction IS wygrana;
RULE 22: IF shootsOnTargetAverage IS duzo AND possessionAverage IS duzo OR shootsOnTargetAverage IS przecietnie AND possessionAverage IS duzo THEN prediction IS wygrana;
RULE 23: IF lastMatchesResultAverage IS bardzo_dobrze THEN prediction IS wygrana;
RULE 24: IF penaltyAreaEntriesAverage IS czesto AND lastMatchesResultAverage IS dobrze OR penaltyAreaEntriesAverage IS czesto AND lastMatchesResultAverage IS przecietnie THEN prediction IS wygrana;
RULE 25: IF goalsAverage IS duzo AND goalsLostAverage is malo OR goalsAverage IS przecietnie AND goalsLostAverage is malo THEN prediction IS wygrana;
RULE 26: IF formationAgainstForm is dobra AND possessionAverage IS przecietnie OR formationAgainstForm is dobra AND possessionAverage IS duzo THEN prediction IS wygrana;
RULE 27: IF lastMatchesResultBetweenAverage IS bardzo_dobrze THEN prediction IS wygrana;
RULE 28: IF lastMatchesResultBetweenAverage IS dobrze AND lastMatchesResultAverage IS dobrze OR lastMatchesResultBetweenAverage IS przecietnie AND lastMatchesResultAverage IS dobrze THEN prediction IS wygrana;
RULE 29: IF penaltiesAverage IS duzo THEN prediction IS wygrana;
RULE 30: IF redCardsAverage IS malo THEN prediction IS wygrana;
RULE 31: IF possessionAverage IS duzo AND goalsLostAverage IS malo THEN prediction IS wygrana;
RULE 32: IF penaltyAreaEntriesAverage is czesto THEN prediction IS wygrana;
RULE 33: IF goalsLostAverage IS malo THEN prediction IS wygrana;
RULE 34: IF goalkeeperForm IS znakomita THEN prediction IS wygrana;
RULE 35: IF formationAgainstForm IS przecietna AND goalsAverage IS duzo THEN prediction IS wygrana;
RULE 36: IF formationAgainstForm IS przecietna AND goalkeeperForm IS zla AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
RULE 37: IF penaltiesAverage IS przecietnie AND goalsLostAverage IS duzo AND goalsAverage IS malo THEN prediction IS przegrana;
RULE 38: IF shootsOnTargetAverage IS przecietnie AND goalsLostAverage IS duzo OR shootsOnTargetAverage IS przecietnie AND goalkeeperForm IS zla THEN prediction IS przegrana;
RULE 39: IF redCardsAverage IS przecietnie AND possessionAverage IS malo AND goalkeeperForm IS zla THEN prediction IS przegrana;
*/
END_RULEBLOCK
END_FUNCTION_BLOCK

View File

@ -47,18 +47,6 @@ public class Prediction {
for (com.resultprediction.polishekstraklasa.Predictions.Variable variable : variables){
fis.setVariable(variable.getName(), variable.getValue());
}
/*
fis.setVariable("goalkeeperForm", 85);
fis.setVariable("formationAgainstForm", 60);
fis.setVariable("shootsOnTargetAverage", 8);
fis.setVariable("possessionAverage", 80);
fis.setVariable("goalsAverage", 2);
fis.setVariable("goalsLostAverage", 0);
fis.setVariable("redCardsAverage", 0.1);
fis.setVariable("penaltyAreaEntriesAverage", 1);
fis.setVariable("penaltiesAverage", 0.1);
fis.setVariable("lastMatchesResultAverage", 8);
fis.setVariable("lastMatchesResultBetweenAverage", 8);*/
// Wylicza zbiory rozmyte
fis.evaluate();
@ -73,16 +61,20 @@ public class Prediction {
// Drukuje reguly
//System.out.println(fis);
variables.clear();
System.out.println(fis.getVariable("prediction"));
double draw = Double.valueOf(fis.getVariable("prediction").getMembership("remis"));
double win = Double.valueOf(fis.getVariable("prediction").getMembership("wygrana"));
double loss = Double.valueOf(fis.getVariable("prediction").getMembership("przegrana"));
if (draw > win && draw > loss)
return 0;
if (win > draw && win > loss)
return 1;
if (loss > draw && loss > win)
return 2;
double team1 = Double.valueOf(fis.getVariable("prediction").getMembership("team1"));
double team2 = Double.valueOf(fis.getVariable("prediction").getMembership("team2"));
if (draw >= team1 && draw >= team2) {
System.out.println("PREDICTION : DRAW\n\n");
return 0;
}
if (team1 > draw && team1 > team2) {
System.out.println("PREDICTION : team1\n\n");
return 1;
}
else {
System.out.println("PREDICTION : team2\n\n");
return 2;
}
}
}

View File

@ -19,31 +19,31 @@ public class PredictService {
*/
//goalkeeper form///////////////
private int howManyPastForGoalkeeperForm = 3; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
private int howManyPastForGoalkeeperForm = 4; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
////////////////////////////////
//formation form///////////////
private int howManyPastForFormationAgainstForm = 3; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
private int howManyPastForFormationAgainstForm = 4; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
//////////////////////////////
//teamform///////////////////////
private int howManyPastMatchesTeamForm = 3; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
private int howManyPastMatchesTeamForm = 4; //na ile ostatnich meczy patrzymy (maks 10 - można zwiększyć ale trzeba coś dorobić w kodzie)
// wartości na jak 'ważne' jest to zdarzenie
private int shootsOnTargetValue = 2;
private int possessionValue = 10;
private int goalsValue = 10;
private int goalsLostValue = 10;
private int shootsOnTargetValue = 5;
private int possessionValue = 4;
private int goalsValue = 8;
private int goalsLostValue = 8;
private int redCardsValue = 1;
private int penaltyAreaEntriesValue = 4;
private int penaltiesValue = 1;
private int lastMatchesResultValue = 20; private int howManyLastMatchesResult = 3;
private int lastMatchesResultBetweenValue = 10; private int howManyLastMatchesResultBetween = 3;
private int penaltyAreaEntriesValue = 5;
private int penaltiesValue = 3;
private int lastMatchesResultValue = 999999999; private int howManyLastMatchesResult = 4;
private int lastMatchesResultBetweenValue = 10; private int howManyLastMatchesResultBetween = 4;
/////////////////////////////
//jak bardzo licza się wyliczone poszczegolne wartosci dla ogolnego rozrachunku
private int gooalkeeperFormValue = 1;
private int formationFormValue = 1;
private int teamFormValue = 20;
private int gooalkeeperFormValue = 2;
private int formationFormValue = 3;
private int teamFormValue = 15;
//wlasnosci
@ -75,8 +75,7 @@ public class PredictService {
} else {
goalkeeperForm1 = calculateGoalkeeperForm(previousMatchesTeam1.subList(0, howManyPastForGoalkeeperForm - 1), team1);
}
Prediction.addToList(new Variable("goalkeeperForm", goalkeeperForm1));
System.out.println("Team1 Goalkeeper form = " + goalkeeperForm1);
//System.out.println("Team1 Goalkeeper form = " + goalkeeperForm1);
List<Match> formationMatchesTeam1 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeAndTeamsMatchStatistics2FormationOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeAndTeamsMatchStatistics1FormationOrderByDateDesc(team1, match.getSeason(), match.getDate(), match.getTeamsMatchStatistics2().getFormation(), team1, match.getSeason(), match.getDate(), match.getTeamsMatchStatistics2().getFormation());
double formationAgainstForm1;
@ -85,21 +84,21 @@ public class PredictService {
} else {
formationAgainstForm1 = calculateFormationForm(formationMatchesTeam1.subList(0, howManyPastForFormationAgainstForm - 1), team1);
}
Prediction.addToList(new Variable("formationAgainstForm", formationAgainstForm1));
System.out.println("Team1 Formation against form = " + formationAgainstForm1);
//System.out.println("Team1 Formation against form = " + formationAgainstForm1);
List<Match> teamFormMatches1 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team1, match.getSeason(), match.getDate(), team1, match.getSeason(), match.getDate());
double teamForm1;
if (howManyLastMatchesResult > teamFormMatches1.size()){
teamForm1 = calculateTeamForm(teamFormMatches1, team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate());
teamForm1 = calculateTeamForm(teamFormMatches1, team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate(), "team1");
} else {
teamForm1 = calculateTeamForm(teamFormMatches1.subList(0, howManyLastMatchesResult - 1), team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate());
teamForm1 = calculateTeamForm(teamFormMatches1.subList(0, howManyLastMatchesResult - 1), team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate(), "team1");
}
System.out.println("Team1 Form = " + teamForm1);
//System.out.println("Team1 Form = " + teamForm1);
double calculatedTeam1Form = ((goalkeeperForm1 * gooalkeeperFormValue) + (formationAgainstForm1 * formationFormValue) + (teamForm1 * teamFormValue)) / (gooalkeeperFormValue + formationFormValue + teamFormValue);
System.out.println("Team1 Calculated Form = " + calculatedTeam1Form);
int team1Value = Prediction.make();
//int team1Value = Prediction.make();
Prediction.addToList(new Variable("team1Form", calculatedTeam1Form));
Team team2 = match.getTeamsMatchStatistics2().getTeam();
List<Match> previousMatchesTeam2 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team2, match.getSeason(), match.getDate(), team2, match.getSeason(), match.getDate());
@ -110,8 +109,7 @@ public class PredictService {
} else {
goalkeeperForm2 = calculateGoalkeeperForm(previousMatchesTeam2.subList(0, howManyPastForGoalkeeperForm - 1), team1);
}
Prediction.addToList(new Variable("goalkeeperForm", goalkeeperForm2));
System.out.println("Team2 Goalkeeper form = " + goalkeeperForm2);
//System.out.println("Team2 Goalkeeper form = " + goalkeeperForm2);
List<Match> formationMatchesTeam2 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeAndTeamsMatchStatistics2FormationOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeAndTeamsMatchStatistics1FormationOrderByDateDesc(team2, match.getSeason(), match.getDate(), match.getTeamsMatchStatistics1().getFormation(), team2, match.getSeason(), match.getDate(), match.getTeamsMatchStatistics1().getFormation());
double formationAgainstForm2;
@ -120,38 +118,23 @@ public class PredictService {
} else {
formationAgainstForm2 = calculateFormationForm(formationMatchesTeam2.subList(0, howManyPastForFormationAgainstForm - 1), team2);
}
Prediction.addToList(new Variable("formationAgainstForm", formationAgainstForm2));
System.out.println("Team2 Formation against form = " + formationAgainstForm2);
//System.out.println("Team2 Formation against form = " + formationAgainstForm2);
List<Match> teamFormMatches2 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team2, match.getSeason(), match.getDate(), team2, match.getSeason(), match.getDate());
double teamForm2;
if (howManyLastMatchesResult > teamFormMatches2.size()){
teamForm2 = calculateTeamForm(teamFormMatches2, team2, team1, match.getDate());
teamForm2 = calculateTeamForm(teamFormMatches2, team2, team1, match.getDate(), "team2");
} else {
teamForm2 = calculateTeamForm(teamFormMatches2.subList(0, howManyLastMatchesResult - 1), team2, team1, match.getDate());
teamForm2 = calculateTeamForm(teamFormMatches2.subList(0, howManyLastMatchesResult - 1), team2, team1, match.getDate(), "team2");
}
System.out.println("Team2 Form = " + teamForm2);
//System.out.println("Team2 Form = " + teamForm2);
double calculatedTeam2Form = ((goalkeeperForm2 * gooalkeeperFormValue) + (formationAgainstForm2 * formationFormValue) + (teamForm2 * teamFormValue)) / (gooalkeeperFormValue + formationFormValue + teamFormValue);
System.out.println("Team2 Calculated Form = " + calculatedTeam2Form);
int team2Value = Prediction.make();
Prediction.addToList(new Variable("team2Form", calculatedTeam2Form));
System.out.println(match.getTeamsMatchStatistics1().getGoals() + ":" + match.getTeamsMatchStatistics1().getGoals_lost());
if (team1Value == team2Value){
match.setPredicted_result(0);
}
else if (team1Value == 1){
match.setPredicted_result(1);
}
else if (team2Value == 1){
match.setPredicted_result(2);
}
else if (team2Value == 0 && team1Value == 2){
match.setPredicted_result(2);
}
else if (team1Value == 0 && team2Value == 2){
match.setPredicted_result(1);
}
match.setPredicted_result(Prediction.make());
matchRepository.save(match);
//int winner = whoWillWin(calculatedTeam1Form, calculatedTeam2Form);
@ -176,17 +159,10 @@ public class PredictService {
}*/
private int calculateTeamForm(List<Match> matches, Team team, Team enemy, Date actualMatchDate) {
private int calculateTeamForm(List<Match> matches, Team team, Team enemy, Date actualMatchDate, String addToFuzzyVariable) {
if (matches.size() == 0) {
Prediction.addToList(new Variable("shootsOnTargetAverage", (double)0));
Prediction.addToList(new Variable("possessionAverage", (double)50));
Prediction.addToList(new Variable("goalsAverage", (double)0));
Prediction.addToList(new Variable("goalsLostAverage", (double)0));
Prediction.addToList(new Variable("redCardsAverage", (double)0));
Prediction.addToList(new Variable("penaltyAreaEntriesAverage", (double)0));
Prediction.addToList(new Variable("penaltiesAverage", (double)0));
Prediction.addToList(new Variable("lastMatchesResultAverage", (double)0));
Prediction.addToList(new Variable("lastMatchesResultBetweenAverage", (double)0));
Prediction.addToList(new Variable(addToFuzzyVariable + "GoalsAverage", (double) 1));
Prediction.addToList(new Variable(addToFuzzyVariable + "GoalsLostAverage", (double) 1));
return 100;
}
@ -275,26 +251,19 @@ public class PredictService {
lastMatchesResultBetweenAverage = lastMatchesResultBetweenAverage / matchesBetween.size();
else lastMatchesResultBetweenAverage = 0;
Prediction.addToList(new Variable("shootsOnTargetAverage", shootsOnTargetAverage));
Prediction.addToList(new Variable("possessionAverage", possessionAverage));
Prediction.addToList(new Variable("goalsAverage", goalsAverage));
Prediction.addToList(new Variable("goalsLostAverage", goalsLostAverage));
Prediction.addToList(new Variable("redCardsAverage", redCardsAverage));
Prediction.addToList(new Variable("penaltyAreaEntriesAverage", penaltyAreaEntriesAverage));
Prediction.addToList(new Variable("penaltiesAverage", penaltiesAverage));
Prediction.addToList(new Variable("lastMatchesResultAverage", lastMatchesResultAverage));
Prediction.addToList(new Variable("lastMatchesResultBetweenAverage", lastMatchesResultBetweenAverage));
Prediction.addToList(new Variable(addToFuzzyVariable + "GoalsAverage", goalsAverage));
Prediction.addToList(new Variable(addToFuzzyVariable + "GoalsLostAverage", goalsLostAverage));
return calculateTeamStatsByAverages(shootsOnTargetAverage, possessionAverage, goalsAverage, goalsLostAverage, redCardsAverage, penaltyAreaEntriesAverage, penaltiesAverage, lastMatchesResultAverage, lastMatchesResultBetweenAverage, matches.size(), lastMatchesBetweenSize);
}
private int calculateTeamStatsByAverages(double shootsOnTargetAverage, double possessionAverage, double goalsAverage, double goalsLostAverage, double redCardsAverage, double penaltyAreaEntriesAverage, double penaltiesAverage, double lastMatchesResultAverage, double lastMatchesResultBetweenAverage, double howManyLastMatchesSize, double lastMatchesBetweenSize) {
double fuzzyValueOfShootsOnTarget = fuzzyChecker(2,10, 10, shootsOnTargetAverage);
double fuzzyValueOfPossession = fuzzyChecker(30,70, 70, possessionAverage);
double fuzzyValueOfPossession = fuzzyChecker(40,60, 60, possessionAverage);
double fuzzyValueOfGoals = fuzzyChecker(1,3, 3, goalsAverage);
double fuzzyValueOfGoalsLost = fuzzyChecker(0,0, 3, goalsLostAverage);
double fuzzyValueOfRedCards = fuzzyChecker(0,0, 1, redCardsAverage);
double fuzzyValueOfPenaltyAreaEntries = fuzzyChecker(10,25, 25, penaltyAreaEntriesAverage);
double fuzzyValueOfPenaltyAreaEntries = fuzzyChecker(3,15, 15, penaltyAreaEntriesAverage);
double fuzzyValueOfPenalties = fuzzyChecker(0,1, 1, penaltiesAverage);
double fuzzyValueOfLastMatchesResult = fuzzyChecker(0,(int)howManyLastMatchesSize * 3, (int)howManyLastMatchesSize * 3, lastMatchesResultAverage);
double fuzzyValueOfLastMatchesResultBetween = fuzzyChecker(0,(int)lastMatchesBetweenSize * 3, (int)lastMatchesBetweenSize * 3, lastMatchesResultBetweenAverage);