package com.iaskdata.controller;

import java.util.List;

import hex.genmodel.easy.exception.PredictException;

import com.iaskdata.service.PredictService;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;

/**
 * 功能接口
 * 
 */
public class FunctionController extends Controller {

	/**
	 * 获取系统时间
	 */
	@ActionKey("/gettime")
	public void getTime() {
		setAttr("status", 0);
		setAttr("ts", System.currentTimeMillis());
	}

	/**
	 * 模型训练接口
	 */
	@ActionKey("/train")
	public void train() {
		setAttr("status", -1);
		setAttr("msg", "Unimplemented");
		setAttr("ts", System.currentTimeMillis());

	}

	/**
	 * 模型預測接口
	 */
	@ActionKey("/predict")
	public void predict() {
		setAttr("status", 0);

		PredictService ps = new PredictService();
		try {
			List result = ps
					.predictHandle("loan_amnt=10000&emp_length=5&home_ownership=RENT&annual_inc=60000&verification_status=verified&purpose=debt_consolidation&addr_state=FL&dti=3&delinq_2yrs=0&revol_util=35&total_acc=4&longest_credit_length=10");
			setAttr("result", result);
		} catch (PredictException e) {
			setAttr("status", -1);
			setAttr("msg", "Unimplemented");
			setAttr("ts", System.currentTimeMillis());
			e.printStackTrace();
		}

	}

}

@@ -126,38 +126,305 @@
 com.
-iaskdata.service.PredictServic
+alibaba.fastjson.JSONObject;%0D%0Aimport com.iaskdata.interceptor.ContentTypeInterceptor;%0D%0Aimport com.iaskdata.interceptor.JSONInterceptor;%0D%0Aimport com.iaskdata.interceptor.MethodInterceptor;%0D%0Aimport com.iaskdata.service.PredictService;%0D%0Aimport com.iaskdata.util.Constant;%0D%0Aimport com.jfinal.aop.Befor
 e;%0D%0A
@@ -520,16 +520,18 @@
  %0D%0A */%0D%0A
+%0D%0A
 public c
@@ -649,24 +649,26 @@
 etTime() %7B%0D%0A
+%0D%0A
 %09%09setAttr(%22s
@@ -1019,18 +1019,55 @@
 %22, 0);%0D%0A
+%09%09this.getRequest().getQueryString();
 %0D%0A
-
 %09%09Predic
@@ -1110,16 +1110,19 @@
 %0A%09%09try %7B
+%09%09%09
 %0D%0A%09%09%09Lis
@@ -1160,216 +1160,42 @@
 dle(
-%22loan_amnt=10000&emp_length=5&home_ownership=RENT&annual_inc=60000&verification_status=verified&purpose=debt_consolidation&addr_state=FL&dti=3&delinq_2yrs=0&revol_util=35&total_acc=4&longest_credit_length=10%22
+this.getRequest().getQueryString()
 );%0D%0A

implement predict