This commit is contained in:
= 2020-05-24 12:22:13 +02:00
parent b375d70bbc
commit 09afa32b38
10 changed files with 320 additions and 15 deletions

View File

@ -33,6 +33,10 @@
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jFuzzyLogic</groupId>
<artifactId>jFuzzyLogic</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>

View File

@ -0,0 +1,171 @@
FUNCTION_BLOCK prediction // Definicja bloku (moze byc wiecej blokow w pliku)
VAR_INPUT // Definiuje zmienne wejsciowe
goalkeeperForm1 : REAL;
formationAgainstForm1 : REAL;
shootsOnTargetAverage1 : REAL;
possessionAverage1 : REAL;
goalsAverage1 : REAL;
goalsLostAverage1 : REAL;
redCardsAverage1 : REAL;
penaltyAreaEntriesAverage1 : REAL;
penaltiesAverage1 : REAL;
lastMatchesResultAverage1 : REAL;
lastMatchesResultBetweenAverage1 : REAL;
goalkeeperForm2 : REAL;
formationAgainstForm2 : REAL;
shootsOnTargetAverage2 : REAL;
possessionAverage2 : REAL;
goalsAverage2 : REAL;
goalsLostAverage2 : REAL;
redCardsAverage2 : REAL;
penaltyAreaEntriesAverage2 : REAL;
penaltiesAverage2 : REAL;
lastMatchesResultAverage2 : REAL;
lastMatchesResultBetweenAverage2 : REAL;
END_VAR
VAR_OUTPUT // Definiuje zmienne wyjsciowe
prediction : REAL;
END_VAR
FUZZIFY goalkeeperForm1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY goalkeeperForm2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY formationAgainstForm1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY formationAgainstForm2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY shootsOnTargetAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY shootsOnTargetAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY possessionAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY possessionAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY goalsAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY goalsAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY goalsLostAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY goalsLostAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY redCardsAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY redCardsAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY penaltyAreaEntriesAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY penaltyAreaEntriesAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY penaltiesAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY penaltiesAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultBetweenAverage1
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY lastMatchesResultBetweenAverage2
TERM zla := (0, 1) (4, 0) ;
TERM dobra := (1, 0) (4,1) (6,1) (9,0);
TERM znakomita := (6, 0) (9, 1);
END_FUZZIFY
DEFUZZIFY prediction // Zmienna wyjsciowa 'prediction' : {'skromny', 'sredni', 'hojny' }
TERM skromny := (0,0) (5,1) (11,0);
TERM sredni := (9,0) (15,1) (21,0);
TERM hojny := (19,0) (25,1) (30,0);
METHOD : COG; // Metoda defuzyfikacji - 'Center Of Gravity' - 'Sreodka ciezkosci'
DEFAULT := 0;
END_DEFUZZIFY
RULEBLOCK No1
AND : MIN; // Uzycie 'min' jako 'and' (implikuje uzycie 'max' jako 'or' dla zapewnienia praw DeMorgan'a)
ACT : MIN; // Uzycie 'min' jako metody aktywacji
ACCU : MAX; // Metoda agregacji - 'max'
RULE 1 : IF goalkeeperForm1 IS zla OR goalkeeperForm2 is zla THEN prediction IS skromny;
END_RULEBLOCK
END_FUNCTION_BLOCK

View File

@ -0,0 +1,78 @@
package com.resultprediction.polishekstraklasa.Predictions;
import lombok.Getter;
import lombok.Setter;
import net.sourceforge.jFuzzyLogic.FIS;
import net.sourceforge.jFuzzyLogic.FunctionBlock;
import net.sourceforge.jFuzzyLogic.plot.JFuzzyChart;
import net.sourceforge.jFuzzyLogic.rule.Variable;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class Prediction {
@Getter
@Setter
private static List<com.resultprediction.polishekstraklasa.Predictions.Variable> variables = new ArrayList<>();
public static void addToList(com.resultprediction.polishekstraklasa.Predictions.Variable variable){
variables.add(variable);
}
public static void make() {
// Load from 'FCL' file
String fileName = "C:\\Users\\Adrian\\Desktop\\Systemy rozmyte\\Back\\src\\main\\java\\com\\resultprediction\\polishekstraklasa\\Predictions\\Prediction.fcl";
FIS fis = FIS.load(fileName, true);
if( fis == null ) {
System.err.println("Nie moge zaladowc pliku: '" + fileName + "'");
return;
}
// Pokazuje reguly
FunctionBlock functionBlock = fis.getFunctionBlock(null);
JFuzzyChart.get().chart(functionBlock);
// Ustawia wejscia
for (com.resultprediction.polishekstraklasa.Predictions.Variable variable : variables){
fis.setVariable(variable.getName(), variable.getValue());
}
/*
fis.setVariable("obsluga", 3);
fis.setVariable("jedzenie", 8);*/
// Wylicza zbiory rozmyte
fis.evaluate();
// Ustawia wyjscia
Variable prediction = functionBlock.getVariable("prediction");
// Pokazuje wykres zmiennych wyjsciowych
JFuzzyChart.get().chart(prediction, prediction.getDefuzzifier(), true);
// Drukuje reguly
System.out.println(fis);
System.out.println("Prediction:" + fis.getVariable("prediction").getValue());
Process proc = null;
try {
proc = Runtime.getRuntime().exec("javac -cp jFuzzyLogic.jar Prediction.java");
} catch (IOException e) {
e.printStackTrace();
}
try {
proc = Runtime.getRuntime().exec("java -cp jFuzzyLogic.jar;. Prediction");
} catch (IOException e) {
e.printStackTrace();
}
InputStream in = proc.getInputStream();
InputStream err = proc.getErrorStream();
variables.clear();
}
}

View File

@ -4,6 +4,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ -19,7 +21,12 @@ import java.util.Map;
public class PredictionsApplication {
public static void main(String[] args) {
SpringApplication.run(PredictionsApplication.class, args);
SpringApplicationBuilder builder = new SpringApplicationBuilder(PredictionsApplication.class);
//SpringApplication.run(PredictionsApplication.class, args);
builder.headless(false);
ConfigurableApplicationContext context = builder.run(args);
}
}

View File

@ -0,0 +1,21 @@
package com.resultprediction.polishekstraklasa.Predictions;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
public class Variable {
@Getter
@Setter
private String name;
@Getter
@Setter
private Integer value;
}

View File

@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.util.Date;

View File

@ -1,9 +1,12 @@
package com.resultprediction.polishekstraklasa.Predictions.model.match;
import com.resultprediction.polishekstraklasa.Predictions.Prediction;
import com.resultprediction.polishekstraklasa.Predictions.Variable;
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -44,10 +47,10 @@ public class PredictService {
//wlasnosci
private int homeTeamBoost = 20; // w punktach [0,100]
/*private int homeTeamBoost = 20; // w punktach [0,100]
private int downwardZoneDrawBoost = 10; // w punktach [0,100]
*/
//private int winningStreakChanceForLoseValue = 1;
@ -72,6 +75,7 @@ public class PredictService {
} else {
goalkeeperForm1 = calculateGoalkeeperForm(previousMatchesTeam1.subList(0, howManyPastForGoalkeeperForm - 1), team1);
}
Prediction.addToList(new Variable("goalkeeperForm1", 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());
@ -81,14 +85,15 @@ public class PredictService {
} else {
formationAgainstForm1 = calculateFormationForm(formationMatchesTeam1.subList(0, howManyPastForFormationAgainstForm - 1), team1);
}
Prediction.addToList(new Variable("formationAgainstForm1", formationAgainstForm1));
System.out.println("Team1 Formation against form = " + formationAgainstForm1);
List<Match> teamFormMatches1 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team1, match.getSeason(), match.getDate(), team1, match.getSeason(), match.getDate());
int teamForm1;
if (howManyLastMatchesResult > teamFormMatches1.size()){
teamForm1 = calculateTeamForm(teamFormMatches1, team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate());
teamForm1 = calculateTeamForm(teamFormMatches1, team1, match.getTeamsMatchStatistics2().getTeam(), match.getDate(),"1");
} 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(),"1");
}
System.out.println("Team1 Form = " + teamForm1);
@ -105,6 +110,7 @@ public class PredictService {
} else {
goalkeeperForm2 = calculateGoalkeeperForm(previousMatchesTeam2.subList(0, howManyPastForGoalkeeperForm - 1), team1);
}
Prediction.addToList(new Variable("goalkeeperForm2", 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());
@ -114,27 +120,32 @@ public class PredictService {
} else {
formationAgainstForm2 = calculateFormationForm(formationMatchesTeam2.subList(0, howManyPastForFormationAgainstForm - 1), team2);
}
Prediction.addToList(new Variable("formationAgainstForm2", formationAgainstForm2));
System.out.println("Team2 Formation against form = " + formationAgainstForm2);
List<Match> teamFormMatches2 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team2, match.getSeason(), match.getDate(), team2, match.getSeason(), match.getDate());
int teamForm2;
if (howManyLastMatchesResult > teamFormMatches2.size()){
teamForm2 = calculateTeamForm(teamFormMatches2, team2, team1, match.getDate());
teamForm2 = calculateTeamForm(teamFormMatches2, team2, team1, match.getDate(),"2");
} else {
teamForm2 = calculateTeamForm(teamFormMatches2.subList(0, howManyLastMatchesResult - 1), team2, team1, match.getDate());
teamForm2 = calculateTeamForm(teamFormMatches2.subList(0, howManyLastMatchesResult - 1), team2, team1, match.getDate(),"2");
}
System.out.println("Team2 Form = " + teamForm2);
int calculatedTeam2Form = ((goalkeeperForm2 * gooalkeeperFormValue) + (formationAgainstForm2 * formationFormValue) + (teamForm2 * teamFormValue)) / (gooalkeeperFormValue + formationFormValue + teamFormValue);
System.out.println("Team2 Calculated Form = " + calculatedTeam2Form);
System.out.println(match.getTeamsMatchStatistics1().getGoals() + ":" + match.getTeamsMatchStatistics1().getGoals_lost());
Prediction.make();
//int winner = whoWillWin(calculatedTeam1Form, calculatedTeam2Form);
LeagueTable leagueTable = new LeagueTable(matchRepository.findAllByDateBeforeAndSeason(match.getDate(), match.getSeason()));
/* LeagueTable leagueTable = new LeagueTable(matchRepository.findAllByDateBeforeAndSeason(match.getDate(), match.getSeason()));
System.out.println("###############################################################");
for (LeagueTeamScore leagueTeamScore : leagueTable.getLeagueTeamScores()){
System.out.println(leagueTeamScore.getScore() + " " + leagueTeamScore.getTeam().getName());
}
System.out.println("###############################################################");
System.out.println("###############################################################");*/
}
return "done";
@ -150,7 +161,7 @@ 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 nameForFuzzy) {
if (matches.size() == 0)
return 100;
@ -239,9 +250,15 @@ public class PredictService {
lastMatchesResultBetweenAverage = lastMatchesResultBetweenAverage / matchesBetween.size();
else lastMatchesResultBetweenAverage = 0;
Prediction.addToList(new Variable("shootsOnTargetAverage" + nameForFuzzy, shootsOnTargetAverage));
Prediction.addToList(new Variable("possessionAverage" + nameForFuzzy, possessionAverage));
Prediction.addToList(new Variable("goalsAverage" + nameForFuzzy, goalsAverage));
Prediction.addToList(new Variable("goalsLostAverage" + nameForFuzzy, goalsLostAverage));
Prediction.addToList(new Variable("redCardsAverage" + nameForFuzzy, redCardsAverage));
Prediction.addToList(new Variable("penaltyAreaEntriesAverage" + nameForFuzzy, penaltyAreaEntriesAverage));
Prediction.addToList(new Variable("penaltiesAverage" + nameForFuzzy, penaltiesAverage));
Prediction.addToList(new Variable("lastMatchesResultAverage" + nameForFuzzy, lastMatchesResultAverage));
Prediction.addToList(new Variable("lastMatchesResultBetweenAverage" + nameForFuzzy, lastMatchesResultBetweenAverage));
return calculateTeamStatsByAverages(shootsOnTargetAverage, possessionAverage, goalsAverage, goalsLostAverage, redCardsAverage, penaltyAreaEntriesAverage, penaltiesAverage, lastMatchesResultAverage, lastMatchesResultBetweenAverage, matches.size(), lastMatchesBetweenSize);
}

View File

@ -0,0 +1,8 @@
Kompilacja w laboratoriach:
javac -cp jFuzzyLogic.jar prediction.java
Uruchomienie Windows
java -cp jFuzzyLogic.jar;. prediction
Uruchomienie Linux
java -cp jFuzzyLogic.jar:. prediction

View File

@ -1,4 +1,4 @@
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3307/ekstraklasa
spring.datasource.url=jdbc:mysql://localhost:3306/ekstraklasa
spring.datasource.username=ekstra
spring.datasource.password=YnBDC0hqqhKaxt94