pred
This commit is contained in:
parent
68f81edc2d
commit
d8066450a5
@ -1,22 +0,0 @@
|
||||
package com.resultprediction.polishekstraklasa.Predictions;
|
||||
|
||||
import net.sourceforge.jFuzzyLogic.JFuzzyLogic;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Fuzzy {
|
||||
|
||||
public static JFuzzyLogic jFuzzyLogic = null;
|
||||
|
||||
public Fuzzy() {
|
||||
File file = new File("Prediction.fcl");
|
||||
String fileName = file.getAbsolutePath();
|
||||
String[] a = new String[2];
|
||||
a[0] = "-c";
|
||||
a[1] = fileName.replace("Prediction.fcl", "src\\main\\java\\com\\resultprediction\\polishekstraklasa\\Predictions\\Prediction.fcl");
|
||||
jFuzzyLogic = new JFuzzyLogic(a);
|
||||
jFuzzyLogic.run();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -45,13 +45,13 @@ END_FUZZIFY
|
||||
FUZZIFY goalsAverage
|
||||
TERM malo := (0, 1) (1, 0);
|
||||
TERM przecietnie := (1, 0) (1.5,1) (2,0);
|
||||
TERM duzo := (2, 0) (3, 1);
|
||||
TERM duzo := (2, 0) (3, 1) (10, 1);
|
||||
END_FUZZIFY
|
||||
|
||||
FUZZIFY goalsLostAverage
|
||||
TERM malo := (0, 1) (1, 0);
|
||||
TERM przecietnie := (1, 0) (1.5,1) (2,0);
|
||||
TERM duzo := (2, 0) (3, 1);
|
||||
TERM duzo := (2, 0) (3, 1) (10, 1);
|
||||
END_FUZZIFY
|
||||
|
||||
FUZZIFY redCardsAverage
|
||||
@ -69,7 +69,7 @@ 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);
|
||||
TERM duzo := (0.3, 0) (0.4, 1) (1 , 1) (5, 1);
|
||||
END_FUZZIFY
|
||||
|
||||
FUZZIFY lastMatchesResultAverage
|
||||
@ -89,10 +89,10 @@ FUZZIFY lastMatchesResultBetweenAverage
|
||||
END_FUZZIFY
|
||||
|
||||
DEFUZZIFY prediction
|
||||
TERM przegrana := (0,1) (10,0);
|
||||
TERM remis := (10,0) (15,1) (20,0);
|
||||
TERM wygrana := (20,0) (30,1);
|
||||
DEFAULT := 0;
|
||||
TERM przegrana := (-1,1) (0,0);
|
||||
TERM remis := (-0.2,0) (0,1) (0.2,0);
|
||||
TERM wygrana := (0,0) (1,1);
|
||||
DEFAULT := 10;
|
||||
END_DEFUZZIFY
|
||||
|
||||
RULEBLOCK No1
|
||||
@ -101,43 +101,9 @@ RULEBLOCK No1
|
||||
ACCU : MAX;
|
||||
|
||||
|
||||
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 goalkeeperForm IS znakomita AND penaltiesAverage IS duzo OR goalkeeperForm IS dobra AND penaltiesAverage IS duzo THEN prediction IS wygrana;
|
||||
RULE 20: IF shootsOnTargetAverage IS duzo AND possessionAverage IS duzo OR shootsOnTargetAverage IS przecietnie AND possessionAverage IS duzo THEN prediction IS wygrana;
|
||||
RULE 21: IF lastMatchesResultAverage IS bardzo_dobrze THEN prediction IS wygrana;
|
||||
RULE 22: IF penaltyAreaEntriesAverage IS czesto AND lastMatchesResultAverage IS dobrze OR penaltyAreaEntriesAverage IS czesto AND lastMatchesResultAverage IS przecietnie THEN prediction IS wygrana;
|
||||
RULE 23: IF goalsAverage IS duzo AND goalsLostAverage is malo OR goalsAverage IS przecietnie AND goalsLostAverage is malo THEN prediction IS wygrana;
|
||||
RULE 24: IF formationAgainstForm is dobra AND possessionAverage IS przecietnie OR formationAgainstForm is dobra AND possessionAverage IS duzo THEN prediction IS wygrana;
|
||||
RULE 25: IF lastMatchesResultBetweenAverage IS bardzo_dobrze THEN prediction IS wygrana;
|
||||
RULE 26: IF lastMatchesResultBetweenAverage IS dobrze AND lastMatchesResultAverage IS dobrze OR lastMatchesResultBetweenAverage IS przecietnie AND lastMatchesResultAverage IS dobrze THEN prediction IS wygrana;
|
||||
RULE 27: IF penaltiesAverage IS duzo THEN prediction IS wygrana;
|
||||
RULE 28: IF redCardsAverage IS malo THEN prediction IS wygrana;
|
||||
RULE 29: IF possessionAverage IS duzo AND goalsLostAverage IS malo THEN prediction IS wygrana;
|
||||
RULE 30: IF penaltyAreaEntriesAverage is czesto THEN prediction IS wygrana;
|
||||
RULE 31: IF goalsLostAverage IS malo THEN prediction IS wygrana;
|
||||
RULE 32: IF goalkeeperForm IS znakomita THEN prediction IS wygrana;
|
||||
RULE 33: IF formationAgainstForm IS przecietna AND goalsAverage IS duzo THEN prediction IS wygrana;
|
||||
RULE 34: IF formationAgainstForm IS przecietna AND goalkeeperForm IS zla AND shootsOnTargetAverage IS malo THEN prediction IS przegrana;
|
||||
RULE 35: IF penaltiesAverage IS przecietnie AND goalsLostAverage IS duzo AND goalsAverage IS malo THEN prediction IS przegrana;
|
||||
RULE 36: IF shootsOnTargetAverage IS przecietnie AND goalsLostAverage IS duzo OR shootsOnTargetAverage IS przecietnie AND goalkeeperForm IS zla THEN prediction IS przegrana;
|
||||
RULE 37: IF redCardsAverage IS przecietnie AND possessionAverage IS malo AND goalkeeperForm IS zla THEN prediction IS przegrana;
|
||||
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;
|
||||
|
||||
END_RULEBLOCK
|
||||
|
||||
|
@ -28,10 +28,9 @@ public class Prediction {
|
||||
}
|
||||
|
||||
|
||||
public static void make() {
|
||||
public static int make() {
|
||||
|
||||
// Load from 'FCL' file
|
||||
//FIS fis = Fuzzy.jFuzzyLogic.getFis();
|
||||
File file = new File("Prediction.fcl");
|
||||
String fileName = file.getAbsolutePath().replace("Prediction.fcl", "src\\main\\java\\com\\resultprediction\\polishekstraklasa\\Predictions\\Prediction.fcl");
|
||||
FIS fis = FIS.load(fileName, true);
|
||||
@ -42,7 +41,7 @@ public class Prediction {
|
||||
}
|
||||
// Pokazuje reguly
|
||||
FunctionBlock functionBlock = fis.getFunctionBlock(null);
|
||||
JFuzzyChart.get().chart(functionBlock);
|
||||
//JFuzzyChart.get().chart(functionBlock);
|
||||
|
||||
// Ustawia wejscia
|
||||
for (com.resultprediction.polishekstraklasa.Predictions.Variable variable : variables){
|
||||
@ -69,12 +68,21 @@ public class Prediction {
|
||||
|
||||
// Pokazuje wykres zmiennych wyjsciowych
|
||||
|
||||
JFuzzyChart.get().chart(prediction, prediction.getDefuzzifier(), true);
|
||||
//JFuzzyChart.get().chart(prediction, prediction.getDefuzzifier(), true);
|
||||
|
||||
// Drukuje reguly
|
||||
//System.out.println(fis);
|
||||
System.out.println(fis);
|
||||
System.out.println("Napiwek:" + fis.getVariable("prediction"));
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -31,7 +31,6 @@ public class PredictionsApplication {
|
||||
|
||||
ConfigurableApplicationContext context = builder.run(args);
|
||||
|
||||
//Fuzzy fuzzy = new Fuzzy();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.resultprediction.polishekstraklasa.Predictions.controllers;
|
||||
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.match.Match;
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.match.MatchDTO;
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.match.MatchRepository;
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.match.PredictService;
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.team.Team;
|
||||
@ -8,16 +9,13 @@ import com.resultprediction.polishekstraklasa.Predictions.model.team.TeamReposit
|
||||
import com.resultprediction.polishekstraklasa.Predictions.model.teamsMatchStatistics.TeamsMatchStatisticsRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/matches")
|
||||
public class MatchController {
|
||||
|
||||
@ -86,4 +84,10 @@ public class MatchController {
|
||||
public String predict() {
|
||||
return predictService.predictMatches();
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public List<MatchDTO> getMatches() {
|
||||
return predictService.getMatches();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.resultprediction.polishekstraklasa.Predictions.model.match;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class MatchDTO {
|
||||
|
||||
private Long id;
|
||||
private String result;
|
||||
private String predictedResult;
|
||||
private String predictedGoals;
|
||||
private String season;
|
||||
private String date;
|
||||
private String teamName1;
|
||||
private String teamName2;
|
||||
|
||||
}
|
@ -99,7 +99,7 @@ public class PredictService {
|
||||
|
||||
double calculatedTeam1Form = ((goalkeeperForm1 * gooalkeeperFormValue) + (formationAgainstForm1 * formationFormValue) + (teamForm1 * teamFormValue)) / (gooalkeeperFormValue + formationFormValue + teamFormValue);
|
||||
System.out.println("Team1 Calculated Form = " + calculatedTeam1Form);
|
||||
Prediction.make();
|
||||
int team1Value = Prediction.make();
|
||||
|
||||
Team team2 = match.getTeamsMatchStatistics2().getTeam();
|
||||
List<Match> previousMatchesTeam2 = matchRepository.findTop10ByTeamsMatchStatistics1TeamAndSeasonAndDateBeforeOrTeamsMatchStatistics2TeamAndSeasonAndDateBeforeOrderByDateDesc(team2, match.getSeason(), match.getDate(), team2, match.getSeason(), match.getDate());
|
||||
@ -134,11 +134,25 @@ public class PredictService {
|
||||
System.out.println("Team2 Form = " + teamForm2);
|
||||
double calculatedTeam2Form = ((goalkeeperForm2 * gooalkeeperFormValue) + (formationAgainstForm2 * formationFormValue) + (teamForm2 * teamFormValue)) / (gooalkeeperFormValue + formationFormValue + teamFormValue);
|
||||
System.out.println("Team2 Calculated Form = " + calculatedTeam2Form);
|
||||
Prediction.make();
|
||||
int team2Value = Prediction.make();
|
||||
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);
|
||||
}
|
||||
matchRepository.save(match);
|
||||
|
||||
//int winner = whoWillWin(calculatedTeam1Form, calculatedTeam2Form);
|
||||
/* LeagueTable leagueTable = new LeagueTable(matchRepository.findAllByDateBeforeAndSeason(match.getDate(), match.getSeason()));
|
||||
@ -375,4 +389,27 @@ public class PredictService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<MatchDTO> getMatches() {
|
||||
List<Match> matches = matchRepository.findAllByOrderByDateAsc();
|
||||
List<MatchDTO> matchDTOS = new ArrayList<>();
|
||||
for (Match match : matches){
|
||||
String result;
|
||||
if (match.getResult() == 1)
|
||||
result = match.getTeamsMatchStatistics1().getTeam().getName();
|
||||
else if (match.getResult() == 2)
|
||||
result = match.getTeamsMatchStatistics2().getTeam().getName();
|
||||
else
|
||||
result = "X";
|
||||
|
||||
String predictedResult;
|
||||
if (match.getPredicted_result() == 1)
|
||||
predictedResult = match.getTeamsMatchStatistics1().getTeam().getName();
|
||||
else if (match.getPredicted_result() == 2)
|
||||
predictedResult = match.getTeamsMatchStatistics2().getTeam().getName();
|
||||
else
|
||||
predictedResult = "X";
|
||||
matchDTOS.add(new MatchDTO(match.getId(), result, predictedResult, match.getPredicted_goals(), match.getSeason().toString(), match.getDate().toString(), match.getTeamsMatchStatistics1().getTeam().getName(), match.getTeamsMatchStatistics2().getTeam().getName()));
|
||||
}
|
||||
return matchDTOS;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user