WIP: страницы для правил #62
@ -65,9 +65,10 @@ public class TimeSeriesMarkupController {
|
|||||||
);
|
);
|
||||||
MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss);
|
MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss);
|
||||||
model.addAttribute("markupForm", markupFormWithTs);
|
model.addAttribute("markupForm", markupFormWithTs);
|
||||||
// if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) {
|
if (markupForm.getTimeSeriesForMarkupList() != null
|
||||||
// markupService.saveMarkup(markupForm);
|
&& !markupForm.getTimeSeriesForMarkupList().isEmpty()) {
|
||||||
// }
|
markupService.generateRules(markupForm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "markup";
|
return "markup";
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package ru.ulstu.extractor.markup.model;
|
|
||||||
|
|
||||||
import ru.ulstu.extractor.core.BaseEntity;
|
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Markup extends BaseEntity {
|
|
||||||
@ManyToOne
|
|
||||||
private TimeSeries timeSeries;
|
|
||||||
private String markup;
|
|
||||||
|
|
||||||
public Markup() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Markup(TimeSeries timeSeries, String markup) {
|
|
||||||
this.timeSeries = timeSeries;
|
|
||||||
this.markup = markup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeSeries getTimeSeries() {
|
|
||||||
return timeSeries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeSeries(TimeSeries timeSeries) {
|
|
||||||
this.timeSeries = timeSeries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMarkup() {
|
|
||||||
return markup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMarkup(String markup) {
|
|
||||||
this.markup = markup;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +1,27 @@
|
|||||||
package ru.ulstu.extractor.markup.model;
|
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.TimeSeries;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.HashMap;
|
||||||
import java.util.TreeSet;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TimeSeriesForMarkup {
|
public class TimeSeriesForMarkup {
|
||||||
private Set<TimeSeries> timeSeriesSet = new TreeSet<>();
|
private Map<TimeSeries, AntecedentValue> timeSeriesTendencyMap = new HashMap<>();
|
||||||
|
private String markup;
|
||||||
private Date dateFrom;
|
private Date dateFrom;
|
||||||
private Date dateTo;
|
private Date dateTo;
|
||||||
|
|
||||||
public TimeSeriesForMarkup(TimeSeries ts1, TimeSeries ts2, 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.timeSeriesSet.add(ts1);
|
this.timeSeriesTendencyMap.put(ts1, tendency1);
|
||||||
this.timeSeriesSet.add(ts2);
|
this.timeSeriesTendencyMap.put(ts2, tendency2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<TimeSeries> getTimeSeriesSet() {
|
public Map<TimeSeries, AntecedentValue> getTimeSeriesTendencyMap() {
|
||||||
return timeSeriesSet;
|
return timeSeriesTendencyMap;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeSeriesSet(Set<TimeSeries> timeSeriesSet) {
|
|
||||||
this.timeSeriesSet = timeSeriesSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDateFrom() {
|
public Date getDateFrom() {
|
||||||
@ -41,4 +39,8 @@ public class TimeSeriesForMarkup {
|
|||||||
public void setDateTo(Date dateTo) {
|
public void setDateTo(Date dateTo) {
|
||||||
this.dateTo = dateTo;
|
this.dateTo = dateTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMarkup() {
|
||||||
|
return markup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package ru.ulstu.extractor.markup.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import ru.ulstu.extractor.markup.model.Markup;
|
|
||||||
|
|
||||||
public interface MarkupRepository extends JpaRepository<Markup, Integer> {
|
|
||||||
}
|
|
@ -1,39 +1,63 @@
|
|||||||
package ru.ulstu.extractor.markup.service;
|
package ru.ulstu.extractor.markup.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.extractor.markup.model.Markup;
|
import ru.ulstu.extractor.markup.model.MarkupForm;
|
||||||
import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup;
|
import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup;
|
||||||
import ru.ulstu.extractor.markup.repository.MarkupRepository;
|
import ru.ulstu.extractor.rule.model.AntecedentValue;
|
||||||
|
import ru.ulstu.extractor.rule.service.AntecedentValueService;
|
||||||
|
import ru.ulstu.extractor.rule.service.DbRuleService;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
import ru.ulstu.extractor.ts.model.TimeSeries;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
||||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
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;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MarkupService {
|
public class MarkupService {
|
||||||
private final MarkupRepository markupRepository;
|
private final DbRuleService dbRuleService;
|
||||||
private final TimeSeriesService timeSeriesService;
|
private final AntecedentValueService antecedentValueService;
|
||||||
|
|
||||||
public MarkupService(MarkupRepository markupRepository,
|
public MarkupService(DbRuleService dbRuleService,
|
||||||
TimeSeriesService timeSeriesService) {
|
AntecedentValueService antecedentValueService) {
|
||||||
this.markupRepository = markupRepository;
|
this.dbRuleService = dbRuleService;
|
||||||
this.timeSeriesService = timeSeriesService;
|
this.antecedentValueService = antecedentValueService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Transactional
|
@Transactional
|
||||||
public void saveMarkup(MarkupForm markupForm) {
|
public void generateRules(MarkupForm markupForm) {
|
||||||
markupForm.getMarkupRows().forEach(markupRow -> {
|
markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> {
|
||||||
TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId());
|
Set<Map.Entry<TimeSeries, AntecedentValue>> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet();
|
||||||
markupRepository.save(new Markup(timeSeries, markupRow.getMarkup()));
|
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(),
|
||||||
|
markupRow.getMarkup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}*/
|
|
||||||
|
|
||||||
public List<Markup> findAll() {
|
|
||||||
return markupRepository.findAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AntecedentValue getAntecedent(Double diff) {
|
||||||
|
String antecedentValue;
|
||||||
|
if (diff < 0) {
|
||||||
|
antecedentValue = "спад";
|
||||||
|
} else if (diff > 0) {
|
||||||
|
antecedentValue = "рост";
|
||||||
|
} else {
|
||||||
|
antecedentValue = "стабильно";
|
||||||
|
}
|
||||||
|
return antecedentValueService.getByValue(antecedentValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<TimeSeriesForMarkup> getTimeSeriesForMarkup(List<TimeSeries> timeSeriesList) {
|
public List<TimeSeriesForMarkup> getTimeSeriesForMarkup(List<TimeSeries> timeSeriesList) {
|
||||||
List<TimeSeriesForMarkup> tsForMarkup = new ArrayList<>();
|
List<TimeSeriesForMarkup> tsForMarkup = new ArrayList<>();
|
||||||
for (int i = 0; i < timeSeriesList.size(); i++) {
|
for (int i = 0; i < timeSeriesList.size(); i++) {
|
||||||
@ -52,17 +76,22 @@ public class MarkupService {
|
|||||||
.filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate()))
|
.filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate()))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
AntecedentValue antecedentValue1 = getAntecedent(values1.get(index + 1).getValue() - values1.get(index).getValue());
|
||||||
|
AntecedentValue antecedentValue2 = getAntecedent(values2.get(l + 1).getValue() - values2.get(l).getValue());
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index+1).getDate()));
|
tsForMarkup.add(new TimeSeriesForMarkup(ts1, antecedentValue1, ts2, antecedentValue2, values1.get(index).getDate(), values1.get(index + 1).getDate()));
|
||||||
} else {
|
} else {
|
||||||
found.getTimeSeriesSet().add(ts1);
|
found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1);
|
||||||
found.getTimeSeriesSet().add(ts2);
|
found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tsForMarkup;
|
return tsForMarkup
|
||||||
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(TimeSeriesForMarkup::getDateFrom))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
package ru.ulstu.extractor.rule.service;
|
package ru.ulstu.extractor.rule.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import ru.ulstu.extractor.markup.model.Markup;
|
|
||||||
import ru.ulstu.extractor.markup.service.MarkupService;
|
|
||||||
import ru.ulstu.extractor.rule.model.AddRuleForm;
|
import ru.ulstu.extractor.rule.model.AddRuleForm;
|
||||||
import ru.ulstu.extractor.rule.model.AntecedentValue;
|
import ru.ulstu.extractor.rule.model.AntecedentValue;
|
||||||
import ru.ulstu.extractor.rule.model.DbRule;
|
import ru.ulstu.extractor.rule.model.DbRule;
|
||||||
import ru.ulstu.extractor.rule.repository.RuleRepository;
|
import ru.ulstu.extractor.rule.repository.RuleRepository;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeriesType;
|
import ru.ulstu.extractor.ts.model.TimeSeriesType;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
|
||||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -19,15 +14,11 @@ import java.util.stream.Collectors;
|
|||||||
public class DbRuleService {
|
public class DbRuleService {
|
||||||
private final RuleRepository ruleRepository;
|
private final RuleRepository ruleRepository;
|
||||||
private final AntecedentValueService antecedentValueService;
|
private final AntecedentValueService antecedentValueService;
|
||||||
private final MarkupService markupService;
|
|
||||||
|
|
||||||
public DbRuleService(RuleRepository ruleRepository,
|
public DbRuleService(RuleRepository ruleRepository,
|
||||||
TimeSeriesService timeSeriesService,
|
AntecedentValueService antecedentValueService) {
|
||||||
AntecedentValueService antecedentValueService,
|
|
||||||
MarkupService markupService) {
|
|
||||||
this.ruleRepository = ruleRepository;
|
this.ruleRepository = ruleRepository;
|
||||||
this.antecedentValueService = antecedentValueService;
|
this.antecedentValueService = antecedentValueService;
|
||||||
this.markupService = markupService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DbRule> getList() {
|
public List<DbRule> getList() {
|
||||||
@ -52,6 +43,17 @@ public class DbRuleService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveRule(TimeSeriesType timeSeriesType1, AntecedentValue antecedentValue1,
|
||||||
|
TimeSeriesType timeSeriesType2, AntecedentValue antecedentValue2,
|
||||||
|
String consequent) {
|
||||||
|
ruleRepository.save(new DbRule(antecedentValueService.getById(antecedentValue1.getId()),
|
||||||
|
timeSeriesType1,
|
||||||
|
antecedentValueService.getById(antecedentValue2.getId()),
|
||||||
|
timeSeriesType2,
|
||||||
|
consequent));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DbRule findById(Integer id) {
|
public DbRule findById(Integer id) {
|
||||||
return ruleRepository.getOne(id);
|
return ruleRepository.getOne(id);
|
||||||
}
|
}
|
||||||
@ -71,40 +73,4 @@ public class DbRuleService {
|
|||||||
public List<String> getConsequentList() {
|
public List<String> getConsequentList() {
|
||||||
return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList());
|
return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void generateRulesFromMarkup() {
|
|
||||||
List<Markup> markups = markupService.findAll();
|
|
||||||
for (Markup markup1 : markups) {
|
|
||||||
for (Markup markup2 : markups) {
|
|
||||||
if (!markup1.equals(markup2)) {
|
|
||||||
List<TimeSeriesValue> values1 = markup1.getTimeSeries().getValues();
|
|
||||||
for (int i = 1; i < values1.size(); i++) {
|
|
||||||
List<TimeSeriesValue> values2 = markup2.getTimeSeries().getValues();
|
|
||||||
for (int j = 1; j < values2.size(); j++) {
|
|
||||||
ruleRepository.save(new DbRule(
|
|
||||||
getAntecedent(values1.get(i).getValue() - values1.get(i - 1).getValue()),
|
|
||||||
markup1.getTimeSeries().getTimeSeriesType(),
|
|
||||||
getAntecedent(values2.get(j).getValue() - values2.get(j - 1).getValue()),
|
|
||||||
markup2.getTimeSeries().getTimeSeriesType(),
|
|
||||||
"сгенерированный консеквент"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AntecedentValue getAntecedent(Double diff) {
|
|
||||||
String antecedentValue;
|
|
||||||
if (diff < 0) {
|
|
||||||
antecedentValue = "спад";
|
|
||||||
} else if (diff > 0) {
|
|
||||||
antecedentValue = "рост";
|
|
||||||
} else {
|
|
||||||
antecedentValue = "стабильно";
|
|
||||||
}
|
|
||||||
return antecedentValueService.getByValue(antecedentValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,9 @@
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
$('#select-branch').val([[*{branchId}]]);
|
$('#select-branch').val([[ * {branchId}]
|
||||||
|
])
|
||||||
|
;
|
||||||
$('#select-branch').selectpicker('refresh');
|
$('#select-branch').selectpicker('refresh');
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
@ -31,22 +33,15 @@
|
|||||||
value="Применить"/>
|
value="Применить"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-striped">
|
<h5 class="mb-3" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}">
|
||||||
<thead class="thead-dark">
|
Охарактеризуйте периоды вашего проекта</h5>
|
||||||
<tr>
|
<div class="form-group" th:each="m, itemStat: *{timeSeriesForMarkupList}">
|
||||||
<th scope="col" colspan="3">Охарактеризуйте периоды вашего проекта</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr th:each="m, itemStat: *{timeSeriesForMarkupList}">
|
|
||||||
<!-- <td><input type="hidden" th:field="*{markupRows[__${itemStat.index}__].timeSeries.id}"></span></td>-->
|
<!-- <td><input type="hidden" th:field="*{markupRows[__${itemStat.index}__].timeSeries.id}"></span></td>-->
|
||||||
<td><span class="badge badge-success" th:text="${m.dateFrom}"></span></td>
|
<label th:text="${#dates.format(m.dateFrom, 'dd.MM.yyyy HH:mm')} + ' - ' + ${#dates.format(m.dateTo, 'dd.MM.yyyy HH:mm')}"></label>
|
||||||
<td><span class="badge badge-success" th:text="${m.dateTo}"></span></td>
|
<textarea class="form-control"></textarea>
|
||||||
<td><input type="text" ></input></td>
|
</div>
|
||||||
</tr>
|
<input type="submit" th:if="*{timeSeriesForMarkupList != null && #lists.size(timeSeriesForMarkupList) > 0}"
|
||||||
</tbody>
|
class="btn btn-outline-success w-100" value="Сгенерировать правила"/>
|
||||||
</table>
|
|
||||||
<input type="submit" class="btn btn-outline-success w-100" value="Сохранить"/>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user