#91 -- fix markup

This commit is contained in:
Anton Romanov 2023-04-23 23:41:44 +04:00
parent 07cd5abe9c
commit d2f898d758
6 changed files with 63 additions and 16 deletions

View File

@ -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<TimeSeries, AntecedentValue> timeSeriesTendencyMap = new HashMap<>();
private String markup;
private Date dateFrom;
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) {
this.dateFrom = dateFrom;
this.dateTo = dateTo;
this.timeSeriesTendencyMap.put(ts1, tendency1);
this.timeSeriesTendencyMap.put(ts2, tendency2);
refresh();
}
public Map<TimeSeries, AntecedentValue> getTimeSeriesTendencyMap() {
@ -43,4 +56,33 @@ public class TimeSeriesForMarkup {
public String getMarkup() {
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());
}
}

View File

@ -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<Map.Entry<TimeSeries, AntecedentValue>> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet();
Set<Map.Entry<TimeSeries, AntecedentValue>> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet();
for (Map.Entry<TimeSeries, AntecedentValue> entry1 : timeSeriesEntry1) {
for (Map.Entry<TimeSeries, AntecedentValue> 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();
}
}
}

View File

@ -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));

View File

@ -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<TimeSeries> 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)

View File

@ -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());
}
}

View File

@ -34,9 +34,14 @@
<h5 class="mb-3" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}">
Охарактеризуйте периоды вашего проекта</h5>
<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>
<textarea class="form-control"></textarea>
<textarea th:field="*{timeSeriesForMarkupList[__${itemStat.index}__].markup}" class="form-control"></textarea>
</div>
<input type="submit" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}"
class="btn btn-outline-success w-100" value="Сгенерировать правила"/>