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

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

View File

@ -5,6 +5,8 @@ public class GenerationForm {
private int min; private int min;
private int max; private int max;
private int base; private int base;
private int baseTendency;
private int tendencyDynamic;
public int getTsLength() { public int getTsLength() {
return tsLength; return tsLength;
@ -38,13 +40,19 @@ public class GenerationForm {
this.base = base; this.base = base;
} }
@Override public int getBaseTendency() {
public String toString() { return baseTendency;
return "GenerationForm{" + }
"tsLength=" + tsLength +
", min=" + min + public void setBaseTendency(int baseTendency) {
", max=" + max + this.baseTendency = baseTendency;
", base=" + base + }
'}';
public int getTendencyDynamic() {
return tendencyDynamic;
}
public void setTendencyDynamic(int tendencyDynamic) {
this.tendencyDynamic = tendencyDynamic;
} }
} }

View File

@ -1,18 +1,40 @@
package ru.ulstu.extractor.generation.service; package ru.ulstu.extractor.generation.service;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.ulstu.extractor.branch.model.Branch;
import ru.ulstu.extractor.branch.service.BranchService;
import ru.ulstu.extractor.generation.model.GenerationForm; import ru.ulstu.extractor.generation.model.GenerationForm;
import ru.ulstu.extractor.ts.model.TimeSeriesType;
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
import ru.ulstu.extractor.ts.service.TimeSeriesService; import ru.ulstu.extractor.ts.service.TimeSeriesService;
import ru.ulstu.extractor.ts.util.DateUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service @Service
public class GenerationService { public class GenerationService {
private final TimeSeriesService timeSeriesService; private final TimeSeriesService timeSeriesService;
private final BranchService branchService;
public GenerationService(TimeSeriesService timeSeriesService) { public GenerationService(TimeSeriesService timeSeriesService,
BranchService branchService) {
this.timeSeriesService = timeSeriesService; this.timeSeriesService = timeSeriesService;
this.branchService = branchService;
} }
public void generate(GenerationForm generationForm) { public void generate(GenerationForm generationForm) {
System.out.print(generationForm); Branch branch = branchService.findByBranchId(Branch.GENERATED_BRANCH_ID).orElseThrow();
Date startDate = DateUtils.addDays(-generationForm.getTsLength());
Arrays.stream(TimeSeriesType.values()).forEach(tsType -> {
List<TimeSeriesValue> tsValues = new ArrayList<>();
for (int i = 0; i < generationForm.getTsLength(); i++) {
tsValues.add(new TimeSeriesValue(DateUtils.addDays(startDate, i), (double) i));
}
final String tsName = "Генерированный " + tsType.getDescription();
timeSeriesService.save(tsName, branch, tsType, tsValues);
});
} }
} }

View File

@ -5,9 +5,16 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
public class DateUtils { public class DateUtils {
public static Date addMonths(int amount) { public static Date addDays(int amount) {
Calendar c = GregorianCalendar.getInstance(); Calendar c = GregorianCalendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, amount); c.add(Calendar.DAY_OF_MONTH, amount);
return c.getTime(); return c.getTime();
} }
public static Date addDays(Date startDate, int amount) {
Calendar c = GregorianCalendar.getInstance();
c.setTime(startDate);
c.add(Calendar.DAY_OF_MONTH, amount);
return c.getTime();
}
} }

View File

@ -6,10 +6,10 @@ import java.util.List;
public class Dummy { public class Dummy {
public static List<TimeSeriesValue> getDefaultTimeSeries (){ public static List<TimeSeriesValue> getDefaultTimeSeries (){
return List.of(new TimeSeriesValue(DateUtils.addMonths(-5), 1.0), return List.of(new TimeSeriesValue(DateUtils.addDays(-5), 1.0),
new TimeSeriesValue(DateUtils.addMonths(-4), 2.0), new TimeSeriesValue(DateUtils.addDays(-4), 2.0),
new TimeSeriesValue(DateUtils.addMonths(-3), 3.0), new TimeSeriesValue(DateUtils.addDays(-3), 3.0),
new TimeSeriesValue(DateUtils.addMonths(-2), 4.0), new TimeSeriesValue(DateUtils.addDays(-2), 4.0),
new TimeSeriesValue(DateUtils.addMonths(-1), 5.0)); new TimeSeriesValue(DateUtils.addDays(-1), 5.0));
} }
} }

View File

@ -40,6 +40,22 @@
<input type="text" class="form-control m-1" th:field="*{base}"> <input type="text" class="form-control m-1" th:field="*{base}">
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-4 col-sm-12">
Основная тенденция
</div>
<div class="col-md-6 col-sm-12">
<input type="text" class="form-control m-1" th:field="*{baseTendency}">
</div>
</div>
<div class="row">
<div class="col-md-4 col-sm-12">
Динамика тенденции
</div>
<div class="col-md-6 col-sm-12">
<input type="text" class="form-control m-1" th:field="*{tendencyDynamic}">
</div>
</div>
<div class="row"> <div class="row">
<div class="col-md-4 col-sm-12"> <div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-success form-control" value="Сгенерировать временные ряды"/> <input type="submit" class="btn btn-outline-success form-control" value="Сгенерировать временные ряды"/>