diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 6369e5f..7aeeff1 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -23,7 +23,9 @@ public class RuleController { private final AntecedentValueService antecedentValueService; private final TimeSeriesService timeSeriesService; - public RuleController(RuleService ruleService, AntecedentValueService antecedentValueService, TimeSeriesService timeSeriesService) { + public RuleController(RuleService ruleService, + AntecedentValueService antecedentValueService, + TimeSeriesService timeSeriesService) { this.ruleService = ruleService; this.antecedentValueService = antecedentValueService; this.timeSeriesService = timeSeriesService; @@ -38,7 +40,7 @@ public class RuleController { @GetMapping(ADD_RULE) public String getAntecedent(Model model) { model.addAttribute("antecedentValues", antecedentValueService.getList()); - model.addAttribute("antecedents", timeSeriesService.getAllTimeSeries()); + model.addAttribute("antecedents", timeSeriesService.getAllTimeSeriesTypes()); model.addAttribute("addRuleForm", new AddRuleForm()); return ADD_RULE; } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java index 1fd344e..3b64bdd 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AddRuleForm.java @@ -2,9 +2,9 @@ package ru.ulstu.extractor.rule.model; public class AddRuleForm { private Integer firstAntecedentValueId; - private Integer firstAntecedentId; + private String firstAntecedentId; private Integer secondAntecedentValueId; - private Integer secondAntecedentId; + private String secondAntecedentId; private String consequent; public AddRuleForm() { @@ -18,11 +18,11 @@ public class AddRuleForm { this.firstAntecedentValueId = firstAntecedentValueId; } - public Integer getFirstAntecedentId() { + public String getFirstAntecedentId() { return firstAntecedentId; } - public void setFirstAntecedentId(Integer firstAntecedentId) { + public void setFirstAntecedentId(String firstAntecedentId) { this.firstAntecedentId = firstAntecedentId; } @@ -34,11 +34,11 @@ public class AddRuleForm { this.secondAntecedentValueId = secondAntecedentValueId; } - public Integer getSecondAntecedentId() { + public String getSecondAntecedentId() { return secondAntecedentId; } - public void setSecondAntecedentId(Integer secondAntecedentId) { + public void setSecondAntecedentId(String secondAntecedentId) { this.secondAntecedentId = secondAntecedentId; } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/Rule.java b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java index e9efa92..73d015c 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/Rule.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/Rule.java @@ -1,9 +1,11 @@ package ru.ulstu.extractor.rule.model; import ru.ulstu.extractor.core.BaseEntity; -import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.ManyToOne; @Entity @@ -11,14 +13,14 @@ public class Rule extends BaseEntity { @ManyToOne private AntecedentValue firstAntecedentValue; - @ManyToOne - private TimeSeries firstAntecedent; + @Enumerated(EnumType.STRING) + private TimeSeriesType firstAntecedent; @ManyToOne private AntecedentValue secondAntecedentValue; - @ManyToOne - private TimeSeries secondAntecedent; + @Enumerated(EnumType.STRING) + private TimeSeriesType secondAntecedent; private String consequent; @@ -26,9 +28,9 @@ public class Rule extends BaseEntity { } public Rule(AntecedentValue firstAntecedentValue, - TimeSeries firstAntecedent, + TimeSeriesType firstAntecedent, AntecedentValue secondAntecedentValue, - TimeSeries secondAntecedent, + TimeSeriesType secondAntecedent, String consequent) { this.firstAntecedentValue = firstAntecedentValue; this.firstAntecedent = firstAntecedent; @@ -37,21 +39,6 @@ public class Rule extends BaseEntity { this.consequent = consequent; } - public Rule(Integer id, - Integer version, - AntecedentValue firstAntecedentValue, - TimeSeries firstAntecedent, - AntecedentValue secondAntecedentValue, - TimeSeries secondAntecedent, - String consequent) { - super(id, version); - this.firstAntecedentValue = firstAntecedentValue; - this.firstAntecedent = firstAntecedent; - this.secondAntecedentValue = secondAntecedentValue; - this.secondAntecedent = secondAntecedent; - this.consequent = consequent; - } - public AntecedentValue getFirstAntecedentValue() { return firstAntecedentValue; } @@ -60,11 +47,11 @@ public class Rule extends BaseEntity { this.firstAntecedentValue = firstAntecedentValue; } - public TimeSeries getFirstAntecedent() { + public TimeSeriesType getFirstAntecedent() { return firstAntecedent; } - public void setFirstAntecedent(TimeSeries firstAntecedent) { + public void setFirstAntecedent(TimeSeriesType firstAntecedent) { this.firstAntecedent = firstAntecedent; } @@ -76,11 +63,11 @@ public class Rule extends BaseEntity { this.secondAntecedentValue = secondAntecedentValue; } - public TimeSeries getSecondAntecedent() { + public TimeSeriesType getSecondAntecedent() { return secondAntecedent; } - public void setSecondAntecedent(TimeSeries secondAntecedent) { + public void setSecondAntecedent(TimeSeriesType secondAntecedent) { this.secondAntecedent = secondAntecedent; } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java index 46a95a6..63413b9 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/RuleService.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.rule.model.AddRuleForm; import ru.ulstu.extractor.rule.model.Rule; import ru.ulstu.extractor.rule.repository.RuleRepository; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.List; @@ -28,9 +29,9 @@ public class RuleService { public void saveRule(AddRuleForm addRuleForm) { ruleRepository.save(new Rule(antecedentValueService.getById(addRuleForm.getFirstAntecedentValueId()), - timeSeriesService.getById(addRuleForm.getFirstAntecedentId()), + TimeSeriesType.valueOf(addRuleForm.getFirstAntecedentId()), antecedentValueService.getById(addRuleForm.getSecondAntecedentValueId()), - timeSeriesService.getById(addRuleForm.getSecondAntecedentId()), + TimeSeriesType.valueOf(addRuleForm.getSecondAntecedentId()), addRuleForm.getConsequent())); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index c7da83c..9c79d0f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -20,6 +20,7 @@ import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; import javax.transaction.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -102,4 +103,8 @@ public class TimeSeriesService { return timeSeriesRepository.findById(tsId) .orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); } + + public List getAllTimeSeriesTypes() { + return Arrays.asList(TimeSeriesType.values()); + } } diff --git a/src/main/resources/db/changelog-20221012_170000-schema.xml b/src/main/resources/db/changelog-20221012_170000-schema.xml index 61b2f4f..765df26 100644 --- a/src/main/resources/db/changelog-20221012_170000-schema.xml +++ b/src/main/resources/db/changelog-20221012_170000-schema.xml @@ -49,4 +49,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/addRule.html b/src/main/resources/templates/addRule.html index 8c709d0..191e07a 100644 --- a/src/main/resources/templates/addRule.html +++ b/src/main/resources/templates/addRule.html @@ -12,6 +12,19 @@
Если
+
+ +
+
+ имеет тенденцию +
- и + имеет тенденцию
-
- временной ряд -
-
- -
то:
-
+
-
+
+
+
+
diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html index 93e139a..1f71b46 100644 --- a/src/main/resources/templates/listRules.html +++ b/src/main/resources/templates/listRules.html @@ -16,10 +16,10 @@ Если - + и - + то