list of assessments #85

Merged
romanov73 merged 6 commits from 84-list-of-consequents into master 2023-02-02 13:05:28 +04:00
2 changed files with 10 additions and 2 deletions
Showing only changes of commit 36e2b09568 - Show all commits

View File

@ -19,6 +19,7 @@ import ru.ulstu.extractor.rule.model.DbRule;
import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeries;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -31,6 +32,7 @@ public class FuzzyInferenceService {
private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then " private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then "
+ OUTPUT_VARIABLE_NAME + OUTPUT_VARIABLE_NAME
+ " is %s"; + " is %s";
private final static String NO_RESULT = "Нет результата";
private final DbRuleService ruleService; private final DbRuleService ruleService;
private final AntecedentValueService antecedentValueService; private final AntecedentValueService antecedentValueService;
private final GitRepositoryService gitRepositoryService; private final GitRepositoryService gitRepositoryService;
@ -130,6 +132,9 @@ public class FuzzyInferenceService {
List<Integer> consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); List<Integer> consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList());
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues, consequentValues)); engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues, consequentValues));
String consequent = getConsequent(engine, variableValues); String consequent = getConsequent(engine, variableValues);
if (consequent.equals(NO_RESULT)) {
return new ArrayList<>();
}
return dbRules return dbRules
.stream() .stream()
.filter(r -> r.getId().equals(Integer.valueOf(consequent))) .filter(r -> r.getId().equals(Integer.valueOf(consequent)))
@ -173,7 +178,7 @@ public class FuzzyInferenceService {
outputVariable.defuzzify(); outputVariable.defuzzify();
} }
return (outputVariable == null || Double.isNaN(outputVariable.getValue())) return (outputVariable == null || Double.isNaN(outputVariable.getValue()))
? "Нет результата" ? NO_RESULT
: outputVariable.highestMembership(outputVariable.getValue()).getSecond().getName(); : outputVariable.highestMembership(outputVariable.getValue()).getSecond().getName();
} }
} }

View File

@ -34,7 +34,7 @@
<input type="hidden" th:field="*{branchId}"> <input type="hidden" th:field="*{branchId}">
</form> </form>
<div th:if="${assessments != null}"> <div th:if="${assessments != null && #lists.size(assessments) > 0}">
<h5>Состояние репозитория описывается следующими выражениями:</h5> <h5>Состояние репозитория описывается следующими выражениями:</h5>
<div th:each="assessment: ${assessments}"> <div th:each="assessment: ${assessments}">
<span th:text="${assessment.consequent}"></span> <span th:text="${assessment.consequent}"></span>
@ -44,5 +44,8 @@
th:text="${assessment.secondAntecedent.description}"></span>'; th:text="${assessment.secondAntecedent.description}"></span>';
</div> </div>
</div> </div>
<div th:if="${assessments != null && #lists.size(assessments) == 0}">
<h5>Нет результатов</h5>
</div>
</div> </div>
</html> </html>