WIP: страницы для правил #62

Closed
Ghost wants to merge 132 commits from master into 61-rules-pages
5 changed files with 115 additions and 51 deletions
Showing only changes of commit d111121e24 - Show all commits

View File

@ -8,14 +8,12 @@ import org.springframework.web.bind.annotation.PostMapping;
import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.branch.service.BranchService;
import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.core.Route;
import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.MarkupForm;
import ru.ulstu.extractor.markup.model.MarkupRow; import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup;
import ru.ulstu.extractor.markup.service.MarkupService; import ru.ulstu.extractor.markup.service.MarkupService;
import ru.ulstu.extractor.ts.model.TimeSeries;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Controller @Controller
@ApiIgnore @ApiIgnore
@ -34,18 +32,21 @@ public class TimeSeriesMarkupController {
@GetMapping("time-series-markup") @GetMapping("time-series-markup")
public String markupTs(Model model) { public String markupTs(Model model) {
model.addAttribute("branches", branchService.findAll()); model.addAttribute("branches", branchService.findAllValid());
model.addAttribute("markupForm", new MarkupForm()); model.addAttribute("markupForm", new MarkupForm());
return "markup"; return "markup";
} }
@PostMapping("time-series-markup") @PostMapping("time-series-markup")
public String filter(Model model, @ModelAttribute MarkupForm markupForm) { public String filter(Model model, @ModelAttribute MarkupForm markupForm) {
model.addAttribute("branches", branchService.findAll()); model.addAttribute("branches", branchService.findAllValid());
if (markupForm != null && markupForm.getBranchId() != null) { if (markupForm != null && markupForm.getBranchId() != null) {
List<TimeSeries> tss = timeSeriesService.getByBranch(markupForm.getBranchId()); List<TimeSeriesForMarkup> tss = markupService.getTimeSeriesForMarkup(
MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); timeSeriesService.getGroupedTendencies(
markupFormWithTs.setBranchId(markupForm.getBranchId()); timeSeriesService.getByBranch(markupForm.getBranchId())
)
);
MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss);
model.addAttribute("markupForm", markupFormWithTs); model.addAttribute("markupForm", markupFormWithTs);
} else { } else {
model.addAttribute("markupForm", new MarkupForm()); model.addAttribute("markupForm", new MarkupForm());
@ -55,15 +56,18 @@ public class TimeSeriesMarkupController {
@PostMapping(Route.ADD_MARKUP) @PostMapping(Route.ADD_MARKUP)
public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) {
model.addAttribute("branches", branchService.findAll()); model.addAttribute("branches", branchService.findAllValid());
if (markupForm.getBranchId() != null) { if (markupForm != null && markupForm.getBranchId() != null) {
List<TimeSeries> tss = timeSeriesService.getByBranch(markupForm.getBranchId()); List<TimeSeriesForMarkup> tss = markupService.getTimeSeriesForMarkup(
MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); timeSeriesService.getGroupedTendencies(
markupFormWithTs.setBranchId(markupForm.getBranchId()); timeSeriesService.getByBranch(markupForm.getBranchId())
)
);
MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss);
model.addAttribute("markupForm", markupFormWithTs); model.addAttribute("markupForm", markupFormWithTs);
if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { // if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) {
markupService.saveMarkup(markupForm); // markupService.saveMarkup(markupForm);
} // }
} }
return "markup"; return "markup";
} }

View File

@ -4,24 +4,23 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MarkupForm { public class MarkupForm {
private List<MarkupRow> markupRows = new ArrayList<>(); private List<TimeSeriesForMarkup> timeSeriesForMarkupList = new ArrayList<>();
private Integer branchId; private Integer branchId;
private boolean save;
private boolean filter;
public MarkupForm() { public MarkupForm() {
} }
public MarkupForm(List<MarkupRow> markupRows) { public MarkupForm(Integer branchId, List<TimeSeriesForMarkup> tss) {
this.markupRows = markupRows; this.timeSeriesForMarkupList = tss;
this.branchId = branchId;
} }
public List<MarkupRow> getMarkupRows() { public List<TimeSeriesForMarkup> getTimeSeriesForMarkupList() {
return markupRows; return timeSeriesForMarkupList;
} }
public void setMarkupRows(List<MarkupRow> markupRows) { public void setTimeSeriesForMarkupList(List<TimeSeriesForMarkup> timeSeriesForMarkupList) {
this.markupRows = markupRows; this.timeSeriesForMarkupList = timeSeriesForMarkupList;
} }
public Integer getBranchId() { public Integer getBranchId() {
@ -31,20 +30,4 @@ public class MarkupForm {
public void setBranchId(Integer branchId) { public void setBranchId(Integer branchId) {
this.branchId = branchId; this.branchId = branchId;
} }
public boolean isSave() {
return save;
}
public void setSave(boolean save) {
this.save = save;
}
public boolean isFilter() {
return filter;
}
public void setFilter(boolean filter) {
this.filter = filter;
}
} }

View File

@ -0,0 +1,44 @@
package ru.ulstu.extractor.markup.model;
import ru.ulstu.extractor.ts.model.TimeSeries;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;
public class TimeSeriesForMarkup {
private Set<TimeSeries> timeSeriesSet = new TreeSet<>();
private Date dateFrom;
private Date dateTo;
public TimeSeriesForMarkup(TimeSeries ts1, TimeSeries ts2, Date dateFrom, Date dateTo) {
this.dateFrom = dateFrom;
this.dateTo = dateTo;
this.timeSeriesSet.add(ts1);
this.timeSeriesSet.add(ts2);
}
public Set<TimeSeries> getTimeSeriesSet() {
return timeSeriesSet;
}
public void setTimeSeriesSet(Set<TimeSeries> timeSeriesSet) {
this.timeSeriesSet = timeSeriesSet;
}
public Date getDateFrom() {
return dateFrom;
}
public void setDateFrom(Date dateFrom) {
this.dateFrom = dateFrom;
}
public Date getDateTo() {
return dateTo;
}
public void setDateTo(Date dateTo) {
this.dateTo = dateTo;
}
}

View File

@ -1,13 +1,14 @@
package ru.ulstu.extractor.markup.service; package ru.ulstu.extractor.markup.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.model.Markup;
import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup;
import ru.ulstu.extractor.markup.repository.MarkupRepository; import ru.ulstu.extractor.markup.repository.MarkupRepository;
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.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
@ -21,15 +22,47 @@ public class MarkupService {
this.timeSeriesService = timeSeriesService; this.timeSeriesService = timeSeriesService;
} }
@Transactional /*@Transactional
public void saveMarkup(MarkupForm markupForm) { public void saveMarkup(MarkupForm markupForm) {
markupForm.getMarkupRows().forEach(markupRow -> { markupForm.getMarkupRows().forEach(markupRow -> {
TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId());
markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); markupRepository.save(new Markup(timeSeries, markupRow.getMarkup()));
}); });
} }*/
public List<Markup> findAll() { public List<Markup> findAll() {
return markupRepository.findAll(); return markupRepository.findAll();
} }
public List<TimeSeriesForMarkup> getTimeSeriesForMarkup(List<TimeSeries> timeSeriesList) {
List<TimeSeriesForMarkup> tsForMarkup = new ArrayList<>();
for (int i = 0; i < timeSeriesList.size(); i++) {
TimeSeries ts1 = timeSeriesList.get(i);
for (int j = i + 1; j < timeSeriesList.size(); j++) {
TimeSeries ts2 = timeSeriesList.get(j);
List<TimeSeriesValue> values1 = ts1.getValues();
for (int k = 0; k < values1.size() - 1; k++) {
List<TimeSeriesValue> values2 = ts2.getValues();
for (int l = 0; l < values2.size() - 1; l++) {
if (values1.get(k).getDate().equals(values2.get(l).getDate())
&& values1.get(k + 1).getDate().equals(values2.get(l + 1).getDate())) {
final int index = k;
TimeSeriesForMarkup found = tsForMarkup
.stream()
.filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate()))
.findAny()
.orElse(null);
if (found == null) {
tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index + 1).getDate()));
} else {
found.getTimeSeriesSet().add(ts1);
found.getTimeSeriesSet().add(ts2);
}
}
}
}
}
}
return tsForMarkup;
}
} }

View File

@ -36,15 +36,15 @@
<table class="table table-striped"> <table class="table table-striped">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col" colspan="3">Разметка временных рядов</th> <th scope="col" colspan="3">Охарактеризуйте периоды вашего проекта</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="m, itemStat: *{markupRows}"> <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" <td><span class="badge badge-success" th:text="${m.dateFrom}"></span></td>
th:text="*{markupRows[__${itemStat.index}__].timeSeries.name}"></span></td> <td><span class="badge badge-success" th:text="${m.dateTo}"></span></td>
<td><input type="text" th:field="*{markupRows[__${itemStat.index}__].markup}"></input></td> <td><input type="text"></input></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>