diff --git a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java index 99b19f3..8571d6a 100644 --- a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java +++ b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java @@ -5,6 +5,8 @@ public class GenerationForm { private int min; private int max; private int base; + private int baseTendency; + private int tendencyDynamic; public int getTsLength() { return tsLength; @@ -38,13 +40,19 @@ public class GenerationForm { this.base = base; } - @Override - public String toString() { - return "GenerationForm{" + - "tsLength=" + tsLength + - ", min=" + min + - ", max=" + max + - ", base=" + base + - '}'; + public int getBaseTendency() { + return baseTendency; + } + + public void setBaseTendency(int baseTendency) { + this.baseTendency = baseTendency; + } + + public int getTendencyDynamic() { + return tendencyDynamic; + } + + public void setTendencyDynamic(int tendencyDynamic) { + this.tendencyDynamic = tendencyDynamic; } } diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java index 0a50824..43eb10d 100644 --- a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -1,18 +1,40 @@ package ru.ulstu.extractor.generation.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.ts.model.TimeSeriesType; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; 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 public class GenerationService { private final TimeSeriesService timeSeriesService; + private final BranchService branchService; - public GenerationService(TimeSeriesService timeSeriesService) { + public GenerationService(TimeSeriesService timeSeriesService, + BranchService branchService) { this.timeSeriesService = timeSeriesService; + this.branchService = branchService; } 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 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); + }); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java index 773e9e0..d998853 100644 --- a/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java +++ b/src/main/java/ru/ulstu/extractor/ts/util/DateUtils.java @@ -5,9 +5,16 @@ import java.util.Date; import java.util.GregorianCalendar; public class DateUtils { - public static Date addMonths(int amount) { + public static Date addDays(int amount) { Calendar c = GregorianCalendar.getInstance(); c.add(Calendar.DAY_OF_MONTH, amount); 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(); + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java b/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java index 61b0389..59fcd52 100644 --- a/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java +++ b/src/main/java/ru/ulstu/extractor/ts/util/Dummy.java @@ -6,10 +6,10 @@ import java.util.List; public class Dummy { public static List getDefaultTimeSeries (){ - return List.of(new TimeSeriesValue(DateUtils.addMonths(-5), 1.0), - new TimeSeriesValue(DateUtils.addMonths(-4), 2.0), - new TimeSeriesValue(DateUtils.addMonths(-3), 3.0), - new TimeSeriesValue(DateUtils.addMonths(-2), 4.0), - new TimeSeriesValue(DateUtils.addMonths(-1), 5.0)); + return List.of(new TimeSeriesValue(DateUtils.addDays(-5), 1.0), + new TimeSeriesValue(DateUtils.addDays(-4), 2.0), + new TimeSeriesValue(DateUtils.addDays(-3), 3.0), + new TimeSeriesValue(DateUtils.addDays(-2), 4.0), + new TimeSeriesValue(DateUtils.addDays(-1), 5.0)); } } diff --git a/src/main/resources/templates/generation.html b/src/main/resources/templates/generation.html index 4174f8b..f21f39d 100644 --- a/src/main/resources/templates/generation.html +++ b/src/main/resources/templates/generation.html @@ -40,6 +40,22 @@ +
+
+ Основная тенденция +
+
+ +
+
+
+
+ Динамика тенденции +
+
+ +
+