Skip to content
Snippets Groups Projects
Unverified Commit b0413ac6 authored by BARBIER Marc's avatar BARBIER Marc
Browse files

simplifiew the windows fetching

parent c4fd0974
Branches
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -31,44 +32,24 @@ public class TableLoadController {
@Autowired
ProjectRepository repository;
/**
* CSV or ARFF
*/
@RequestMapping(value="/rest/load-data", method=RequestMethod.GET)
public @ResponseBody Table loadData(@RequestParam("pagination") String pagination, HttpServletRequest request)
@RequestMapping(value="/rest/load-data-windows", method=RequestMethod.GET)
public @ResponseBody Table loadData(@RequestParam("pagination") Optional<String> pagination, @RequestParam("id") Optional<String> id, HttpServletRequest request)
{
FileItem item = getCurrentItem(request.getSession());
if(item == null)
return null;
//Access database to get filename
if(!item.isArff() && !item.isCSV())
throw new RuntimeException("Only ARRF or CSV input expected");
System.out.println("rest>>loadData(" + item.getId() + "," + item + ")");
//Load ARRF or CSV file
if(pagination.equals("")){
pagination = "0-1000"; //default only first 1000 rows read
return loadDataWindows(Optional.of(true), pagination, id, request);
}
int from = Math.max(0, Integer.valueOf(pagination.split("-")[0]));
int to = Integer.valueOf(pagination.split("-")[1]);
try {
Table table = null;
if(item.isArff()){
table = new ArffDenseUtils().loadArff(item.getFile(), from, to);
}
else{
table = CSVUtils.loadCSV(item.getFile(), from, to);
}
return table;
}catch (IOException e) {
e.printStackTrace();
return null;
@RequestMapping(value="/rest/load-data", method=RequestMethod.GET)
public @ResponseBody Table loadDataWindows(@RequestParam("windowed") Optional<Boolean> windowed, @RequestParam("pagination") Optional<String> pagination, @RequestParam("id") Optional<String> id, HttpServletRequest request)
{
String page;
FileItem item = null;
if(id.isPresent()) {
item = repository.findItemById(id.get().trim());
}
if(item == null) {
item = getCurrentItem(request.getSession());
}
@RequestMapping(value="/rest/load-data-windows", method=RequestMethod.GET)
public @ResponseBody Table loadDataWindows(@RequestParam("pagination") String pagination, HttpServletRequest request)
{
FileItem item = getCurrentItem(request.getSession());
if(item == null)
return null;
//Access database to get filename
......@@ -76,15 +57,24 @@ public class TableLoadController {
throw new RuntimeException("ARRF input expected");
System.out.println("rest>>loadDataWindows(" + item.getId() + "," + item + ")");
//Load ARRF or CSV file
if(pagination.equals("")){
pagination = "0-1000"; //default only first 1000 rows read
if(pagination.isPresent() && pagination.get().equals("") || !pagination.isPresent()){
page = "0-1000"; //default only first 1000 rows read
} else {
page = pagination.get();
}
int from = Math.max(0, Integer.valueOf(pagination.split("-")[0]));
int to = Integer.valueOf(pagination.split("-")[1]);
File f = item.getFile();
int from = Math.max(0, Integer.valueOf(page.split("-")[0]));
int to = Integer.parseInt(page.split("-")[1]);
try {
Table tab = MakePatternOccurrences.groupByWindow(f,from,to);
return tab;
if(windowed.isPresent() && windowed.get()) {
return MakePatternOccurrences.groupByWindow(item.getFile(),from,to);
} else {
if(item.isArff()){
return new ArffDenseUtils().loadArff(item.getFile(), from, to);
}
else{
return CSVUtils.loadCSV(item.getFile(), from, to);
}
}
}catch (IOException e) {
e.printStackTrace();
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment