From 4bd2f460467cbe85159ab8d095046e36fee91444 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 22:31:53 +0400 Subject: [PATCH 01/28] #91 -- Add markup page menu item --- src/main/resources/templates/default.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 45c036d..e7c1cec 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,8 +1,3 @@ - - @@ -37,6 +32,9 @@ + -- 2.34.1 From f08e5447fdf5ff571ad8ae822626c995d6c43329 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 22 Feb 2023 23:01:56 +0400 Subject: [PATCH 02/28] #91 -- Fix menu --- src/main/resources/templates/default.html | 6 +++--- src/main/resources/templates/listRepositories.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index e7c1cec..aa66144 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -33,13 +33,13 @@ Link diff --git a/src/main/resources/templates/listRepositories.html b/src/main/resources/templates/listRepositories.html index 8e07b46..ab2ff08 100644 --- a/src/main/resources/templates/listRepositories.html +++ b/src/main/resources/templates/listRepositories.html @@ -19,7 +19,7 @@ + th:text="${repo.name}" th:title="${repo.url}"> -- 2.34.1 From a701f943eb677fd2c2b13f4c4d36e445e180b647 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 25 Feb 2023 11:30:08 +0400 Subject: [PATCH 03/28] #91 -- Fix mvc config --- src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java index d4f9a9c..a85543c 100644 --- a/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/extractor/config/MvcConfiguration.java @@ -16,9 +16,7 @@ import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; public class MvcConfiguration implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/{articlename:\\w+}"); registry.addRedirectViewController("/", LIST_INDEXED_REPOSITORIES); - registry.addRedirectViewController("/default", "/home"); } @Override -- 2.34.1 From 41b23570c03a9878522bdcbaa3e97f7955085ef3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 25 Feb 2023 12:26:48 +0400 Subject: [PATCH 04/28] #91 -- Fix buttons --- .../resources/templates/listBranches.html | 29 ++++++++++--------- .../resources/templates/listRepositories.html | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/resources/templates/listBranches.html b/src/main/resources/templates/listBranches.html index a9cb074..db6d729 100644 --- a/src/main/resources/templates/listBranches.html +++ b/src/main/resources/templates/listBranches.html @@ -22,19 +22,22 @@ th:text="${branch.name}"> - - - - Индексируется... - - - - + diff --git a/src/main/resources/templates/listRepositories.html b/src/main/resources/templates/listRepositories.html index ab2ff08..8c9289b 100644 --- a/src/main/resources/templates/listRepositories.html +++ b/src/main/resources/templates/listRepositories.html @@ -21,7 +21,7 @@ - -- 2.34.1 From f4600c2ba5d144ca3b7de486fa780f86016df3a0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 27 Feb 2023 14:47:51 +0400 Subject: [PATCH 05/28] #91 -- Group ts tendencies --- .../controller/TimeSeriesMarkupController.java | 1 + .../ulstu/extractor/ts/model/TimeSeries.java | 12 ++++++++++++ .../extractor/ts/model/TimeSeriesValue.java | 13 +++++++++++++ .../ts/service/TimeSeriesService.java | 13 +++++++++++++ .../ru/ulstu/extractor/util/JsonUtils.java | 18 ++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 src/main/java/ru/ulstu/extractor/util/JsonUtils.java diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java index 5caad5c..32674c5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java @@ -22,6 +22,7 @@ public class TimeSeriesMarkupController { public String markupTs(Model model) { List ts = timeSeriesService.getAllTimeSeries(); model.addAttribute("ts", ts); + model.addAttribute("fts", timeSeriesService.getGroupedTendencies(ts.get(0))); return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index 76abf70..34a2b4c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -2,6 +2,7 @@ package ru.ulstu.extractor.ts.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.json.JSONObject; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.core.BaseEntity; @@ -15,6 +16,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.util.JsonUtils.getListOfObjects; @Entity public class TimeSeries extends BaseEntity { @@ -51,6 +55,14 @@ public class TimeSeries extends BaseEntity { this.branch = branch; } + public TimeSeries(JSONObject timeSeries) { + this.name = timeSeries.getString("name"); + this.values = getListOfObjects(timeSeries.getJSONArray("values")) + .stream() + .map(TimeSeriesValue::new) + .collect(Collectors.toList()); + } + public String getName() { return name; } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java index 9b77f2a..e9ac965 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java @@ -1,8 +1,11 @@ package ru.ulstu.extractor.ts.model; +import org.json.JSONObject; import ru.ulstu.extractor.core.BaseEntity; import javax.persistence.Entity; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; @Entity @@ -28,6 +31,16 @@ public class TimeSeriesValue extends BaseEntity { this.value = value; } + public TimeSeriesValue(JSONObject jsonValue) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); + try { + this.date = formatter.parse(jsonValue.getString("date")); + } catch (ParseException e) { + e.printStackTrace(); + } + this.value = jsonValue.getDouble("value"); + } + public Date getDate() { return date; } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index d5e12e6..1cdf4cc 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -36,6 +36,7 @@ public class TimeSeriesService { private final HttpService httpService; private final static String TIME_SERIES_SAVE_SERVICE_URL = "http://time-series.athene.tech/api/1.0/add-time-series?setKey=git-extractor"; private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getSpecificMethodSmoothed"; + private final static String TIME_SERIES_GROUPED_TENDENCIES_URL = "http://time-series.athene.tech/api/1.0/getGroupedTendencies"; public TimeSeriesService(TimeSeriesRepository timeSeriesRepository, TimeSeriesValueRepository timeSeriesValueRepository, @@ -136,4 +137,16 @@ public class TimeSeriesService { } return Optional.empty(); } + + public Optional getGroupedTendencies(TimeSeries ts) { + if (ts != null && ts.getValues().size() > 5) { + JSONObject response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONObject(new JsonTimeSeries(ts))); + LOG.debug("Send to group time series tendencies"); + if (response.has("response") && response.getString("response").equals("empty")) { + return Optional.empty(); + } + return Optional.of(new TimeSeries(response)); + } + return Optional.empty(); + } } diff --git a/src/main/java/ru/ulstu/extractor/util/JsonUtils.java b/src/main/java/ru/ulstu/extractor/util/JsonUtils.java new file mode 100644 index 0000000..6ac8927 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/util/JsonUtils.java @@ -0,0 +1,18 @@ +package ru.ulstu.extractor.util; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class JsonUtils { + + public static List getListOfObjects(JSONArray jsonArray) { + List result = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + result.add(jsonArray.getJSONObject(i)); + } + return result; + } +} -- 2.34.1 From 704366f11ada7b4bf027e18e56b1390f9db1dac9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 27 Feb 2023 23:35:31 +0400 Subject: [PATCH 06/28] #91 -- Group list of ts tendencies --- .../ru/ulstu/extractor/http/HttpService.java | 20 +++++++++++++++++++ .../TimeSeriesMarkupController.java | 2 +- .../ts/service/TimeSeriesService.java | 19 +++++++++--------- src/main/resources/templates/markup.html | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 1e53488..97dd0df 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -41,6 +41,26 @@ public class HttpService { return response; } + public JSONArray post(String url, JSONArray postData) { + log.debug("Service call: {}", url); + JSONArray response = null; + try { + response = new JSONArray(Optional.ofNullable(client + .post() + .uri(url) + .contentType(MediaType.APPLICATION_JSON) + .body(BodyInserters.fromValue(postData.toString())) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(String.class) + .toFuture().get()).orElse("[{response:\"empty\"}]")); + } catch (Exception e) { + return new JSONArray("[{response:\"empty\"}]"); + } + log.debug("Service response: {}", response); + return response; + } + public JSONArray get(String url) { log.debug("Service call: {}", url); try { diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java index 32674c5..fbe7493 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java @@ -22,7 +22,7 @@ public class TimeSeriesMarkupController { public String markupTs(Model model) { List ts = timeSeriesService.getAllTimeSeries(); model.addAttribute("ts", ts); - model.addAttribute("fts", timeSeriesService.getGroupedTendencies(ts.get(0))); + model.addAttribute("groupedTs", timeSeriesService.getGroupedTendencies(ts)); return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 1cdf4cc..dac66fe 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -20,12 +20,14 @@ import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.repository.TimeSeriesRepository; import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository; import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper; +import ru.ulstu.extractor.util.JsonUtils; import javax.transaction.Transactional; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service public class TimeSeriesService { @@ -138,15 +140,12 @@ public class TimeSeriesService { return Optional.empty(); } - public Optional getGroupedTendencies(TimeSeries ts) { - if (ts != null && ts.getValues().size() > 5) { - JSONObject response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONObject(new JsonTimeSeries(ts))); - LOG.debug("Send to group time series tendencies"); - if (response.has("response") && response.getString("response").equals("empty")) { - return Optional.empty(); - } - return Optional.of(new TimeSeries(response)); - } - return Optional.empty(); + public List getGroupedTendencies(List tsList) { + JSONArray response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONArray(tsList.stream().map(JsonTimeSeries::new).collect(Collectors.toList()))); + LOG.debug("Send to group time series tendencies"); + return JsonUtils.getListOfObjects(response) + .stream() + .map(TimeSeries::new) + .collect(Collectors.toList()); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 329d010..533e30a 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -14,7 +14,7 @@ - + -- 2.34.1 From ed68fa47f7a0c686836f438f8bd1d4ddeff55af0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 2 Mar 2023 21:02:10 +0400 Subject: [PATCH 07/28] #91 -- Add markup table --- .../TimeSeriesMarkupController.java | 2 +- .../ulstu/extractor/markup/model/Markup.java | 30 +++++++++++++++++++ .../db/changelog-20230302_210000-schema.xml | 23 ++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) rename src/main/java/ru/ulstu/extractor/{ts => markup}/controller/TimeSeriesMarkupController.java (95%) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/Markup.java create mode 100644 src/main/resources/db/changelog-20230302_210000-schema.xml diff --git a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java similarity index 95% rename from src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java rename to src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index fbe7493..d9571a8 100644 --- a/src/main/java/ru/ulstu/extractor/ts/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.controller; +package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java new file mode 100644 index 0000000..84c6d80 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -0,0 +1,30 @@ +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 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; + } +} \ No newline at end of file diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml new file mode 100644 index 0000000..7ccb661 --- /dev/null +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index dfde9f7..aa59e26 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -15,4 +15,5 @@ + -- 2.34.1 From 0883c5193bb35934a2090de0154a0e8b694dc3fc Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 2 Mar 2023 22:03:29 +0400 Subject: [PATCH 08/28] #91 -- Add dtos --- .../java/ru/ulstu/extractor/core/Route.java | 5 ++++ .../TimeSeriesMarkupController.java | 15 ++++++++-- .../extractor/markup/model/MarkupForm.java | 15 ++++++++++ .../extractor/markup/model/MarkupRow.java | 28 +++++++++++++++++++ src/main/resources/templates/markup.html | 28 ++++++++++--------- 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index be9cb53..e1605e7 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -21,6 +21,7 @@ public class Route { public static final String ADD_RULE = "addRule"; public static final String ASSESSMENTS = "assessments"; public static final String DELETE_RULE = "deleteRule"; + public static final String ADD_MARKUP = "addMarkup"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; @@ -45,4 +46,8 @@ public class Route { public static String getASSESSMENTS() { return ASSESSMENTS; } + + public static String getADD_MARKUP() { + return ADD_MARKUP; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index d9571a8..c816987 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -3,11 +3,16 @@ package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import ru.ulstu.extractor.markup.model.MarkupForm; +import ru.ulstu.extractor.markup.model.MarkupRow; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; +import java.util.stream.Collectors; @Controller @ApiIgnore @@ -20,9 +25,13 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - List ts = timeSeriesService.getAllTimeSeries(); - model.addAttribute("ts", ts); - model.addAttribute("groupedTs", timeSeriesService.getGroupedTendencies(ts)); + List tss = timeSeriesService.getAllTimeSeries(); + model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).collect(Collectors.toList()))); + return "markup"; + } + + @PostMapping("addMarkups") + public String addMarkups(@RequestBody MarkupForm markupForm) { return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java new file mode 100644 index 0000000..987103a --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -0,0 +1,15 @@ +package ru.ulstu.extractor.markup.model; + +import java.util.List; + +public class MarkupForm { + private List markupRows; + + public MarkupForm(List markupRows) { + this.markupRows = markupRows; + } + + public List getMarkupRows() { + return markupRows; + } +} diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java new file mode 100644 index 0000000..f62640e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java @@ -0,0 +1,28 @@ +package ru.ulstu.extractor.markup.model; + +import ru.ulstu.extractor.ts.model.TimeSeries; + +public class MarkupRow { + private TimeSeries timeSeries; + private String markup; + + public MarkupRow(TimeSeries ts) { + this.timeSeries = ts; + } + + 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; + } +} diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 533e30a..3579887 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,18 +7,20 @@
- - - - - - - - - - - - -
Разметка временных рядов
+
+ + + + + + + + + + + + +
Разметка временных рядов
+
-- 2.34.1 From 0239b0afd479e8f59ba4b704dd369c04fdb36ff9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 3 Mar 2023 10:44:26 +0400 Subject: [PATCH 09/28] #91 -- Add save operation --- .../TimeSeriesMarkupController.java | 14 ++++++++++---- .../ulstu/extractor/markup/model/Markup.java | 8 ++++++++ .../extractor/markup/model/MarkupForm.java | 4 ++++ .../markup/repository/MarkupRepository.java | 7 +++++++ .../markup/service/MarkupService.java | 19 +++++++++++++++++++ src/main/resources/templates/markup.html | 3 ++- 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java create mode 100644 src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index c816987..9eeab36 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -3,10 +3,12 @@ package ru.ulstu.extractor.markup.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.MarkupRow; +import ru.ulstu.extractor.markup.service.MarkupService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; @@ -18,9 +20,12 @@ import java.util.stream.Collectors; @ApiIgnore public class TimeSeriesMarkupController { private final TimeSeriesService timeSeriesService; + private final MarkupService markupService; - public TimeSeriesMarkupController(TimeSeriesService timeSeriesService) { + public TimeSeriesMarkupController(TimeSeriesService timeSeriesService, + MarkupService markupService) { this.timeSeriesService = timeSeriesService; + this.markupService = markupService; } @GetMapping("time-series-markup") @@ -30,8 +35,9 @@ public class TimeSeriesMarkupController { return "markup"; } - @PostMapping("addMarkups") - public String addMarkups(@RequestBody MarkupForm markupForm) { + @PostMapping(Route.ADD_MARKUP) + public String addMarkups(@ModelAttribute MarkupForm markupForm) { + markupService.saveMarkup(markupForm); return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java index 84c6d80..0117bc8 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -12,6 +12,14 @@ public class Markup extends BaseEntity { private TimeSeries timeSeries; private String markup; + public Markup() { + } + + public Markup(MarkupRow markupRow) { + this.timeSeries = markupRow.getTimeSeries(); + this.markup = markupRow.getMarkup(); + } + public TimeSeries getTimeSeries() { return timeSeries; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index 987103a..e197b6b 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -12,4 +12,8 @@ public class MarkupForm { public List getMarkupRows() { return markupRows; } + + public void setMarkupRows(List markupRows) { + this.markupRows = markupRows; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java new file mode 100644 index 0000000..0d149f1 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java @@ -0,0 +1,7 @@ +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 { +} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java new file mode 100644 index 0000000..266240c --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -0,0 +1,19 @@ +package ru.ulstu.extractor.markup.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.repository.MarkupRepository; + +@Service +public class MarkupService { + private final MarkupRepository markupRepository; + + public MarkupService(MarkupRepository markupRepository) { + this.markupRepository = markupRepository; + } + + public void saveMarkup(MarkupForm markupForm) { + markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow))); + } +} diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 3579887..6417ba2 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,7 +7,7 @@
-
+ @@ -21,6 +21,7 @@
+
-- 2.34.1 From 211a8b004c8d1cf47cd63ba30904e12cc75838fa Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 3 Mar 2023 11:10:35 +0400 Subject: [PATCH 10/28] #91 -- Add get markups form --- .../ulstu/extractor/GitExtractorApplication.java | 1 - .../controller/TimeSeriesMarkupController.java | 2 +- .../ulstu/extractor/markup/model/MarkupForm.java | 6 +++++- .../ru/ulstu/extractor/markup/model/MarkupRow.java | 3 +++ src/main/resources/templates/markup.html | 14 ++++++++------ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 1cf7928..8491e6c 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -26,5 +26,4 @@ public class GitExtractorApplication { public void doSomethingAfterStartup() { indexService.indexFailedBranchesOnStart(); } - } diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 9eeab36..0c1600c 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -31,7 +31,7 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { List tss = timeSeriesService.getAllTimeSeries(); - model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).collect(Collectors.toList()))); + model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()))); return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index e197b6b..b81a110 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -1,9 +1,13 @@ package ru.ulstu.extractor.markup.model; +import java.util.ArrayList; import java.util.List; public class MarkupForm { - private List markupRows; + private List markupRows = new ArrayList<>(); + + public MarkupForm() { + } public MarkupForm(List markupRows) { this.markupRows = markupRows; diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java index f62640e..3989a6f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupRow.java @@ -6,6 +6,9 @@ public class MarkupRow { private TimeSeries timeSeries; private String markup; + public MarkupRow() { + } + public MarkupRow(TimeSeries ts) { this.timeSeries = ts; } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 6417ba2..b2b1d4e 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -7,21 +7,23 @@
-
+ - + - - - + + + +
Разметка временных рядовРазметка временных рядов
- +
-- 2.34.1 From d7790dff700c3e0a1c1ff96ac03f0f1e51365c63 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 7 Mar 2023 16:59:17 +0400 Subject: [PATCH 11/28] #91 -- Save markup --- .../TimeSeriesMarkupController.java | 35 ++++++++++++++++--- .../ulstu/extractor/markup/model/Markup.java | 6 ++-- .../extractor/markup/model/MarkupForm.java | 27 ++++++++++++++ .../markup/service/MarkupService.java | 14 ++++++-- src/main/resources/templates/markup.html | 25 +++++++++++++ 5 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 0c1600c..0672544 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -5,6 +5,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; +import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.core.Route; import ru.ulstu.extractor.markup.model.MarkupForm; import ru.ulstu.extractor.markup.model.MarkupRow; @@ -20,24 +21,50 @@ import java.util.stream.Collectors; @ApiIgnore public class TimeSeriesMarkupController { private final TimeSeriesService timeSeriesService; + private final BranchService branchService; private final MarkupService markupService; public TimeSeriesMarkupController(TimeSeriesService timeSeriesService, + BranchService branchService, MarkupService markupService) { this.timeSeriesService = timeSeriesService; + this.branchService = branchService; this.markupService = markupService; } @GetMapping("time-series-markup") public String markupTs(Model model) { - List tss = timeSeriesService.getAllTimeSeries(); - model.addAttribute("markupForm", new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList()))); + model.addAttribute("branches", branchService.findAll()); + model.addAttribute("markupForm", new MarkupForm()); + return "markup"; + } + + @PostMapping("time-series-markup") + public String filter(Model model, @ModelAttribute MarkupForm markupForm) { + model.addAttribute("branches", branchService.findAll()); + if (markupForm != null && markupForm.getBranchId() != null) { + List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); + MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); + markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("markupForm", markupFormWithTs); + } else { + model.addAttribute("markupForm", new MarkupForm()); + } return "markup"; } @PostMapping(Route.ADD_MARKUP) - public String addMarkups(@ModelAttribute MarkupForm markupForm) { - markupService.saveMarkup(markupForm); + public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { + model.addAttribute("branches", branchService.findAll()); + if (markupForm.getBranchId() != null) { + List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); + MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); + markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("markupForm", markupFormWithTs); + if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { + markupService.saveMarkup(markupForm); + } + } return "markup"; } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java index 0117bc8..f119e41 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java @@ -15,9 +15,9 @@ public class Markup extends BaseEntity { public Markup() { } - public Markup(MarkupRow markupRow) { - this.timeSeries = markupRow.getTimeSeries(); - this.markup = markupRow.getMarkup(); + public Markup(TimeSeries timeSeries, String markup) { + this.timeSeries = timeSeries; + this.markup = markup; } public TimeSeries getTimeSeries() { diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index b81a110..c07c837 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -5,6 +5,9 @@ import java.util.List; public class MarkupForm { private List markupRows = new ArrayList<>(); + private Integer branchId; + private boolean save; + private boolean filter; public MarkupForm() { } @@ -20,4 +23,28 @@ public class MarkupForm { public void setMarkupRows(List markupRows) { this.markupRows = markupRows; } + + public Integer getBranchId() { + return branchId; + } + + public void setBranchId(Integer 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; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 266240c..ae3e35f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,19 +1,29 @@ package ru.ulstu.extractor.markup.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.MarkupForm; import ru.ulstu.extractor.markup.repository.MarkupRepository; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.service.TimeSeriesService; @Service public class MarkupService { private final MarkupRepository markupRepository; + private final TimeSeriesService timeSeriesService; - public MarkupService(MarkupRepository markupRepository) { + public MarkupService(MarkupRepository markupRepository, + TimeSeriesService timeSeriesService) { this.markupRepository = markupRepository; + this.timeSeriesService = timeSeriesService; } + @Transactional public void saveMarkup(MarkupForm markupForm) { - markupForm.getMarkupRows().forEach(markupRow -> markupRepository.save(new Markup(markupRow))); + markupForm.getMarkupRows().forEach(markupRow -> { + TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); + markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); + }); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index b2b1d4e..c0c98a7 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -8,6 +8,31 @@
+
+
+ Репозиторий-ветка +
+
+ + +
+
+ +
+
-- 2.34.1 From 71652c7b79225bcef75d5fa5c7433334a3c1c8c9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 11 Mar 2023 00:55:43 +0400 Subject: [PATCH 12/28] #91 -- Add some rule generator --- .../extractor/GitExtractorApplication.java | 6 ++- .../assessment/service/AssessmentService.java | 3 +- .../markup/service/MarkupService.java | 6 +++ .../extractor/rule/model/AntecedentValue.java | 3 +- .../repository/AntecedentValueRepository.java | 3 ++ .../rule/service/AntecedentValueService.java | 5 ++ .../extractor/rule/service/DbRuleService.java | 48 +++++++++++++++++-- 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 8491e6c..95e1008 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -7,15 +7,18 @@ import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import ru.ulstu.extractor.gitrepository.service.IndexService; +import ru.ulstu.extractor.rule.service.DbRuleService; @SpringBootApplication @EnableScheduling @EnableAsync public class GitExtractorApplication { private final IndexService indexService; + private final DbRuleService dbRuleService; - public GitExtractorApplication(IndexService indexService) { + public GitExtractorApplication(IndexService indexService, DbRuleService dbRuleService) { this.indexService = indexService; + this.dbRuleService = dbRuleService; } public static void main(String[] args) { @@ -25,5 +28,6 @@ public class GitExtractorApplication { @EventListener(ApplicationReadyEvent.class) public void doSomethingAfterStartup() { indexService.indexFailedBranchesOnStart(); + //dbRuleService.generateRulesFromMarkup(); } } diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index d221806..2514e6a 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -71,8 +71,9 @@ public class AssessmentService { Map variableValues = new HashMap<>(); timeSeries .stream() - .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() + .filter(ts -> (ts.getTimeSeriesType() == dbRule.getFirstAntecedent() || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) + && ts.getValues().size() > 0) .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService .getLastTimeSeriesTendency(ts) .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index ae3e35f..c4d3fd3 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -8,6 +8,8 @@ import ru.ulstu.extractor.markup.repository.MarkupRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import java.util.List; + @Service public class MarkupService { private final MarkupRepository markupRepository; @@ -26,4 +28,8 @@ public class MarkupService { markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); }); } + + public List findAll() { + return markupRepository.findAll(); + } } diff --git a/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java index 3583e6a..39b5eb6 100644 --- a/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java +++ b/src/main/java/ru/ulstu/extractor/rule/model/AntecedentValue.java @@ -11,8 +11,7 @@ public class AntecedentValue extends BaseEntity { public AntecedentValue() { } - public AntecedentValue(Integer id, String antecedentValue) { - this.setId(id); + public AntecedentValue(String antecedentValue) { this.antecedentValue = antecedentValue; } diff --git a/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java index 1ea84d7..3ae5795 100644 --- a/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java +++ b/src/main/java/ru/ulstu/extractor/rule/repository/AntecedentValueRepository.java @@ -4,5 +4,8 @@ package ru.ulstu.extractor.rule.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.extractor.rule.model.AntecedentValue; +import java.util.Optional; + public interface AntecedentValueRepository extends JpaRepository { + Optional findByAntecedentValue(String antecedentValue); } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java index ef3c124..8de502a 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/AntecedentValueService.java @@ -22,4 +22,9 @@ public class AntecedentValueService { return antecedentValueRepository.findById(antecedentValueId) .orElseThrow(() -> new RuntimeException("Antecedent value not found by id " + antecedentValueId)); } + + public AntecedentValue getByValue(String antecedentValue) { + return antecedentValueRepository.findByAntecedentValue(antecedentValue) + .orElseThrow(() -> new RuntimeException("Antecedent value not found by value " + antecedentValue)); + } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index 198d486..c0a2dc5 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -1,10 +1,15 @@ package ru.ulstu.extractor.rule.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.AntecedentValue; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.repository.RuleRepository; 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; @@ -13,15 +18,16 @@ import java.util.stream.Collectors; @Service public class DbRuleService { private final RuleRepository ruleRepository; - private final TimeSeriesService timeSeriesService; private final AntecedentValueService antecedentValueService; + private final MarkupService markupService; public DbRuleService(RuleRepository ruleRepository, TimeSeriesService timeSeriesService, - AntecedentValueService antecedentValueService) { + AntecedentValueService antecedentValueService, + MarkupService markupService) { this.ruleRepository = ruleRepository; - this.timeSeriesService = timeSeriesService; this.antecedentValueService = antecedentValueService; + this.markupService = markupService; } public List getList() { @@ -65,4 +71,40 @@ public class DbRuleService { public List getConsequentList() { return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList()); } + + @Transactional + public void generateRulesFromMarkup() { + List markups = markupService.findAll(); + for (Markup markup1 : markups) { + for (Markup markup2 : markups) { + if (!markup1.equals(markup2)) { + List values1 = markup1.getTimeSeries().getValues(); + for (int i = 1; i < values1.size(); i++) { + List 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); + } } -- 2.34.1 From 80904e622148e740e0d09fd6fbf0730776fde1f5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 14 Mar 2023 23:20:57 +0400 Subject: [PATCH 13/28] #91 -- Restore --- .../ulstu/extractor/assessment/service/AssessmentService.java | 3 +-- .../ru/ulstu/extractor/rule/controller/RuleController.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 2514e6a..d221806 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -71,9 +71,8 @@ public class AssessmentService { Map variableValues = new HashMap<>(); timeSeries .stream() - .filter(ts -> (ts.getTimeSeriesType() == dbRule.getFirstAntecedent() + .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) - && ts.getValues().size() > 0) .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService .getLastTimeSeriesTendency(ts) .orElse(ts.getValues().get(ts.getValues().size() - 1).getValue()))); diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java index 4e855df..a9a8258 100644 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RuleController.java @@ -54,7 +54,7 @@ public class RuleController { } @GetMapping(DELETE_RULE) - public String deleteRule(Model model, @RequestParam Integer id) { + public String deleteRule(@RequestParam Integer id) { ruleService.deleteById(id); return "redirect:/" + LIST_RULE; } -- 2.34.1 From 394873f63b31287aa1a48932cbc64d6e6402bfec Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Mar 2023 14:21:37 +0400 Subject: [PATCH 14/28] #91 -- Remove copyright --- .../ru/ulstu/extractor/ts/service/TimeSeriesService.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 1067649..5d48ae7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.ts.service; import org.json.JSONArray; @@ -27,8 +22,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Stream; import java.util.stream.Collectors; +import java.util.stream.Stream; @Service public class TimeSeriesService { -- 2.34.1 From ddedfc97515ca08d36af264b8f4724146c506154 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Mar 2023 14:36:47 +0400 Subject: [PATCH 15/28] #91 -- Fix form --- src/main/resources/templates/assessments.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index a303e2d..8a8c7f7 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -31,8 +31,6 @@
Выбрерите ветку для получения оценки репозитория
- -
Состояние репозитория описывается следующими выражениями:
-- 2.34.1 From d111121e2437d39cc8d2841693c15456e8caa1cb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Mar 2023 23:09:04 +0400 Subject: [PATCH 16/28] #91 -- Use new models --- .../TimeSeriesMarkupController.java | 36 ++++++++------- .../extractor/markup/model/MarkupForm.java | 33 ++++---------- .../markup/model/TimeSeriesForMarkup.java | 44 +++++++++++++++++++ .../markup/service/MarkupService.java | 41 +++++++++++++++-- src/main/resources/templates/markup.html | 12 ++--- 5 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 0672544..94d1ec4 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -8,14 +8,12 @@ import org.springframework.web.bind.annotation.PostMapping; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.core.Route; 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.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; -import java.util.stream.Collectors; @Controller @ApiIgnore @@ -34,18 +32,21 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAllValid()); model.addAttribute("markupForm", new MarkupForm()); return "markup"; } @PostMapping("time-series-markup") public String filter(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAllValid()); if (markupForm != null && markupForm.getBranchId() != null) { - List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); - MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); - markupFormWithTs.setBranchId(markupForm.getBranchId()); + List tss = markupService.getTimeSeriesForMarkup( + timeSeriesService.getGroupedTendencies( + timeSeriesService.getByBranch(markupForm.getBranchId()) + ) + ); + MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); } else { model.addAttribute("markupForm", new MarkupForm()); @@ -55,15 +56,18 @@ public class TimeSeriesMarkupController { @PostMapping(Route.ADD_MARKUP) public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAll()); - if (markupForm.getBranchId() != null) { - List tss = timeSeriesService.getByBranch(markupForm.getBranchId()); - MarkupForm markupFormWithTs = new MarkupForm(tss.stream().map(MarkupRow::new).limit(200).collect(Collectors.toList())); - markupFormWithTs.setBranchId(markupForm.getBranchId()); + model.addAttribute("branches", branchService.findAllValid()); + if (markupForm != null && markupForm.getBranchId() != null) { + List tss = markupService.getTimeSeriesForMarkup( + timeSeriesService.getGroupedTendencies( + timeSeriesService.getByBranch(markupForm.getBranchId()) + ) + ); + MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); - if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { - markupService.saveMarkup(markupForm); - } +// if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { +// markupService.saveMarkup(markupForm); +// } } return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java index c07c837..098a379 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/MarkupForm.java @@ -4,24 +4,23 @@ import java.util.ArrayList; import java.util.List; public class MarkupForm { - private List markupRows = new ArrayList<>(); + private List timeSeriesForMarkupList = new ArrayList<>(); private Integer branchId; - private boolean save; - private boolean filter; public MarkupForm() { } - public MarkupForm(List markupRows) { - this.markupRows = markupRows; + public MarkupForm(Integer branchId, List tss) { + this.timeSeriesForMarkupList = tss; + this.branchId = branchId; } - public List getMarkupRows() { - return markupRows; + public List getTimeSeriesForMarkupList() { + return timeSeriesForMarkupList; } - public void setMarkupRows(List markupRows) { - this.markupRows = markupRows; + public void setTimeSeriesForMarkupList(List timeSeriesForMarkupList) { + this.timeSeriesForMarkupList = timeSeriesForMarkupList; } public Integer getBranchId() { @@ -31,20 +30,4 @@ public class MarkupForm { public void setBranchId(Integer 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; - } } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java new file mode 100644 index 0000000..3bb84ff --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -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 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 getTimeSeriesSet() { + return timeSeriesSet; + } + + public void setTimeSeriesSet(Set 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; + } +} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index c4d3fd3..2d3096f 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,13 +1,14 @@ package ru.ulstu.extractor.markup.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.MarkupForm; +import ru.ulstu.extractor.markup.model.TimeSeriesForMarkup; import ru.ulstu.extractor.markup.repository.MarkupRepository; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; +import java.util.ArrayList; import java.util.List; @Service @@ -21,15 +22,47 @@ public class MarkupService { this.timeSeriesService = timeSeriesService; } - @Transactional + /*@Transactional public void saveMarkup(MarkupForm markupForm) { markupForm.getMarkupRows().forEach(markupRow -> { TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); }); - } + }*/ public List findAll() { return markupRepository.findAll(); } + + public List getTimeSeriesForMarkup(List timeSeriesList) { + List 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 values1 = ts1.getValues(); + for (int k = 0; k < values1.size() - 1; k++) { + List 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; + } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index c0c98a7..0f085fe 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -36,15 +36,15 @@
- + - - - - + + + + +
Разметка временных рядовОхарактеризуйте периоды вашего проекта
-- 2.34.1 From 5c6b38890185d3dd6e7054471c338c1290fdc844 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Mar 2023 23:09:26 +0400 Subject: [PATCH 17/28] #91 -- Reformat --- .../extractor/markup/service/MarkupService.java | 12 ++++++------ src/main/resources/templates/markup.html | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 2d3096f..c222d39 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -38,22 +38,22 @@ public class MarkupService { List 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++) { + for (int j = i+1; j < timeSeriesList.size(); j++) { TimeSeries ts2 = timeSeriesList.get(j); List values1 = ts1.getValues(); - for (int k = 0; k < values1.size() - 1; k++) { + for (int k = 0; k < values1.size()-1; k++) { List values2 = ts2.getValues(); - for (int l = 0; l < values2.size() - 1; l++) { + 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())) { + && 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())) + .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())); + tsForMarkup.add(new TimeSeriesForMarkup(ts1, ts2, values1.get(index).getDate(), values1.get(index+1).getDate())); } else { found.getTimeSeriesSet().add(ts1); found.getTimeSeriesSet().add(ts2); diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 0f085fe..87746b9 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,9 +22,7 @@
@@ -41,10 +39,10 @@ - + - + -- 2.34.1 From 4596a25a595a21bf356d2b94ea809e6b7e7b34cb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 11 Apr 2023 16:36:05 +0400 Subject: [PATCH 18/28] #91 -- Fix fuzzy inference --- .../assessment/service/AssessmentService.java | 49 ++----------------- .../rule/service/FuzzyInferenceService.java | 26 +++++----- .../ts/service/TimeSeriesService.java | 16 +++++- 3 files changed, 28 insertions(+), 63 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index e1a2020..2d9899c 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -8,7 +8,6 @@ import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.DbRuleService; import ru.ulstu.extractor.rule.service.FuzzyInferenceService; import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; import java.util.ArrayList; @@ -57,9 +56,7 @@ public class AssessmentService { timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)); + variableValues); } private List getAssessmentsByTimeSeriesTendencies(List dbRules, List timeSeries) { @@ -75,9 +72,7 @@ public class AssessmentService { .getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(List.of(dbRule), antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)).stream(); + variableValues).stream(); }) .sorted(Comparator.comparing(Assessment::getDegree)) .collect(Collectors.toList()); @@ -88,44 +83,6 @@ public class AssessmentService { timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), ts.getValues().get(ts.getValues().size() - 1).getValue())); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), - variableValues, - getTSsMin(timeSeries), - getTSsMax(timeSeries)); - } - - private Double getMin(List values) { - return values.stream().mapToDouble(v -> v).min().getAsDouble(); - } - - private Map.Entry getTSMin(TimeSeries ts) { - return Map.entry(ts.getTimeSeriesType().name(), - getMin(ts.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()))); - } - - private Map getTSsMin(List tss) { - Map res = new HashMap<>(); - tss.forEach(ts -> { - Map.Entry entry = getTSMin(ts); - res.put(entry.getKey(), entry.getValue()); - }); - return res; - } - - private Double getMax(List values) { - return values.stream().mapToDouble(v -> v).max().getAsDouble(); - } - - private Map.Entry getTSMax(TimeSeries ts) { - return Map.entry(ts.getTimeSeriesType().name(), - getMax(ts.getValues().stream().map(TimeSeriesValue::getValue).collect(Collectors.toList()))); - } - - private Map getTSsMax(List tss) { - Map res = new HashMap<>(); - tss.forEach(ts -> { - Map.Entry entry = getTSMax(ts); - res.put(entry.getKey(), entry.getValue()); - }); - return res; + variableValues); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 6768c87..910dde5 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -34,8 +34,7 @@ public class FuzzyInferenceService { + " is %s"; private final static String NO_RESULT = "Нет результата"; - private List getRulesFromDb(List dbRules, Map variableValues) { - validateVariables(variableValues, dbRules); + private List mapRulesToString(List dbRules) { return dbRules.stream().map(this::getFuzzyRule).collect(Collectors.toList()); } @@ -51,8 +50,6 @@ public class FuzzyInferenceService { private RuleBlock getRuleBlock(Engine engine, List dbRules, Map variableValues, - Map min, - Map max, List antecedentValues, List consequentValues) { variableValues.forEach((key, value) -> { @@ -61,16 +58,16 @@ public class FuzzyInferenceService { input.setDescription(""); input.setEnabled(true); double delta = antecedentValues.size() > 1 - ? (max.get(key) - min.get(key)) / (antecedentValues.size() - 1) - : (max.get(key) - min.get(key)); - input.setRange(min.get(key), max.get(key)); + ? 2.0 / (antecedentValues.size() - 1) + : 2.0; + input.setRange(-1, 1); input.setLockValueInRange(false); for (int i = 0; i < antecedentValues.size(); i++) { input.addTerm( new Triangle( antecedentValues.get(i).getAntecedentValue(), - min.get(key) + i * delta - 0.5 * delta, - min.get(key) + i * delta + delta + 0.5 * delta + -1 + i * delta - 0.5 * delta, + -1 + i * delta + delta + 0.5 * delta ) ); } @@ -87,7 +84,7 @@ public class FuzzyInferenceService { output.setDefaultValue(Double.NaN); output.setLockValueInRange(false); for (int i = 0; i < consequentValues.size(); i++) { - output.addTerm(new Triangle(consequentValues.get(i).toString(), i, i + 2.1)); + output.addTerm(new Triangle(consequentValues.get(i).toString(), i, i + 1)); } engine.addOutputVariable(output); @@ -99,7 +96,7 @@ public class FuzzyInferenceService { //mamdani.setDisjunction(null); mamdani.setImplication(new AlgebraicProduct()); mamdani.setActivation(new General()); - getRulesFromDb(dbRules, variableValues).forEach(r -> { + mapRulesToString(dbRules).forEach(r -> { LOG.info(r); mamdani.addRule(Rule.parse(r, engine)); }); @@ -115,12 +112,11 @@ public class FuzzyInferenceService { public List getFuzzyInference(List dbRules, List antecedentValues, - Map variableValues, - Map min, - Map max) { + Map variableValues) { + validateVariables(variableValues, dbRules); Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); - engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, min, max, antecedentValues, consequentValues)); + engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); Map.Entry consequent = getConsequent(engine, variableValues); if (consequent.getKey().equals(NO_RESULT)) { return new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 5d48ae7..038a3c0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -127,17 +127,29 @@ public class TimeSeriesService { public double getLastTimeSeriesTendency(TimeSeries ts) { if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { - JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(ts))); + JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(normalizeTimeSeries(ts)))); LOG.debug("Успешно отправлен на сервис сглаживания"); if (response.has("response") && response.getString("response").equals("empty")) { return DEFAULT_TIME_SERIES_TENDENCY; } JSONArray jsonArray = response.getJSONObject("timeSeries").getJSONArray("values"); - return jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value"); + return jsonArray.getJSONObject(jsonArray.length() - 1).getDouble("value") - + jsonArray.getJSONObject(jsonArray.length() - 2).getDouble("value"); } return DEFAULT_TIME_SERIES_TENDENCY; } + private TimeSeries normalizeTimeSeries(TimeSeries ts) { + double sum = ts.getValues().stream().mapToDouble(TimeSeriesValue::getValue).sum(); + + if (sum > 0.0d) { + for (int i = 0; i < ts.getValues().size(); i++) { + ts.getValues().get(i).setValue(ts.getValues().get(i).getValue() / sum); + } + } + return ts; + } + public boolean isBranchContainsAllTimeSeries(Branch b) { List timeSeries = getByBranch(b.getId()); return Stream.of(TimeSeriesType.values()).allMatch(type -> timeSeries -- 2.34.1 From d03cb194ee0ef081af66d40fd63081155a68def7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 13:23:48 +0400 Subject: [PATCH 19/28] #91 -- Fix fuzzy inference --- .../controller/AssessmentController.java | 3 ++- .../assessment/service/AssessmentService.java | 20 ++++++------------- src/main/resources/templates/assessments.html | 19 +++++++++++++++++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java index e5721fa..35beb28 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java +++ b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java @@ -29,7 +29,8 @@ public class AssessmentController { public String getAssessments(Model model, @RequestParam Optional branchId) { model.addAttribute("branches", branchService.findAllValid()); if (branchId.isPresent()) { - model.addAttribute("assessments", assessmentService.getAssessmentsByForecastTendencies(branchId.get())); + model.addAttribute("assessments", assessmentService.getAssessments(branchId.get())); + model.addAttribute("singleAssessment", assessmentService.getSingleAssessment(branchId.get())); model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); } else { model.addAttribute("filterBranchForm", new FilterBranchForm()); diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 2d9899c..83e99ef 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -34,24 +34,24 @@ public class AssessmentService { this.fuzzyInferenceService = fuzzyInferenceService; } - public List getAssessmentsByForecastTendencies(Integer branchId) { + public List getAssessments(Integer branchId) { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); try { - return getAssessmentsByTimeSeriesTendencies(dbRules, timeSeries); + return getAssessments(dbRules, timeSeries); } catch (AssessmentException ex) { ex.printStackTrace(); return new ArrayList<>(); } } - public List getAssessmentsByLastValues(Integer branchId) { + public List getSingleAssessment(Integer branchId) throws AssessmentException { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); - return getAssessmentsByLastValues(dbRules, timeSeries); + return getSingleAssessment(dbRules, timeSeries); } - private List getSingleAssessmentByTimeSeriesTendencies(List dbRules, List timeSeries) throws AssessmentException { + private List getSingleAssessment(List dbRules, List timeSeries) throws AssessmentException { Map variableValues = new HashMap<>(); timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, @@ -59,7 +59,7 @@ public class AssessmentService { variableValues); } - private List getAssessmentsByTimeSeriesTendencies(List dbRules, List timeSeries) { + private List getAssessments(List dbRules, List timeSeries) { return dbRules .stream() .flatMap(dbRule -> { @@ -77,12 +77,4 @@ public class AssessmentService { .sorted(Comparator.comparing(Assessment::getDegree)) .collect(Collectors.toList()); } - - private List getAssessmentsByLastValues(List dbRules, List timeSeries) { - Map variableValues = new HashMap<>(); - timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), ts.getValues().get(ts.getValues().size() - 1).getValue())); - return fuzzyInferenceService.getFuzzyInference(dbRules, - antecedentValueService.getList(), - variableValues); - } } diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index 8a8c7f7..f213f81 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -33,7 +33,7 @@
Выбрерите ветку для получения оценки репозитория
-
Состояние репозитория описывается следующими выражениями:
+
Состояние репозитория по нескольким правилам описывается следующими выражениями:
вследствие тенденции '' показателя '
Нет результатов
+ +
+ +
+
Состояние репозитория по лидирующему правилу описывается следующими выражениями:
+
+ + вследствие тенденции '' показателя '' + и тенденции '' показателя ''; + +
+
+
+
Нет результатов
+
-- 2.34.1 From 6823f3499759e7db6b91ab9f86d0b127ce2debb1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 15:00:14 +0400 Subject: [PATCH 20/28] #91 -- Fix fuzzy sets --- .../rule/service/FuzzyInferenceService.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 910dde5..a1a7f53 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -57,20 +57,11 @@ public class FuzzyInferenceService { input.setName(key); input.setDescription(""); input.setEnabled(true); - double delta = antecedentValues.size() > 1 - ? 2.0 / (antecedentValues.size() - 1) - : 2.0; input.setRange(-1, 1); input.setLockValueInRange(false); - for (int i = 0; i < antecedentValues.size(); i++) { - input.addTerm( - new Triangle( - antecedentValues.get(i).getAntecedentValue(), - -1 + i * delta - 0.5 * delta, - -1 + i * delta + delta + 0.5 * delta - ) - ); - } + input.addTerm(new Triangle("спад", -1, 0)); + input.addTerm(new Triangle("стабильно", -0.1, 0.1)); + input.addTerm(new Triangle("рост", 0, 1)); engine.addInputVariable(input); }); @@ -114,6 +105,7 @@ public class FuzzyInferenceService { List antecedentValues, Map variableValues) { validateVariables(variableValues, dbRules); + variableValues.entrySet().forEach(e -> System.out.println(e.getKey() + " " + e.getValue())); Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); -- 2.34.1 From 1dc44f79889eae29b0f0bbb36e5abb5f0965304e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 15:47:27 +0400 Subject: [PATCH 21/28] #91 -- Fix fuzzy inference --- .../controller/AssessmentController.java | 1 - .../assessment/service/AssessmentService.java | 38 ------------------- .../rule/service/FuzzyInferenceService.java | 27 +++++++------ src/main/resources/templates/assessments.html | 17 --------- 4 files changed, 16 insertions(+), 67 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java index 35beb28..9a7ffd8 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java +++ b/src/main/java/ru/ulstu/extractor/assessment/controller/AssessmentController.java @@ -30,7 +30,6 @@ public class AssessmentController { model.addAttribute("branches", branchService.findAllValid()); if (branchId.isPresent()) { model.addAttribute("assessments", assessmentService.getAssessments(branchId.get())); - model.addAttribute("singleAssessment", assessmentService.getSingleAssessment(branchId.get())); model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); } else { model.addAttribute("filterBranchForm", new FilterBranchForm()); diff --git a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java index 83e99ef..0bae62a 100644 --- a/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java +++ b/src/main/java/ru/ulstu/extractor/assessment/service/AssessmentService.java @@ -2,7 +2,6 @@ package ru.ulstu.extractor.assessment.service; import org.springframework.stereotype.Service; import ru.ulstu.extractor.assessment.model.Assessment; -import ru.ulstu.extractor.rule.model.AssessmentException; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.service.AntecedentValueService; import ru.ulstu.extractor.rule.service.DbRuleService; @@ -10,12 +9,9 @@ import ru.ulstu.extractor.rule.service.FuzzyInferenceService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Service public class AssessmentService { @@ -37,44 +33,10 @@ public class AssessmentService { public List getAssessments(Integer branchId) { List timeSeries = timeSeriesService.getByBranch(branchId); List dbRules = ruleService.getList(); - try { - return getAssessments(dbRules, timeSeries); - } catch (AssessmentException ex) { - ex.printStackTrace(); - return new ArrayList<>(); - } - } - - public List getSingleAssessment(Integer branchId) throws AssessmentException { - List timeSeries = timeSeriesService.getByBranch(branchId); - List dbRules = ruleService.getList(); - return getSingleAssessment(dbRules, timeSeries); - } - - private List getSingleAssessment(List dbRules, List timeSeries) throws AssessmentException { Map variableValues = new HashMap<>(); timeSeries.forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService.getLastTimeSeriesTendency(ts))); return fuzzyInferenceService.getFuzzyInference(dbRules, antecedentValueService.getList(), variableValues); } - - private List getAssessments(List dbRules, List timeSeries) { - return dbRules - .stream() - .flatMap(dbRule -> { - Map variableValues = new HashMap<>(); - timeSeries - .stream() - .filter(ts -> ts.getTimeSeriesType() == dbRule.getFirstAntecedent() - || ts.getTimeSeriesType() == dbRule.getSecondAntecedent()) - .forEach(ts -> variableValues.put(ts.getTimeSeriesType().name(), timeSeriesService - .getLastTimeSeriesTendency(ts))); - return fuzzyInferenceService.getFuzzyInference(List.of(dbRule), - antecedentValueService.getList(), - variableValues).stream(); - }) - .sorted(Comparator.comparing(Assessment::getDegree)) - .collect(Collectors.toList()); - } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index a1a7f53..28838c6 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -8,6 +8,7 @@ import com.fuzzylite.norm.t.AlgebraicProduct; import com.fuzzylite.norm.t.Minimum; import com.fuzzylite.rule.Rule; import com.fuzzylite.rule.RuleBlock; +import com.fuzzylite.term.Activated; import com.fuzzylite.term.Triangle; import com.fuzzylite.variable.InputVariable; import com.fuzzylite.variable.OutputVariable; @@ -109,15 +110,19 @@ public class FuzzyInferenceService { Engine engine = getFuzzyEngine(); List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); engine.addRuleBlock(getRuleBlock(engine, dbRules, variableValues, antecedentValues, consequentValues)); - Map.Entry consequent = getConsequent(engine, variableValues); - if (consequent.getKey().equals(NO_RESULT)) { + Map consequents = getConsequent(engine, variableValues); + if (consequents.containsKey(NO_RESULT)) { return new ArrayList<>(); } - return dbRules - .stream() - .filter(r -> r.getId().equals(Integer.valueOf(consequent.getKey()))) - .map(r -> new Assessment(r, consequent.getValue())) - .collect(Collectors.toList()); + List assessments = new ArrayList<>(); + for (Map.Entry consequent : consequents.entrySet()) { + for (DbRule dbRule : dbRules) { + if (dbRule.getId().equals(Integer.valueOf(consequent.getKey()))) { + assessments.add(new Assessment(dbRule, consequent.getValue())); + } + } + } + return assessments; } @@ -134,7 +139,7 @@ public class FuzzyInferenceService { } } - private Map.Entry getConsequent(Engine engine, Map variableValues) { + private Map getConsequent(Engine engine, Map variableValues) { OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME); for (Map.Entry variableValue : variableValues.entrySet()) { InputVariable inputVariable = engine.getInputVariable(variableValue.getKey()); @@ -144,8 +149,8 @@ public class FuzzyInferenceService { if (outputVariable != null) { LOG.info("Output: {}", outputVariable.getValue()); } - return (outputVariable == null || Double.isNaN(outputVariable.getValue())) - ? Map.entry(NO_RESULT, 0.0) - : Map.entry(outputVariable.highestMembershipTerm(outputVariable.getValue()).getName(), outputVariable.getValue()); + return Double.isNaN(outputVariable.getValue()) + ? Map.of(NO_RESULT, 0.0) + : outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree)); } } diff --git a/src/main/resources/templates/assessments.html b/src/main/resources/templates/assessments.html index f213f81..d88b271 100644 --- a/src/main/resources/templates/assessments.html +++ b/src/main/resources/templates/assessments.html @@ -46,22 +46,5 @@
Нет результатов
- -
- -
-
Состояние репозитория по лидирующему правилу описывается следующими выражениями:
-
- - вследствие тенденции '' показателя '' - и тенденции '' показателя ''; - -
-
-
-
Нет результатов
-
-- 2.34.1 From 3bb4f5c49c0ddb09e63f77ddd7884c2d265a5279 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 22:49:33 +0400 Subject: [PATCH 22/28] #91 -- Run scheduled time series creators --- .../gitrepository/service/IndexService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 8e89f21..9b2cca7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -1,8 +1,3 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - package ru.ulstu.extractor.gitrepository.service; import com.sun.istack.NotNull; @@ -18,6 +13,7 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; +import ru.ulstu.extractor.ts.service.ScheduledTimeSeriesService; import java.io.IOException; import java.util.Collections; @@ -30,13 +26,16 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final BranchService branchService; private final List timeSeriesCreators; + private final ScheduledTimeSeriesService scheduledTimeSeriesService; public IndexService(GitRepositoryService gitRepositoryService, BranchService branchService, - List timeSeriesCreators) { + List timeSeriesCreators, + ScheduledTimeSeriesService scheduledTimeSeriesService) { this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; this.timeSeriesCreators = timeSeriesCreators; + this.scheduledTimeSeriesService = scheduledTimeSeriesService; } @Transactional @@ -74,6 +73,7 @@ public class IndexService { branch = branchService.findByBranchId(branch.getId()).orElseThrow(() -> new RuntimeException("Branch not found by id")); final Branch branchForSave = branchService.updateStatus(branch, IndexingStatus.FINISHED); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); + scheduledTimeSeriesService.addTimeSeriesPoints(); LOG.debug("Complete indexing {} branch", branch.getName()); } -- 2.34.1 From 8d31dc36b36fb27940e732d426c7539912c3e1b4 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Apr 2023 23:11:09 +0400 Subject: [PATCH 23/28] #91 -- Fix time series types --- src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java index f694064..27487b7 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesType.java @@ -3,9 +3,6 @@ package ru.ulstu.extractor.ts.model; public enum TimeSeriesType { COMMITS("Временной ряд коммитов"), AUTHOR_COMMITS("Временной ряд коммитов авторов"), - AUTHOR_ISSUES("Временной ряд задач авторов"), - AUTHOR_COMPLETED_ISSUES("Временной ряд завершенных задач авторов"), - AUTHORS("Временной ряд авторов"), BRANCHES("Временной ряд веток"), CLASSES("Временной ряд классов"), DEPENDENCIES("Временной ряд зависимостей"), -- 2.34.1 From 1c62c520e940cf815b7f07068a5db599ecec75e1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 22 Apr 2023 12:26:54 +0400 Subject: [PATCH 24/28] #91 -- Fix db --- .../db/changelog-20230302_210000-schema.xml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml index 7ccb661..670658e 100644 --- a/src/main/resources/db/changelog-20230302_210000-schema.xml +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -20,4 +20,30 @@ referencedTableName="time_series" referencedColumnNames="id"/> + + + delete + from time_series + where time_series_type = 'AUTHORS'; + delete + from rule + where first_antecedent = 'AUTHORS' + OR second_antecedent = 'AUTHORS'; + delete + from time_series + where time_series_type = 'AUTHOR_COMPLETED_ISSUES'; + delete + from rule + where first_antecedent = 'AUTHOR_COMPLETED_ISSUES' + OR second_antecedent = 'AUTHOR_COMPLETED_ISSUES'; + delete + from time_series + where time_series_type = 'AUTHOR_ISSUES'; + delete + from rule + where first_antecedent = 'AUTHOR_ISSUES' + OR second_antecedent = 'AUTHOR_ISSUES'; + + + \ No newline at end of file -- 2.34.1 From 9c3a64b0d0c7707ebcb8e380a337a3b1453b944c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 22 Apr 2023 12:58:12 +0400 Subject: [PATCH 25/28] #91 -- Fix smoothing --- .../ru/ulstu/extractor/ts/service/TimeSeriesService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 038a3c0..2279b0d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -8,7 +8,6 @@ import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; import ru.ulstu.extractor.http.JsonTimeSeries; -import ru.ulstu.extractor.http.SmoothingTimeSeries; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -35,7 +34,7 @@ public class TimeSeriesService { private final TimeSeriesDateMapper.TimeSeriesInterval timeSeriesInterval = TimeSeriesDateMapper.TimeSeriesInterval.HOUR; private final HttpService httpService; private final static String TIME_SERIES_SAVE_SERVICE_URL = "http://time-series.athene.tech/api/1.0/add-time-series?setKey=git-extractor"; - private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getSpecificMethodSmoothed"; + private final static String TIME_SERIES_TENDENCY_URL = "http://time-series.athene.tech/api/1.0/getMaxSmoothing"; private final static String TIME_SERIES_GROUPED_TENDENCIES_URL = "http://time-series.athene.tech/api/1.0/getGroupedTendencies"; public TimeSeriesService(TimeSeriesRepository timeSeriesRepository, @@ -127,7 +126,7 @@ public class TimeSeriesService { public double getLastTimeSeriesTendency(TimeSeries ts) { if (ts != null && ts.getValues().size() > MIN_TIME_SERIES_LENGTH) { - JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new SmoothingTimeSeries(normalizeTimeSeries(ts)))); + JSONObject response = httpService.post(TIME_SERIES_TENDENCY_URL, new JSONObject(new JsonTimeSeries(normalizeTimeSeries(ts)))); LOG.debug("Успешно отправлен на сервис сглаживания"); if (response.has("response") && response.getString("response").equals("empty")) { return DEFAULT_TIME_SERIES_TENDENCY; -- 2.34.1 From e506566a5ddc79ac28b98b06861d3830e44e2572 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 15:08:26 +0400 Subject: [PATCH 26/28] #91 -- Fix data for markup --- .../TimeSeriesMarkupController.java | 7 +- .../ulstu/extractor/markup/model/Markup.java | 38 --------- .../markup/model/TimeSeriesForMarkup.java | 26 +++--- .../markup/repository/MarkupRepository.java | 7 -- .../markup/service/MarkupService.java | 83 +++++++++++++------ .../extractor/rule/service/DbRuleService.java | 58 +++---------- src/main/resources/templates/markup.html | 29 +++---- 7 files changed, 98 insertions(+), 150 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/markup/model/Markup.java delete mode 100644 src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 94d1ec4..3aef93a 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -65,9 +65,10 @@ public class TimeSeriesMarkupController { ); MarkupForm markupFormWithTs = new MarkupForm(markupForm.getBranchId(), tss); model.addAttribute("markupForm", markupFormWithTs); -// if (markupForm.getMarkupRows() != null && !markupForm.getMarkupRows().isEmpty()) { -// markupService.saveMarkup(markupForm); -// } + if (markupForm.getTimeSeriesForMarkupList() != null + && !markupForm.getTimeSeriesForMarkupList().isEmpty()) { + markupService.generateRules(markupForm); + } } return "markup"; } diff --git a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java b/src/main/java/ru/ulstu/extractor/markup/model/Markup.java deleted file mode 100644 index f119e41..0000000 --- a/src/main/java/ru/ulstu/extractor/markup/model/Markup.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java index 3bb84ff..9aaa903 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -1,29 +1,27 @@ package ru.ulstu.extractor.markup.model; +import ru.ulstu.extractor.rule.model.AntecedentValue; import ru.ulstu.extractor.ts.model.TimeSeries; import java.util.Date; -import java.util.Set; -import java.util.TreeSet; +import java.util.HashMap; +import java.util.Map; public class TimeSeriesForMarkup { - private Set timeSeriesSet = new TreeSet<>(); + private Map timeSeriesTendencyMap = new HashMap<>(); + private String markup; private Date dateFrom; 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.dateTo = dateTo; - this.timeSeriesSet.add(ts1); - this.timeSeriesSet.add(ts2); + this.timeSeriesTendencyMap.put(ts1, tendency1); + this.timeSeriesTendencyMap.put(ts2, tendency2); } - public Set getTimeSeriesSet() { - return timeSeriesSet; - } - - public void setTimeSeriesSet(Set timeSeriesSet) { - this.timeSeriesSet = timeSeriesSet; + public Map getTimeSeriesTendencyMap() { + return timeSeriesTendencyMap; } public Date getDateFrom() { @@ -41,4 +39,8 @@ public class TimeSeriesForMarkup { public void setDateTo(Date dateTo) { this.dateTo = dateTo; } + + public String getMarkup() { + return markup; + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java b/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java deleted file mode 100644 index 0d149f1..0000000 --- a/src/main/java/ru/ulstu/extractor/markup/repository/MarkupRepository.java +++ /dev/null @@ -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 { -} diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index c222d39..12ee087 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -1,68 +1,97 @@ package ru.ulstu.extractor.markup.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.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.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; +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 public class MarkupService { - private final MarkupRepository markupRepository; - private final TimeSeriesService timeSeriesService; + private final DbRuleService dbRuleService; + private final AntecedentValueService antecedentValueService; - public MarkupService(MarkupRepository markupRepository, - TimeSeriesService timeSeriesService) { - this.markupRepository = markupRepository; - this.timeSeriesService = timeSeriesService; + public MarkupService(DbRuleService dbRuleService, + AntecedentValueService antecedentValueService) { + this.dbRuleService = dbRuleService; + this.antecedentValueService = antecedentValueService; } - /*@Transactional - public void saveMarkup(MarkupForm markupForm) { - markupForm.getMarkupRows().forEach(markupRow -> { - TimeSeries timeSeries = timeSeriesService.getById(markupRow.getTimeSeries().getId()); - markupRepository.save(new Markup(timeSeries, markupRow.getMarkup())); + @Transactional + public void generateRules(MarkupForm markupForm) { + markupForm.getTimeSeriesForMarkupList().forEach(markupRow -> { + Set> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet(); + Set> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet(); + for (Map.Entry entry1 : timeSeriesEntry1) { + for (Map.Entry entry2 : timeSeriesEntry2) { + if (!entry1.equals(entry2)) { + dbRuleService.saveRule(entry1.getKey().getTimeSeriesType(), entry1.getValue(), + entry2.getKey().getTimeSeriesType(), entry2.getValue(), + markupRow.getMarkup()); + } + } + } }); - }*/ - - public List 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 getTimeSeriesForMarkup(List timeSeriesList) { List 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++) { + for (int j = i + 1; j < timeSeriesList.size(); j++) { TimeSeries ts2 = timeSeriesList.get(j); List values1 = ts1.getValues(); - for (int k = 0; k < values1.size()-1; k++) { + for (int k = 0; k < values1.size() - 1; k++) { List values2 = ts2.getValues(); - for (int l = 0; l < values2.size()-1; l++) { + 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())) { + && 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())) + .filter(m -> m.getDateFrom().equals(values1.get(index).getDate()) && m.getDateTo().equals(values1.get(index + 1).getDate())) .findAny() .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) { - 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 { - found.getTimeSeriesSet().add(ts1); - found.getTimeSeriesSet().add(ts2); + found.getTimeSeriesTendencyMap().put(ts1, antecedentValue1); + found.getTimeSeriesTendencyMap().put(ts2, antecedentValue2); } } } } } } - return tsForMarkup; + return tsForMarkup + .stream() + .sorted(Comparator.comparing(TimeSeriesForMarkup::getDateFrom)) + .collect(Collectors.toList()); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index c0a2dc5..44fe3cf 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -1,16 +1,11 @@ package ru.ulstu.extractor.rule.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.AntecedentValue; import ru.ulstu.extractor.rule.model.DbRule; import ru.ulstu.extractor.rule.repository.RuleRepository; 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.stream.Collectors; @@ -19,15 +14,11 @@ import java.util.stream.Collectors; public class DbRuleService { private final RuleRepository ruleRepository; private final AntecedentValueService antecedentValueService; - private final MarkupService markupService; public DbRuleService(RuleRepository ruleRepository, - TimeSeriesService timeSeriesService, - AntecedentValueService antecedentValueService, - MarkupService markupService) { + AntecedentValueService antecedentValueService) { this.ruleRepository = ruleRepository; this.antecedentValueService = antecedentValueService; - this.markupService = markupService; } public List 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) { return ruleRepository.getOne(id); } @@ -71,40 +73,4 @@ public class DbRuleService { public List getConsequentList() { return ruleRepository.findAll().stream().map(DbRule::getConsequent).collect(Collectors.toList()); } - - @Transactional - public void generateRulesFromMarkup() { - List markups = markupService.findAll(); - for (Markup markup1 : markups) { - for (Markup markup2 : markups) { - if (!markup1.equals(markup2)) { - List values1 = markup1.getTimeSeries().getValues(); - for (int i = 1; i < values1.size(); i++) { - List 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); - } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 87746b9..0d0fc58 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,7 +22,9 @@ @@ -31,22 +33,15 @@ value="Применить"/> - - - - - - - - - - - - - - -
Охарактеризуйте периоды вашего проекта
- +
+ Охарактеризуйте периоды вашего проекта
+
+ + + +
+ -- 2.34.1 From 07cd5abe9cca85ed5df57540e41da1f8c87d7200 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 15:09:00 +0400 Subject: [PATCH 27/28] #91 -- Fix format --- src/main/resources/templates/markup.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 0d0fc58..1009701 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -22,9 +22,7 @@ -- 2.34.1 From d2f898d758d9c4671a19df6dda4897ddc005b5e4 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 23 Apr 2023 23:41:44 +0400 Subject: [PATCH 28/28] #91 -- fix markup --- .../markup/model/TimeSeriesForMarkup.java | 44 ++++++++++++++++++- .../markup/service/MarkupService.java | 15 +++---- .../extractor/rule/service/DbRuleService.java | 4 +- .../ulstu/extractor/ts/model/TimeSeries.java | 5 ++- .../ts/service/TimeSeriesService.java | 2 +- src/main/resources/templates/markup.html | 9 +++- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java index 9aaa903..3a48a57 100644 --- a/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java +++ b/src/main/java/ru/ulstu/extractor/markup/model/TimeSeriesForMarkup.java @@ -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 timeSeriesTendencyMap = new HashMap<>(); - private String markup; private Date dateFrom; private Date dateTo; + //input + private List timeSeriesTypes; + private List 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 getTimeSeriesTendencyMap() { @@ -43,4 +56,33 @@ public class TimeSeriesForMarkup { public String getMarkup() { return markup; } + + public void setTimeSeriesTendencyMap(Map timeSeriesTendencyMap) { + this.timeSeriesTendencyMap = timeSeriesTendencyMap; + } + + public void setMarkup(String markup) { + this.markup = markup; + } + + public List getTimeSeriesTypes() { + return timeSeriesTypes; + } + + public void setTimeSeriesTypes(List timeSeriesTypes) { + this.timeSeriesTypes = timeSeriesTypes; + } + + public List getAntecedentValues() { + return antecedentValues; + } + + public void setAntecedentValues(List antecedentValues) { + this.antecedentValues = antecedentValues; + } + + public void refresh() { + this.antecedentValues = new ArrayList<>(timeSeriesTendencyMap.values()); + this.timeSeriesTypes = timeSeriesTendencyMap.keySet().stream().map(TimeSeries::getTimeSeriesType).collect(Collectors.toList()); + } } diff --git a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java index 12ee087..5c4508d 100644 --- a/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java +++ b/src/main/java/ru/ulstu/extractor/markup/service/MarkupService.java @@ -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> timeSeriesEntry1 = markupRow.getTimeSeriesTendencyMap().entrySet(); - Set> timeSeriesEntry2 = markupRow.getTimeSeriesTendencyMap().entrySet(); - for (Map.Entry entry1 : timeSeriesEntry1) { - for (Map.Entry 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(); } } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java index 44fe3cf..537ef59 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/DbRuleService.java @@ -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)); diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index 34a2b4c..a7519ce 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -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 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) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 2279b0d..6dba38c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -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()); } } diff --git a/src/main/resources/templates/markup.html b/src/main/resources/templates/markup.html index 1009701..fa92dad 100644 --- a/src/main/resources/templates/markup.html +++ b/src/main/resources/templates/markup.html @@ -34,9 +34,14 @@
Охарактеризуйте периоды вашего проекта
- +
+ +
+
+ +
- +
-- 2.34.1