#23 -- Show inference result
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m11s

This commit is contained in:
Anton Romanov 2025-03-04 14:17:36 +04:00
parent a3e59c6461
commit 83c9893efd
5 changed files with 55 additions and 4 deletions

View File

@ -34,15 +34,17 @@ public class ProjectRunController {
@GetMapping("init/{projectId}")
public String getProjects(@PathVariable(value = "projectId") Integer projectId, Model model) {
model.addAttribute("project", projectService.getById(projectId));
model.addAttribute("runProjectForm", new RunProjectForm());
model.addAttribute("runProjectForm", new RunProjectForm(projectId));
model.addAttribute("variables", projectVariableService.getInputByProjectId(projectId));
return "project/init";
}
@PostMapping("run")
public String run(RunProjectForm runProjectForm, Model model) {
model.addAttribute("projectId", runProjectForm.getProjectId());
model.addAttribute("response",
fuzzyInferenceService.getFuzzyInference(
fuzzyInferenceService.getProjectFuzzyInference(
runProjectForm.getProjectId(),
runProjectForm.getVariableValues()));
return "project/result";
}

View File

@ -1,10 +1,18 @@
package ru.ulstu.fc.project.model;
import java.util.HashMap;
import java.util.Map;
public class RunProjectForm {
private Integer projectId;
private Map<String, Double> variableValues;
private Map<String, Double> variableValues = new HashMap<>();
public RunProjectForm() {
}
public RunProjectForm(Integer projectId) {
this.projectId = projectId;
}
public Integer getProjectId() {
return projectId;

View File

@ -188,4 +188,18 @@ public class FuzzyInferenceService {
inputVariables,
outputVariables);
}
public List<OutputValue> getProjectFuzzyInference(Integer projectId, Map<String, Double> variableValues) {
List<String> fuzzyRules = projectRulesService.getByProjectId(projectId)
.stream()
.map(FuzzyRule::getContent)
.toList();
List<Variable> inputVariables = projectVariableService.getInputByProjectId(projectId);
List<Variable> outputVariables = projectVariableService.getOutputByProjectId(projectId);
return getFuzzyInference(fuzzyRules,
variableValues,
inputVariables,
outputVariables);
}
}

View File

@ -13,7 +13,8 @@
<input type="hidden" id="projectId" th:field="*{projectId}">
<div class="form-group" th:each="v : ${variables}">
<label th:text="${v.name}"> </label>
<select class='selectpicker inputVar m-2' data-live-search='true' data-width='70%'>
<select class='selectpicker inputVar m-2' data-live-search='true' data-width='70%'
th:field="*{variableValues[__${v.name}__]}">
<option th:each="t : ${v.fuzzyTerms}"
th:value="${t.crispValue}"
th:utext="${t.description}">

View File

@ -0,0 +1,26 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Результат</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script></script>
</head>
<div class="container" layout:fragment="content">
<h3>Результат нечеткого логического вывода:</h3>
<div class="row" th:each="out : ${response}" th:if="${not #lists.isEmpty(response)}">
<div class="col-md-2" th:text="${out.variable}"></div>
<div class="col-md-4" th:text="${out.fuzzyTerm}"></div>
<div class="col-md-3"> Степень принадлежности:</div>
<div class="col-md-1" th:text="${out.degree}"></div>
</div>
<div class="row" th:if="${response != null && #lists.isEmpty(response)}">
Нет результата
</div>
<div class="form-group">
<a th:href="@{'/runProject/init/' + ${projectId}}"
class="btn btn-outline-dark">Назад</a>
</div>
</div>
</html>