fcl refactor

This commit is contained in:
= 2020-05-24 14:43:33 +02:00
parent 88b838b968
commit 6bb53d21fb
5 changed files with 62 additions and 44 deletions

View File

@ -0,0 +1,22 @@
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();
}
}

View File

@ -105,4 +105,4 @@ RULEBLOCK No1
RULE 3: IF lastMatchesResultBetweenAverage IS slabo OR lastMatchesResultBetweenAverage IS przecietnie OR lastMatchesResultBetweenAverage IS dobrze THEN prediction IS remis;
END_RULEBLOCK
END_FUNCTION_BLOCK
END_FUNCTION_BLOCK

View File

@ -5,6 +5,7 @@ import lombok.Setter;
import net.sourceforge.jFuzzyLogic.FIS;
import net.sourceforge.jFuzzyLogic.FunctionBlock;
import net.sourceforge.jFuzzyLogic.JFuzzyLogic;
import net.sourceforge.jFuzzyLogic.plot.JFuzzyChart;
import net.sourceforge.jFuzzyLogic.rule.Variable;
@ -27,52 +28,31 @@ public class Prediction {
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);
// Load from 'FCL' file
FIS fis = Fuzzy.jFuzzyLogic.getFis();
// 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);*/
// Ustawia wejscia
for (com.resultprediction.polishekstraklasa.Predictions.Variable variable : variables){
fis.setVariable(variable.getName(), variable.getValue());
}
// Wylicza zbiory rozmyte
fis.evaluate();
// Wylicza zbiory rozmyte
fis.evaluate();
// Ustawia wyjscia
Variable prediction = functionBlock.getVariable("prediction");
// Ustawia wyjscia
Variable prediction = functionBlock.getVariable("prediction");
// Pokazuje wykres zmiennych wyjsciowych
// 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();
JFuzzyChart.get().chart(prediction, prediction.getDefuzzifier(), true);
// Drukuje reguly
//System.out.println(fis);
System.out.println("Prediction:" + fis.getVariable("prediction"));
variables.clear();
}
}

View File

@ -1,5 +1,6 @@
package com.resultprediction.polishekstraklasa.Predictions;
import net.sourceforge.jFuzzyLogic.JFuzzyLogic;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -14,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@SpringBootApplication
@ -27,6 +30,8 @@ public class PredictionsApplication {
builder.headless(false);
ConfigurableApplicationContext context = builder.run(args);
Fuzzy fuzzy = new Fuzzy();
}
}

View File

@ -134,10 +134,11 @@ 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();
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()));
@ -162,8 +163,18 @@ public class PredictService {
}*/
private int calculateTeamForm(List<Match> matches, Team team, Team enemy, Date actualMatchDate) {
if (matches.size() == 0)
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));
return 100;
}
double shootsOnTargetAverage = 0;
double possessionAverage = 0;