From 202d8cd0d372855a951e6e624ac66dfe6ac0ed6f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Feb 2025 10:40:47 +0400 Subject: [PATCH] #5 -- Fix validation --- .vscode/settings.json | 3 ++- .../ulstu/fc/rule/controller/RuleController.java | 1 - .../fc/rule/controller/VariableController.java | 9 ++++----- .../java/ru/ulstu/fc/rule/model/FuzzyTerm.java | 13 ++++++------- .../ru/ulstu/fc/rule/model/VariableForm.java | 16 ++++++++++++++++ .../fc/rule/service/FuzzyInferenceService.java | 12 ++++++------ 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c5f3f6b..0153b31 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.configuration.updateBuildConfiguration": "interactive" + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "disabled" } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java index 673e90a..284aa06 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -29,7 +29,6 @@ public class RuleController { (id != null && id != 0) ? new FuzzyRuleForm(id, ruleService.getById(id)) : new FuzzyRuleForm(id, projectId)); - return "rule/edit"; } diff --git a/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java b/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java index 8fdb9b9..b475ab3 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java @@ -25,11 +25,10 @@ public class VariableController { public String edit(@PathVariable(value = "projectId") Integer projectId, @PathVariable(value = "varId") Integer id, Model model) { model.addAttribute("projectId", projectId); - model.addAttribute("variableForm", - new VariableForm(id, (id != null && id != 0) - ? variableService.getById(id).getProject().getId() - : projectId)); - + model.addAttribute("variableForm", + (id != null && id != 0) + ? new VariableForm(id, variableService.getById(id)) + : new VariableForm(id, projectId)); return "var/edit"; } diff --git a/src/main/java/ru/ulstu/fc/rule/model/FuzzyTerm.java b/src/main/java/ru/ulstu/fc/rule/model/FuzzyTerm.java index 296a205..19c4308 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/FuzzyTerm.java +++ b/src/main/java/ru/ulstu/fc/rule/model/FuzzyTerm.java @@ -6,14 +6,14 @@ import ru.ulstu.fc.core.model.BaseEntity; @Entity public class FuzzyTerm extends BaseEntity { private String description; - private Double value; + private Double crispValue; public FuzzyTerm() { } public FuzzyTerm(String description, Double value) { this.description = description; - this.value = value; + this.crispValue = value; } public String getDescription() { @@ -24,12 +24,11 @@ public class FuzzyTerm extends BaseEntity { this.description = description; } - public Double getValue() { - return value; + public Double getCrispValue() { + return crispValue; } - public void setValue(Double value) { - this.value = value; + public void setCrispValue(Double crispValue) { + this.crispValue = crispValue; } - } diff --git a/src/main/java/ru/ulstu/fc/rule/model/VariableForm.java b/src/main/java/ru/ulstu/fc/rule/model/VariableForm.java index a8e5200..286c86e 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/VariableForm.java +++ b/src/main/java/ru/ulstu/fc/rule/model/VariableForm.java @@ -10,6 +10,8 @@ public class VariableForm { @Size(min = 3, max = 250, message = "Длина должна быть от 3 до 250") private String name; + private boolean isInput = true; + public VariableForm() { } @@ -18,6 +20,13 @@ public class VariableForm { this.projectId = projectId; } + public VariableForm(Integer id, Variable variable) { + this.id = id; + this.projectId = variable.getProject().getId(); + this.name = variable.getName(); + this.isInput = variable.isInput(); + } + public Integer getProjectId() { return projectId; } @@ -42,4 +51,11 @@ public class VariableForm { this.name = name; } + public boolean isInput() { + return isInput; + } + + public void setInput(boolean isInput) { + this.isInput = isInput; + } } diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java index 9b904cf..7aded59 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java @@ -45,15 +45,15 @@ public class FuzzyInferenceService { final InputVariable input = new InputVariable(); input.setName(variable.getName()); input.setDescription(""); - input.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getValue()); + input.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue()); input.setEnabled(true); input.setLockValueInRange(false); double prev = 0; for (int i = 0; i < variable.getFuzzyTerms().size(); i++) { Triangle term = new Triangle(variable.getFuzzyTerms().get(i).getDescription(), prev, - variable.getFuzzyTerms().get(i).getValue(), - variable.getFuzzyTerms().get(i).getValue() + variable.getFuzzyTerms().get(i).getValue() - prev); + variable.getFuzzyTerms().get(i).getCrispValue(), + variable.getFuzzyTerms().get(i).getCrispValue() + variable.getFuzzyTerms().get(i).getCrispValue() - prev); prev = term.getVertexB(); input.addTerm(term); } @@ -64,7 +64,7 @@ public class FuzzyInferenceService { final OutputVariable output = new OutputVariable(); output.setName(variable.getName()); output.setDescription(""); - output.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getValue()); + output.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue()); output.setEnabled(true); output.setAggregation(new Maximum()); output.setDefuzzifier(new WeightedAverage()); @@ -75,8 +75,8 @@ public class FuzzyInferenceService { Triangle term = new Triangle( variable.getFuzzyTerms().get(i).getDescription(), prev, - variable.getFuzzyTerms().get(i).getValue(), - variable.getFuzzyTerms().get(i).getValue() + variable.getFuzzyTerms().get(i).getValue() - prev); + variable.getFuzzyTerms().get(i).getCrispValue(), + variable.getFuzzyTerms().get(i).getCrispValue() + variable.getFuzzyTerms().get(i).getCrispValue() - prev); prev = term.getVertexB(); output.addTerm(term); }