~ small fixes and code cleanup
Signed-off-by: Johannes Theiner <j.theiner@live.de> #SPM-31: add work 20m testing
This commit is contained in:
parent
243eb1c7f9
commit
3fa8de6df4
|
@ -27,14 +27,12 @@ public class ShoppingCart implements Analysis<Map<List<String>, List<String>>> {
|
|||
|
||||
@Override
|
||||
public Map<List<String>, List<String>> getResult() {
|
||||
if(result != null) {
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = new HashMap<>();
|
||||
|
||||
Apriori model = new Apriori();
|
||||
|
||||
for (int i = 0; i < 11; i++) {
|
||||
instances.deleteAttributeAt(0);
|
||||
}
|
||||
|
@ -60,6 +58,8 @@ public class ShoppingCart implements Analysis<Map<List<String>, List<String>>> {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Apriori model = new Apriori();
|
||||
|
||||
model.setTreatZeroAsMissing(true);
|
||||
try {
|
||||
model.buildAssociations(instances);
|
||||
|
@ -67,19 +67,19 @@ public class ShoppingCart implements Analysis<Map<List<String>, List<String>>> {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(int i = 0; i < model.getAssociationRules().getRules().size();i++){
|
||||
for (int i = 0; i < model.getAssociationRules().getRules().size(); i++) {
|
||||
AssociationRule rule = model.getAssociationRules().getRules().get(i);
|
||||
|
||||
List<String> l1 = new ArrayList<>();
|
||||
for(Item item : rule.getPremise()){
|
||||
for (Item item : rule.getPremise()) {
|
||||
l1.add(item.getAttribute().name());
|
||||
}
|
||||
List<String> l2 = new ArrayList<>();
|
||||
for(Item item : rule.getConsequence()){
|
||||
for (Item item : rule.getConsequence()) {
|
||||
l2.add(item.getAttribute().name());
|
||||
}
|
||||
|
||||
result.put(l1,l2);
|
||||
result.put(l1, l2);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,33 @@ package de.hsel.spm.baudas.web;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* all possible error codes.
|
||||
*
|
||||
* @author Julian Hinxlage
|
||||
* @version 0.1
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErrorCode {
|
||||
FILE_NOT_FOUND ("Die Hochgeladene Datei konnte nicht gefunden werden"),
|
||||
EMPTY_FILE ("Die Hochgeladene Datei ist leer"),
|
||||
INVALID_FORMAT("Die Hochgeladene Datei hat ein falsches Format");
|
||||
FILE_NOT_FOUND("Die hochgeladene Datei konnte nicht gefunden werden"),
|
||||
EMPTY_FILE("Die hochgeladene Datei ist leer"),
|
||||
INVALID_FORMAT("Die hochgeladene Datei hat ein falsches Format");
|
||||
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* is there a error code with this name ?.
|
||||
*
|
||||
* @param message string to search for
|
||||
* @return error code exits ?
|
||||
*/
|
||||
public static boolean exists(String message) {
|
||||
for (ErrorCode code : values()) {
|
||||
System.out.println(message + " == " + code.name());
|
||||
if (code.name().equals(message))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.nio.file.StandardCopyOption;
|
|||
/**
|
||||
* saves uploaded files.
|
||||
*
|
||||
* @author Johannes Theiner
|
||||
* @author Johannes Theiner, Julian Hinxlage
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
@ -32,56 +32,60 @@ public class Upload extends HttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 14144111845151L;
|
||||
|
||||
|
||||
/**
|
||||
* let weka check if the format is valid.
|
||||
*
|
||||
* @param stream input stream
|
||||
* @return format valid
|
||||
*/
|
||||
private boolean checkFormat(InputStream stream) {
|
||||
CSVLoader loader = new CSVLoader();
|
||||
try {
|
||||
loader.setSource(stream);
|
||||
return loader.getDataSet() != null;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
protected void doPost(@NotNull HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
|
||||
Part filePart = req.getPart("file");
|
||||
|
||||
if(filePart == null){
|
||||
if (filePart == null) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.FILE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
if(filePart.getSubmittedFileName() == null){
|
||||
if (filePart.getSubmittedFileName() == null) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.FILE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString();
|
||||
|
||||
if(fileName == null){
|
||||
if (fileName == null) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.FILE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream inputStream = filePart.getInputStream();
|
||||
|
||||
if(inputStream == null){
|
||||
if (inputStream == null) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.FILE_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
if(inputStream.available() == 0) {
|
||||
if (inputStream.available() == 0) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.EMPTY_FILE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!checkFormat(inputStream)){
|
||||
if (!checkFormat(inputStream)) {
|
||||
resp.sendRedirect("error.jsp?code=" + ErrorCode.INVALID_FORMAT);
|
||||
return;
|
||||
}else{
|
||||
} else {
|
||||
inputStream = filePart.getInputStream();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: julian
|
||||
Date: 21.05.19
|
||||
Time: 14:21
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
|
||||
<%@ page import="java.nio.charset.StandardCharsets" %>
|
||||
<%@ page import="de.hsel.spm.baudas.web.ErrorCode" %>
|
||||
<%@ page import="java.nio.charset.StandardCharsets" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="java.util.Arrays" %>
|
||||
<%@ page import="java.util.ArrayList" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||
<%@include file="emptyHeader.jsp"%>
|
||||
<% response.setCharacterEncoding(StandardCharsets.UTF_8.name()); %>
|
||||
|
@ -15,7 +10,8 @@
|
|||
|
||||
<%
|
||||
String code = request.getParameter("code");
|
||||
if(code != null){
|
||||
|
||||
if(code != null && ErrorCode.exists(code)){
|
||||
ErrorCode errorCode = ErrorCode.valueOf(code);
|
||||
%>
|
||||
|
||||
|
|
Loading…
Reference in New Issue