3-add-f-transform #4

Merged
romanov73 merged 3 commits from 3-f-transform into master 2022-04-19 22:20:08 +04:00
4 changed files with 45 additions and 29 deletions
Showing only changes of commit 3e26083765 - Show all commits

View File

@ -55,31 +55,6 @@ public class IndexController {
return "index";
}
@GetMapping("/method")
public String method(Model model) throws IOException {
model.addAttribute("sets", dbService.getSets());
model.addAttribute("methods", timeSeriesService.getAvailableMethods());
model.addAttribute("chartForm", new ChartForm());
return "method";
}
@GetMapping("chartMethod")
public String chartMethod(@ModelAttribute ChartForm chartForm, Model model) throws IOException, ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
model.addAttribute("sets", dbService.getSets());
model.addAttribute("methods", timeSeriesService.getAvailableMethods());
if (chartForm.getSet() != null && !chartForm.getSet().getKey().equals("")) {
model.addAttribute("listTimeSeries", dbService.getTimeSeriesMeta(chartForm.getSet()));
}
if (chartForm.getTimeSeriesMeta() != null
&& chartForm.getTimeSeriesMeta().getKey() != null
&& !chartForm.getTimeSeriesMeta().getKey().isEmpty()
&& chartForm.getMethodClassName() != null
&& !chartForm.getMethodClassName().equals("")) {
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), chartForm.getMethodClassName(), model);
}
return "method";
}
private void addChartToModel(TimeSeries timeSeries, String method, Model model) throws ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ModelingException {
int countForecastPoints = timeSeries.getLength() > 20 ? 10 : timeSeries.getLength() / 3;
TimeSeries timeSeriesModel;
@ -95,7 +70,18 @@ public class IndexController {
TimeSeries testForecast = modelingResult.getTestForecast();
model.addAttribute("dates", getDatesForChart(timeSeries, forecast));
model.addAttribute("timeSeries", timeSeries.getValues().stream().map(TimeSeriesValue::getValue).toArray());
model.addAttribute("model", timeSeriesModel.getValues().stream().map(TimeSeriesValue::getValue).toArray());
// если временной ряд был сжат моделью, то для графика нужно вставить пустые значения
TimeSeries modelWithSkips = new TimeSeries(timeSeriesModel.getKey());
int j = 0;
for (int i = 0; i < timeSeries.getLength(); i++) {
if (timeSeries.getValue(i).getDate().equals(timeSeriesModel.getValue(j).getDate())) {
modelWithSkips.addValue(timeSeriesModel.getValue(j));
j++;
} else {
modelWithSkips.addValue(new TimeSeriesValue((Double) null));
}
}
model.addAttribute("model", modelWithSkips.getValues().stream().map(TimeSeriesValue::getValue).toArray());
timeSeries.getValues().remove(timeSeries.getValues().size() - 1);
List<Double> forecastValues = timeSeries.getValues().stream().map(v -> (Double) null).collect(Collectors.toList());
@ -121,4 +107,29 @@ public class IndexController {
.collect(Collectors.toList());
}
@GetMapping("/method")
public String method(Model model) throws IOException {
model.addAttribute("sets", dbService.getSets());
model.addAttribute("methods", timeSeriesService.getAvailableMethods());
model.addAttribute("chartForm", new ChartForm());
return "method";
}
@GetMapping("chartMethod")
public String chartMethod(@ModelAttribute ChartForm chartForm, Model model) throws IOException, ModelingException, ExecutionException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
model.addAttribute("sets", dbService.getSets());
model.addAttribute("methods", timeSeriesService.getAvailableMethods());
if (chartForm.getSet() != null && !chartForm.getSet().getKey().equals("")) {
model.addAttribute("listTimeSeries", dbService.getTimeSeriesMeta(chartForm.getSet()));
}
if (chartForm.getTimeSeriesMeta() != null
&& chartForm.getTimeSeriesMeta().getKey() != null
&& !chartForm.getTimeSeriesMeta().getKey().isEmpty()
&& chartForm.getMethodClassName() != null
&& !chartForm.getMethodClassName().equals("")) {
addChartToModel(dbService.getTimeSeries(chartForm.getSet(), chartForm.getTimeSeriesMeta().getKey()), chartForm.getMethodClassName(), model);
}
return "method";
}
}

View File

@ -35,6 +35,7 @@ public class DbFileService implements DbService {
createDbIfNotExists();
return Arrays.stream(Objects.requireNonNull(new File(timeSeriesDbPath).listFiles(File::isDirectory)))
.map(TimeSeriesSet::new)
.sorted()
.collect(Collectors.toList());
}
@ -47,7 +48,7 @@ public class DbFileService implements DbService {
.readValue(Paths.get(getSetPath(timeSeriesSet).getAbsolutePath(), file.getName())
.toFile(), TimeSeriesMeta.class));
}
return list;
return list.stream().sorted().collect(Collectors.toList());
}
@Override

View File

@ -17,7 +17,7 @@ public class FTransform extends Method {
List<MethodParamValue> parameters) {
FTransformModel model = new FTransformModel(ts, parameters);
List<AComponent> aComponents = generateAComponents(ts, model.getNumberOfCoveredPoints().getIntValue(), model.getAComponents());
;
TimeSeries piecewiseLinearTrend = model.getPiecewiseLinearTrend();
TimeSeries tsModel = model.getTimeSeriesModel();
@ -42,7 +42,7 @@ public class FTransform extends Method {
int startPoint = (currentPoint == 0)
? 0
: piecewiseLinearTrend.get(piecewiseLinearTrend.size() - 1).getTop();
AComponent bf = new AComponent(startPoint, currentPoint, currentPoint + numberOfCoveredPoints / 2);
AComponent bf = new AComponent(startPoint, currentPoint, (int) (currentPoint + Math.round(numberOfCoveredPoints / 2.0)));
if (bf.getStart() < 0) {
bf.setStart(0);
}

View File

@ -63,21 +63,25 @@
{
name: [[#{messages.time_series}]],
color: 'rgba(119,152,191,0.5)',
connectNulls: true,
data: [[${timeSeries}]]
},
{
name: [[#{messages.time_series_model}]],
color: 'rgba(255,200,0,0.5)',
connectNulls: true,
data: [[${model}]]
},
{
name: [[#{messages.time_series_test_forecast}]],
color: 'rgba(255,0,0,0.5)',
connectNulls: true,
data: [[${testForecast}]]
},
{
name: [[#{messages.time_series_forecast_short}]],
color: 'rgba(255,0,0,0.5)',
connectNulls: true,
data: [[${forecast}]]
}
];