Merge branch '3-jfs-page-for-demo' into 'master'
Resolve "JFS page for demo" Closes #3 See merge request romanov73/time-series-smoothing!3
This commit is contained in:
commit
4a78171fe5
10
build.gradle
10
build.gradle
@ -9,7 +9,11 @@ jar {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://repository.primefaces.org/"
|
||||
}
|
||||
}
|
||||
|
||||
sourceCompatibility = 11
|
||||
@ -23,11 +27,15 @@ dependencies {
|
||||
versionSwagger = '2.5.0'
|
||||
}
|
||||
|
||||
|
||||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
|
||||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
|
||||
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
|
||||
implementation group: 'org.slf4j', name: 'slf4j-api', version: versionSLF4J
|
||||
implementation group: 'org.primefaces', name: 'primefaces', version: '7.0'
|
||||
implementation group: 'net.bootsfaces', name: 'bootsfaces', version: '1.4.2'
|
||||
implementation group: 'org.joinfaces', name: 'jsf-spring-boot-starter', version: '4.0.8'
|
||||
implementation group: 'org.javassist', name: 'javassist', version: '3.25.0-GA'
|
||||
implementation group: 'org.primefaces.themes', name: 'all-themes', version: '1.0.10'
|
||||
|
||||
implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: versionJetty
|
||||
|
||||
|
@ -22,10 +22,12 @@ public class TimeSeriesUtils {
|
||||
}
|
||||
|
||||
public static TimeSeries fillDates(TimeSeries timeSeries, long milliseconds) {
|
||||
if (!timeSeries.isEmpty()) {
|
||||
timeSeries.getLastValue().setDate(LocalDateTime.now());
|
||||
for (int i = timeSeries.getLength() - 2; i >= 0; i--) {
|
||||
timeSeries.getValues().get(i).setDate(timeSeries.getValues().get(i + 1).getDate().minus(milliseconds, ChronoUnit.MILLIS));
|
||||
}
|
||||
}
|
||||
return timeSeries;
|
||||
}
|
||||
|
||||
|
14
src/main/java/ru/ulstu/configurations/MvcConfiguration.java
Normal file
14
src/main/java/ru/ulstu/configurations/MvcConfiguration.java
Normal file
@ -0,0 +1,14 @@
|
||||
package ru.ulstu.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MvcConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addRedirectViewController("/", "/index.xhtml");
|
||||
registry.addRedirectViewController("/default", "/index.xhtml");
|
||||
}
|
||||
}
|
96
src/main/java/ru/ulstu/pages/IndexView.java
Normal file
96
src/main/java/ru/ulstu/pages/IndexView.java
Normal file
@ -0,0 +1,96 @@
|
||||
package ru.ulstu.pages;
|
||||
|
||||
import org.primefaces.model.chart.AxisType;
|
||||
import org.primefaces.model.chart.DateAxis;
|
||||
import org.primefaces.model.chart.LegendPlacement;
|
||||
import org.primefaces.model.chart.LineChartModel;
|
||||
import org.primefaces.model.chart.LineChartSeries;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import ru.ulstu.models.TimeSeries;
|
||||
import ru.ulstu.models.TimeSeriesValue;
|
||||
import ru.ulstu.models.exceptions.ModelingException;
|
||||
import ru.ulstu.services.TimeSeriesService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import java.io.Serializable;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Named
|
||||
@ViewScoped
|
||||
public class IndexView implements Serializable {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(IndexView.class);
|
||||
private LineChartModel model;
|
||||
private String timeSeriesString = "1,2,3";
|
||||
|
||||
@Autowired
|
||||
private TimeSeriesService timeSeriesService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
createChart();
|
||||
}
|
||||
|
||||
private LineChartModel initLinearModel() {
|
||||
LineChartModel model = new LineChartModel();
|
||||
|
||||
LineChartSeries series1 = new LineChartSeries();
|
||||
series1.setLabel("Временной ряд");
|
||||
|
||||
TimeSeries timeSeries = timeSeriesService.getTimeSeriesFromString(timeSeriesString);
|
||||
for (TimeSeriesValue value : timeSeries.getValues()) {
|
||||
series1.set(DateTimeFormatter.ISO_LOCAL_DATE.format(value.getDate()), value.getValue());
|
||||
}
|
||||
|
||||
LineChartSeries series2 = new LineChartSeries();
|
||||
series2.setLabel("Сглаженный ряд");
|
||||
try {
|
||||
for (TimeSeriesValue value : timeSeriesService.getForecast(timeSeries, 10).getModel().getModelTimeSeries().getValues()) {
|
||||
series2.set(DateTimeFormatter.ISO_LOCAL_DATE.format(value.getDate()), value.getValue());
|
||||
}
|
||||
} catch (ModelingException ex) {
|
||||
LOG.warn(ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
LineChartSeries series3 = new LineChartSeries();
|
||||
series3.setLabel("Прогноз");
|
||||
try {
|
||||
for (TimeSeriesValue value : timeSeriesService.getForecast(timeSeries, 10).getForecastTimeSeries().getValues()) {
|
||||
series3.set(DateTimeFormatter.ISO_LOCAL_DATE.format(value.getDate()), value.getValue());
|
||||
}
|
||||
} catch (ModelingException ex) {
|
||||
LOG.warn(ex.getMessage());
|
||||
}
|
||||
model.addSeries(series1);
|
||||
model.addSeries(series2);
|
||||
model.addSeries(series3);
|
||||
return model;
|
||||
}
|
||||
|
||||
public void createChart() {
|
||||
model = initLinearModel();
|
||||
model.setTitle("Сглаживание временного ряда");
|
||||
model.setLegendPosition("d");
|
||||
model.setLegendPlacement(LegendPlacement.OUTSIDE);
|
||||
DateAxis xAxis = new DateAxis("Time");
|
||||
xAxis.setTickFormat("%#d %b %Y");
|
||||
model.getAxes().put(AxisType.X, xAxis);
|
||||
}
|
||||
|
||||
public LineChartModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getTimeSeriesString() {
|
||||
createChart();
|
||||
return timeSeriesString;
|
||||
}
|
||||
|
||||
public void setTimeSeriesString(String timeSeriesString) {
|
||||
this.timeSeriesString = timeSeriesString;
|
||||
}
|
||||
}
|
44
src/main/resources/META-INF/resources/basicTemplate.xhtml
Normal file
44
src/main/resources/META-INF/resources/basicTemplate.xhtml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://java.sun.com/jsf/html"
|
||||
xmlns:p="http://primefaces.org/ui"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
|
||||
|
||||
<h:head>
|
||||
<title>Time series smoothing</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<h:outputStylesheet name="css/style.css"/>
|
||||
</h:head>
|
||||
|
||||
<h:body>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12">
|
||||
<p:outputPanel>
|
||||
<p:growl id="msgs" showDetail="true"/>
|
||||
<a href="/index.xhtml">
|
||||
<img src="/img/logo.png" alt="" width="100"/>
|
||||
</a>
|
||||
</p:outputPanel>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12">
|
||||
<ui:insert name="content">Content</ui:insert>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12">
|
||||
<p:outputPanel>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12 ui-md-12 ui-lg-4">Ulyanovsk State Technical University</div>
|
||||
<div class="ui-g-6 ui-md-6 ui-lg-4"><h:outputLink
|
||||
value="http://ulstu.ru">ulstu.ru</h:outputLink></div>
|
||||
<div class="ui-g-6 ui-md-6 ui-lg-4">2020</div>
|
||||
</div>
|
||||
</p:outputPanel>
|
||||
</div>
|
||||
</div>
|
||||
</h:body>
|
||||
</html>
|
7
src/main/resources/META-INF/resources/css/style.css
Normal file
7
src/main/resources/META-INF/resources/css/style.css
Normal file
@ -0,0 +1,7 @@
|
||||
.ui-picklist-list-wrapper {
|
||||
width: 50% !important;
|
||||
}
|
||||
|
||||
.ui-picklist-list {
|
||||
width: 100% !important;
|
||||
}
|
BIN
src/main/resources/META-INF/resources/img/logo.jpg
Normal file
BIN
src/main/resources/META-INF/resources/img/logo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
BIN
src/main/resources/META-INF/resources/img/logo.png
Normal file
BIN
src/main/resources/META-INF/resources/img/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
29
src/main/resources/META-INF/resources/index.xhtml
Normal file
29
src/main/resources/META-INF/resources/index.xhtml
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
|
||||
xmlns:p="http://primefaces.org/ui"
|
||||
xmlns:h="http://java.sun.com/jsf/html">
|
||||
<ui:composition template="/basicTemplate.xhtml">
|
||||
<ui:define name="content">
|
||||
<h:form>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12 ui-md-12 ui-lg-12">
|
||||
<p:inputTextarea id="timeSeriesString" style="height:200px; width:100%;"
|
||||
placeholder="Paste time series here"
|
||||
autoResize="false" value="#{indexView.timeSeriesString}">
|
||||
<p:ajax event="change" update="chart"/>
|
||||
<p:ajax event="keypress" update="chart"/>
|
||||
</p:inputTextarea>
|
||||
<p:commandButton value="Refresh" update="chart" process="timeSeriesString"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui-g">
|
||||
<div class="ui-g-12 ui-md-12 ui-lg-12">
|
||||
<p:chart id="chart" type="line" model="#{indexView.model}" style="height:300px;"/>
|
||||
</div>
|
||||
</div>
|
||||
</h:form>
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
</html>
|
@ -1,5 +1,6 @@
|
||||
spring.main.banner-mode=off
|
||||
logging.level.tech.athene=DEBUG
|
||||
server.port=8080
|
||||
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
joinfaces.primefaces.theme=afterwork
|
||||
joinfaces.primefaces.font-awesome=true
|
Loading…
Reference in New Issue
Block a user