diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java index 9aaa903..3a48a57 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -2,22 +2,35 @@ package ru.ulstu.extractor.markup.model; import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class TimeSeriesForMarkup { + //output private Map timeSeriesTendencyMap = new HashMap<>(); - private String markup; private Date dateFrom; private Date dateTo; + //input + private List timeSeriesTypes; + private List antecedentValues; + private String markup; + + public TimeSeriesForMarkup() { + } + public TimeSeriesForMarkup(TimeSeries ts1, AntecedentValue tendency1, TimeSeries ts2, AntecedentValue tendency2, Date dateFrom, Date dateTo) { this.dateFrom = dateFrom; this.dateTo = dateTo; this.timeSeriesTendencyMap.put(ts1, tendency1); this.timeSeriesTendencyMap.put(ts2, tendency2); + refresh(); } public Map getTimeSeriesTendencyMap() { @@ -43,4 +56,33 @@ public class TimeSeriesForMarkup { public String getMarkup() { return markup; } + + public void setTimeSeriesTendencyMap(Map timeSeriesTendencyMap) { + this.timeSeriesTendencyMap = timeSeriesTendencyMap; + } + + public void setMarkup(String markup) { + this.markup = markup; + } + + public List getTimeSeriesTypes() { + return timeSeriesTypes; + } + + public void setTimeSeriesTypes(List timeSeriesTypes) { + this.timeSeriesTypes = timeSeriesTypes; + } + + public List getAntecedentValues() { + return antecedentValues; + } + + public void setAntecedentValues(List antecedentValues) { + this.antecedentValues = antecedentValues; + } + + public void refresh() { + this.antecedentValues = new ArrayList<>(timeSeriesTendencyMap.values()); + this.timeSeriesTypes = timeSeriesTendencyMap.keySet().stream().map(TimeSeries::getTimeSeriesType).collect(Collectors.toList()); + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 12ee087..5c4508d 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -13,8 +13,6 @@ import javax.transaction.Transactional; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; @Service @@ -31,13 +29,11 @@ public class MarkupService { @Transactional public void generateRules(MarkupForm markupForm) { markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> { - Set> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet(); - Set> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet(); - for (Map.Entry entry1 : timeSeriesEntry1) { - for (Map.Entry entry2 : timeSeriesEntry2) { - if (!entry1.equals(entry2)) { - dbRuleService.saveRule(entry1.getKey().getTimeSeriesType(), entry1.getValue(), - entry2.getKey().getTimeSeriesType(), entry2.getValue(), + for (int i = 0; i < markupRow.getTimeSeriesTypes().size(); i++) { + for (int j = i+1; j < markupRow.getTimeSeriesTypes().size(); j++) { + if (i != j) { + dbRuleService.saveRule(markupRow.getTimeSeriesTypes().get(i), markupRow.getAntecedentValues().get(i), + markupRow.getTimeSeriesTypes().get(j), markupRow.getAntecedentValues().get(j), markupRow.getMarkup()); } } @@ -83,6 +79,7 @@ public class MarkupService { } else { found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1); found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2); + found.refresh(); } } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index 44fe3cf..537ef59 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -46,9 +46,9 @@ public class DbRuleService { public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1, TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2, String consequent) { - ruleRepository.save(new DbRule(antecedentValueService.getById(antecedentValue1.getId()), + ruleRepository.save(new DbRule(antecedentValueService.getByValue(antecedentValue1.getAntecedentValue()), timeSeriesType1, - antecedentValueService.getById(antecedentValue2.getId()), + antecedentValueService.getByValue(antecedentValue2.getAntecedentValue()), timeSeriesType2, consequent)); diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index 34a2b4c..a7519ce 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -16,6 +16,7 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects; @@ -55,8 +56,10 @@ public class TimeSeries extends BaseEntity { this.branch = branch; } - public TimeSeries(JSONObject timeSeries) { + public TimeSeries(JSONObject timeSeries, Optional maybeTimeSeries) { this.name = timeSeries.getString("name"); + this.timeSeriesType = maybeTimeSeries.map(TimeSeries::getTimeSeriesType).orElse(null); + this.setId(maybeTimeSeries.map(TimeSeries::getId).orElse(null)); this.values = getListOfObjects(timeSeries.getJSONArray("values")) .stream() .map(TimeSeriesValue::new) 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 2279b0d..6dba38c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -161,7 +161,7 @@ public class TimeSeriesService { LOG.debug("Send to group time series tendencies"); return JsonUtils.getListOfObjects(response) .stream() - .map(TimeSeries::new) + .map(jsonTs -> new TimeSeries(jsonTs, tsList.stream().filter(ts -> jsonTs.get("name").equals("Model of " + ts.getName())).findAny())) .collect(Collectors.toList()); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 1009701..fa92dad 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -34,9 +34,14 @@
Охарактеризуйте периоды вашего проекта
- +
+ +
+
+ +
- +