#91 -- Add markup page menu item #94
@ -41,6 +41,26 @@ public class HttpService {
|
|||||||
return response;
|
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) {
|
public JSONArray get(String url) {
|
||||||
log.debug("Service call: {}", url);
|
log.debug("Service call: {}", url);
|
||||||
try {
|
try {
|
||||||
|
@ -22,7 +22,7 @@ public class TimeSeriesMarkupController {
|
|||||||
public String markupTs(Model model) {
|
public String markupTs(Model model) {
|
||||||
List<TimeSeries> ts = timeSeriesService.getAllTimeSeries();
|
List<TimeSeries> ts = timeSeriesService.getAllTimeSeries();
|
||||||
model.addAttribute("ts", ts);
|
model.addAttribute("ts", ts);
|
||||||
model.addAttribute("fts", timeSeriesService.getGroupedTendencies(ts.get(0)));
|
model.addAttribute("groupedTs", timeSeriesService.getGroupedTendencies(ts));
|
||||||
return "markup";
|
return "markup";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,14 @@ import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
|||||||
import ru.ulstu.extractor.ts.repository.TimeSeriesRepository;
|
import ru.ulstu.extractor.ts.repository.TimeSeriesRepository;
|
||||||
import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository;
|
import ru.ulstu.extractor.ts.repository.TimeSeriesValueRepository;
|
||||||
import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper;
|
import ru.ulstu.extractor.ts.util.TimeSeriesDateMapper;
|
||||||
|
import ru.ulstu.extractor.util.JsonUtils;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TimeSeriesService {
|
public class TimeSeriesService {
|
||||||
@ -138,15 +140,12 @@ public class TimeSeriesService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<TimeSeries> getGroupedTendencies(TimeSeries ts) {
|
public List<TimeSeries> getGroupedTendencies(List<TimeSeries> tsList) {
|
||||||
if (ts != null && ts.getValues().size() > 5) {
|
JSONArray response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONArray(tsList.stream().map(JsonTimeSeries::new).collect(Collectors.toList())));
|
||||||
JSONObject response = httpService.post(TIME_SERIES_GROUPED_TENDENCIES_URL, new JSONObject(new JsonTimeSeries(ts)));
|
|
||||||
LOG.debug("Send to group time series tendencies");
|
LOG.debug("Send to group time series tendencies");
|
||||||
if (response.has("response") && response.getString("response").equals("empty")) {
|
return JsonUtils.getListOfObjects(response)
|
||||||
return Optional.empty();
|
.stream()
|
||||||
}
|
.map(TimeSeries::new)
|
||||||
return Optional.of(new TimeSeries(response));
|
.collect(Collectors.toList());
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="t: ${ts}">
|
<tr th:each="t: ${groupedTs}">
|
||||||
<td><span class="badge badge-success" th:text="${t.name}"></span></td>
|
<td><span class="badge badge-success" th:text="${t.name}"></span></td>
|
||||||
<td><span class="badge badge-success" th:text="${#lists.size(t.values)}"></span></td>
|
<td><span class="badge badge-success" th:text="${#lists.size(t.values)}"></span></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user