// 通过给定的集合List<Webkpi> datas,得到json字符串(横坐标) public static String getCategory(List<WebKpi> datas) { StringBuffer sb = new StringBuffer(); sb.append("["); int size = datas.size(); for (int i = 0; i < size; i++) { WebKpi idw = datas.get(i); sb.append("\"" + DateUtils.dateToSimpleDateStr(idw.getTime(), "yyyy-MM-dd EE") + "\""); if (i != (size - 1)) { sb.append(","); } } sb.append("]"); JSONArray ja = JSONArray.fromObject(sb.toString()); return ja.toString(); }
// 通过给定的集合List<Webkpi> datas,得到json字符串(纵坐标) // 纵坐标又包含多个属性,如name、type、stack、smooth、symbol等等 public static String getValue(List<WebKpi> datas) { JSONArray ja = new JSONArray(); if (datas != null) { StringBuffer sb = new StringBuffer(); Map map = new HashMap(); String name = "PV"; String type = "line"; String stack = "总量"; boolean smooth = true; // 显示平滑曲线 String symbol = "emptyCircle"; // 显示符号 int size = datas.size(); List listPV = new ArrayList(); List listUV = new ArrayList(); List listVV = new ArrayList(); List listNewUV = new ArrayList(); for (WebKpi data : datas) { listPV.add(data.getPv()); listUV.add(data.getUv()); listVV.add(data.getVv()); listNewUV.add(data.getNewUv()); } String arr[] = new String[4]; List names = new ArrayList(); arr[0] = "PV"; names.add(arr[0]); arr[1] = "UV"; names.add(arr[1]); arr[2] = "访问次数"; names.add(arr[2]); arr[3] = "新独立访客"; names.add(arr[3]); map.put(names.get(0), listPV); map.put(names.get(1), listUV); map.put(names.get(2), listVV); map.put(names.get(3), listNewUV); Set set = map.keySet(); sb.append("["); for (int i = 0; i < names.size(); i++) { sb.append( "{\"name\":\"" + names.get(i) + "\",\"type\":\"" + type + "\",\"stack\": \"" + stack + "\",data:" + map.get(names.get(i)) + ",\"smooth\":" + smooth + ",\"symbol\":\"" + symbol + "\"}"); if (i != (names.size() - 1)) { sb.append(","); } } sb.append("]"); ja = JSONArray.fromObject(sb.toString()); } return ja.toString(); }
// 得到Webkpi中 平均时长的分钟+秒钟 public static String getTotalTimeByDatas(WebKpi iuniDaWebKpi) { long minute = iuniDaWebKpi.getTotalTime() / iuniDaWebKpi.getVv(); long second = iuniDaWebKpi.getTotalTime() % iuniDaWebKpi.getVv(); return minute + "分" + second + "秒"; }
// 通过对比字符串,返回特定的集合 // TODO 有问题,需调整 public static List<Object> getListByString(List<WebKpi> datas, String str) { if (str != null && !"".equals(str)) { List<Object> list = new ArrayList<Object>(); for (WebKpi data : datas) { if ("PV".equals(str)) { list.add(data.getPv()); } else if ("UV".equals(str)) { list.add(data.getUv()); } else if ("IP".equals(str)) { list.add(data.getIp()); } else if ("新独立访客".equals(str)) { list.add(data.getNewUv()); } else if ("访问次数".equals(str)) { list.add(data.getVv()); } else if ("人均浏览页面数".equals(str)) { list.add(new DecimalFormat("0.0").format(data.getPv() / data.getUv())); } else if ("平均访问深度".equals(str)) { list.add(new DecimalFormat("0.0").format(data.getPv() / data.getVv())); } else if ("平均访问时长".equals(str)) { list.add(data.getTotalTime() / data.getVv() + data.getTotalTime() % data.getVv()); System.out.println((long) data.getTotalTime() / (long) data.getVv()); } else if ("跳出率".equals(str)) { list.add( new DecimalFormat("00.00") .format((new Double(data.getTotalJump()) / new Double(data.getVv())) * 100)); System.out.println( new DecimalFormat("0.00%") .format((new Double(data.getTotalJump()) / new Double(data.getVv())))); } } return list; } else { return null; } }