make it possible to specify the time in the range

This commit is contained in:
2017-03-27 19:38:02 +02:00
parent 364997e611
commit 726258020f
5 changed files with 32 additions and 10 deletions

View File

@@ -1,14 +1,17 @@
package org.lucares.pdb.plot.api; package org.lucares.pdb.plot.api;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
public class PlotSettings { public class PlotSettings {
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private String query; private String query;
private int height; private int height;
@@ -95,7 +98,7 @@ public class PlotSettings {
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC); return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
} else { } else {
return LocalDate.parse(dateFrom).atTime(OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC)); return LocalDateTime.parse(dateFrom, DATE_FORMAT).atOffset(ZoneOffset.UTC);
} }
} }
@@ -103,7 +106,7 @@ public class PlotSettings {
if (StringUtils.isEmpty(dateTo)) { if (StringUtils.isEmpty(dateTo)) {
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC); return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
} else { } else {
return LocalDate.parse(dateTo).atTime(OffsetTime.of(23, 59, 59, 999_999_999, ZoneOffset.UTC)); return LocalDateTime.parse(dateTo, DATE_FORMAT).atOffset(ZoneOffset.UTC);
} }
} }
} }

View File

@@ -13,6 +13,9 @@ dependencies {
compile project(':performanceDb') compile project(':performanceDb')
compile project(':pdb-plotting') compile project(':pdb-plotting')
compile('org.springframework.boot:spring-boot-starter-mustache:1.5.2.RELEASE') {
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE"){ compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE"){
exclude module: 'spring-boot-starter-logging' exclude module: 'spring-boot-starter-logging'
} }

View File

@@ -2,9 +2,13 @@ package org.lucares.pdbui;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.lucares.ludb.FieldNotExistsException; import org.lucares.ludb.FieldNotExistsException;
import org.lucares.ludb.Proposal; import org.lucares.ludb.Proposal;
@@ -23,12 +27,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller @Controller
@EnableAutoConfiguration @EnableAutoConfiguration
@@ -36,6 +42,9 @@ public class PdbController implements HardcodedValues, CollectionUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(PdbController.class); private static final Logger LOGGER = LoggerFactory.getLogger(PdbController.class);
private static final DateTimeFormatter DATE_FORMAT_BEGIN = DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00");
private static final DateTimeFormatter DATE_FORMAT_END = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");
private final Plotter plotter; private final Plotter plotter;
private final PdbRepository db; private final PdbRepository db;
@@ -44,6 +53,15 @@ public class PdbController implements HardcodedValues, CollectionUtils {
this.plotter = plotter; this.plotter = plotter;
} }
@GetMapping("/")
public ModelAndView index() {
final String view = "main";
final Map<String, Object> model = new HashMap<>();
model.put("oldestValue", LocalDateTime.now().minusYears(1).format(DATE_FORMAT_BEGIN));
model.put("latestValue", LocalDateTime.now().format(DATE_FORMAT_END));
return new ModelAndView(view, model);
}
@RequestMapping(path = "/plots", // @RequestMapping(path = "/plots", //
method = RequestMethod.POST, // method = RequestMethod.POST, //
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, // consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, //

View File

@@ -66,7 +66,7 @@ function renderGroupBy()
}; };
var error = function(e) { var error = function(e) {
$('#result-view').text("FAILED: " + JSON.stringify(e)); $('#result-view').text("FAILED: " + JSON.parse(e.responseText).message);
}; };
@@ -78,7 +78,6 @@ function showLoadingIcon()
$('#result-view').html("<div class='center'><div class='uil-cube-css' style='-webkit-transform:scale(0.41)'><div /><div></div><div></div><div></div></div></div>"); $('#result-view').html("<div class='center'><div class='uil-cube-css' style='-webkit-transform:scale(0.41)'><div /><div></div><div></div><div></div></div></div>");
} }
function plot(event){ function plot(event){
event.preventDefault(); // prevent submit of form which would reload the page event.preventDefault(); // prevent submit of form which would reload the page
@@ -104,11 +103,10 @@ function plot(event){
$('#result-view').text("No data points found."); $('#result-view').text("No data points found.");
} }
else{ else{
$('#result-view').text("FAILED: " + JSON.stringify(e)); $('#result-view').text("FAILED: " + JSON.parse(e.responseText).message);
} }
}; };
postJson("plots", request, success, error); postJson("plots", request, success, error);
} }

View File

@@ -30,10 +30,10 @@
<input type="number" id="search-limit-value" name="search-limit-value" min="1" max="1000" value="10"/> <input type="number" id="search-limit-value" name="search-limit-value" min="1" max="1000" value="10"/>
<label for="search-date-from">From Date:</label> <label for="search-date-from">From Date:</label>
<input id="search-date-from" class="input_date" type="date"> <input id="search-date-from" class="input_date" type="text" value="{{oldestValue}}">
<label for="search-date-to">To Date:</label> <label for="search-date-to">To Date:</label>
<input id="search-date-to" class="input_date" type="date"> <input id="search-date-to" class="input_date" type="text" value="{{latestValue}}">
<button id="search-submit"><i class="fa fa-area-chart"> Plot</i></button> <button id="search-submit"><i class="fa fa-area-chart"> Plot</i></button>
</div> </div>