#91 -- fix markup
This commit is contained in:
parent
07cd5abe9c
commit
d2f898d758
@ -2,22 +2,35 @@ package ru.ulstu.extractor.markup.model;
|
|||||||
|
|
||||||
import ru.ulstu.extractor.rule.model.AntecedentValue;
|
import ru.ulstu.extractor.rule.model.AntecedentValue;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
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.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TimeSeriesForMarkup {
|
public class TimeSeriesForMarkup {
|
||||||
|
//output
|
||||||
private Map<TimeSeries, AntecedentValue> timeSeriesTendencyMap = new HashMap<>();
|
private Map<TimeSeries, AntecedentValue> timeSeriesTendencyMap = new HashMap<>();
|
||||||
private String markup;
|
|
||||||
private Date dateFrom;
|
private Date dateFrom;
|
||||||
private Date dateTo;
|
private Date dateTo;
|
||||||
|
|
||||||
|
//input
|
||||||
|
private List<TimeSeriesType> timeSeriesTypes;
|
||||||
|
private List<AntecedentValue> antecedentValues;
|
||||||
|
private String markup;
|
||||||
|
|
||||||
|
public TimeSeriesForMarkup() {
|
||||||
|
}
|
||||||
|
|
||||||
public TimeSeriesForMarkup(TimeSeries ts1, AntecedentValue tendency1, TimeSeries ts2, AntecedentValue tendency2, Date dateFrom, Date dateTo) {
|
public TimeSeriesForMarkup(TimeSeries ts1, AntecedentValue tendency1, TimeSeries ts2, AntecedentValue tendency2, Date dateFrom, Date dateTo) {
|
||||||
this.dateFrom = dateFrom;
|
this.dateFrom = dateFrom;
|
||||||
this.dateTo = dateTo;
|
this.dateTo = dateTo;
|
||||||
this.timeSeriesTendencyMap.put(ts1, tendency1);
|
this.timeSeriesTendencyMap.put(ts1, tendency1);
|
||||||
this.timeSeriesTendencyMap.put(ts2, tendency2);
|
this.timeSeriesTendencyMap.put(ts2, tendency2);
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<TimeSeries, AntecedentValue> getTimeSeriesTendencyMap() {
|
public Map<TimeSeries, AntecedentValue> getTimeSeriesTendencyMap() {
|
||||||
@ -43,4 +56,33 @@ public class TimeSeriesForMarkup {
|
|||||||
public String getMarkup() {
|
public String getMarkup() {
|
||||||
return markup;
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTimeSeriesTendencyMap(Map<TimeSeries, AntecedentValue> timeSeriesTendencyMap) {
|
||||||
|
this.timeSeriesTendencyMap = timeSeriesTendencyMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkup(String markup) {
|
||||||
|
this.markup = markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TimeSeriesType> getTimeSeriesTypes() {
|
||||||
|
return timeSeriesTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeSeriesTypes(List<TimeSeriesType> timeSeriesTypes) {
|
||||||
|
this.timeSeriesTypes = timeSeriesTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AntecedentValue> getAntecedentValues() {
|
||||||
|
return antecedentValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAntecedentValues(List<AntecedentValue> antecedentValues) {
|
||||||
|
this.antecedentValues = antecedentValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
this.antecedentValues = new ArrayList<>(timeSeriesTendencyMap.values());
|
||||||
|
this.timeSeriesTypes = timeSeriesTendencyMap.keySet().stream().map(TimeSeries::getTimeSeriesType).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ import javax.transaction.Transactional;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -31,13 +29,11 @@ public class MarkupService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void generateRules(MarkupForm markupForm) {
|
public void generateRules(MarkupForm markupForm) {
|
||||||
markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> {
|
markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> {
|
||||||
Set<Map.Entry<TimeSeries, AntecedentValue>> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet();
|
for (int i = 0; i < markupRow.getTimeSeriesTypes().size(); i++) {
|
||||||
Set<Map.Entry<TimeSeries, AntecedentValue>> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet();
|
for (int j = i+1; j < markupRow.getTimeSeriesTypes().size(); j++) {
|
||||||
for (Map.Entry<TimeSeries, AntecedentValue> entry1 : timeSeriesEntry1) {
|
if (i != j) {
|
||||||
for (Map.Entry<TimeSeries, AntecedentValue> entry2 : timeSeriesEntry2) {
|
dbRuleService.saveRule(markupRow.getTimeSeriesTypes().get(i), markupRow.getAntecedentValues().get(i),
|
||||||
if (!entry1.equals(entry2)) {
|
markupRow.getTimeSeriesTypes().get(j), markupRow.getAntecedentValues().get(j),
|
||||||
dbRuleService.saveRule(entry1.getKey().getTimeSeriesType(), entry1.getValue(),
|
|
||||||
entry2.getKey().getTimeSeriesType(), entry2.getValue(),
|
|
||||||
markupRow.getMarkup());
|
markupRow.getMarkup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,6 +79,7 @@ public class MarkupService {
|
|||||||
} else {
|
} else {
|
||||||
found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1);
|
found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1);
|
||||||
found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2);
|
found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2);
|
||||||
|
found.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ public class DbRuleService {
|
|||||||
public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1,
|
public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1,
|
||||||
TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2,
|
TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2,
|
||||||
String consequent) {
|
String consequent) {
|
||||||
ruleRepository.save(new DbRule(antecedentValueService.getById(antecedentValue1.getId()),
|
ruleRepository.save(new DbRule(antecedentValueService.getByValue(antecedentValue1.getAntecedentValue()),
|
||||||
timeSeriesType1,
|
timeSeriesType1,
|
||||||
antecedentValueService.getById(antecedentValue2.getId()),
|
antecedentValueService.getByValue(antecedentValue2.getAntecedentValue()),
|
||||||
timeSeriesType2,
|
timeSeriesType2,
|
||||||
consequent));
|
consequent));
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import javax.persistence.ManyToOne;
|
|||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects;
|
import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects;
|
||||||
@ -55,8 +56,10 @@ public class TimeSeries extends BaseEntity {
|
|||||||
this.branch = branch;
|
this.branch = branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeSeries(JSONObject timeSeries) {
|
public TimeSeries(JSONObject timeSeries, Optional<TimeSeries> maybeTimeSeries) {
|
||||||
this.name = timeSeries.getString("name");
|
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"))
|
this.values = getListOfObjects(timeSeries.getJSONArray("values"))
|
||||||
.stream()
|
.stream()
|
||||||
.map(TimeSeriesValue::new)
|
.map(TimeSeriesValue::new)
|
||||||
|
@ -161,7 +161,7 @@ public class TimeSeriesService {
|
|||||||
LOG.debug("Send to group time series tendencies");
|
LOG.debug("Send to group time series tendencies");
|
||||||
return JsonUtils.getListOfObjects(response)
|
return JsonUtils.getListOfObjects(response)
|
||||||
.stream()
|
.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());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,14 @@
|
|||||||
<h5 class="mb-3" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}">
|
<h5 class="mb-3" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}">
|
||||||
Охарактеризуйте периоды вашего проекта</h5>
|
Охарактеризуйте периоды вашего проекта</h5>
|
||||||
<div class="form-group" th:each="m, itemStat: *{timeSeriesForMarkupList}">
|
<div class="form-group" th:each="m, itemStat: *{timeSeriesForMarkupList}">
|
||||||
<!-- <td><input type="hidden" th:field="*{markupRows[__${itemStat.index}__].timeSeries.id}"></span></td>-->
|
<div th:each="m2, itemStat2: *{timeSeriesForMarkupList[__${itemStat.index}__].timeSeriesTypes}">
|
||||||
|
<input type="hidden" th:field="*{timeSeriesForMarkupList[__${itemStat.index}__].timeSeriesTypes[__${itemStat2.index}__]}">
|
||||||
|
</div>
|
||||||
|
<div th:each="m3, itemStat3: *{timeSeriesForMarkupList[__${itemStat.index}__].antecedentValues}">
|
||||||
|
<input type="hidden" th:field="*{timeSeriesForMarkupList[__${itemStat.index}__].antecedentValues[__${itemStat3.index}__].antecedentValue}">
|
||||||
|
</div>
|
||||||
<label th:text="${#dates.format(m.dateFrom, 'dd.MM.yyyy HH:mm')} + ' - ' + ${#dates.format(m.dateTo, 'dd.MM.yyyy HH:mm')}"></label>
|
<label th:text="${#dates.format(m.dateFrom, 'dd.MM.yyyy HH:mm')} + ' - ' + ${#dates.format(m.dateTo, 'dd.MM.yyyy HH:mm')}"></label>
|
||||||
<textarea class="form-control"></textarea>
|
<textarea th:field="*{timeSeriesForMarkupList[__${itemStat.index}__].markup}" class="form-control"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}"
|
<input type="submit" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}"
|
||||||
class="btn btn-outline-success w-100" value="Сгенерировать правила"/>
|
class="btn btn-outline-success w-100" value="Сгенерировать правила"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user