public boolean validate() { if (element.getDimCount() > 2) { chartMessages.add( "The query has " + element.getDimColNames() + " dimensions. Minimum one and maximum two dimensions are supported."); return false; } if (element.getMetricCount() > 4) { chartMessages.add( "The query has " + element.getMetricColNames() + " metrics. At max only 4 metrics can be graphed."); return false; } if (this.element.getChartType().equalsIgnoreCase(DashboardConstants.PIE_CHART_TYPE)) if (element.getDimCount() != 1) { chartMessages.add( "The query has " + element.getDimColNames() + " dimension. Pie chart is supported with only one dimension."); return false; } else if (element.getMetricCount() != 1) { chartMessages.add( "The query has " + element.getMetricColNames() + " metrics. Pie chart is supported with only one metric."); return false; } return true; }
protected String getRawHeaderString() { StringBuffer html = new StringBuffer(); List<Object> headers = element.getHeader(); if (headers != null) { for (int i = 0; i < headers.size(); i++) { String head = ((String) headers.get(i)).replaceAll("'", ""); String hs[] = head.split(":"); headerIndexToTypeMap.put(i, hs[0]); html.append("data.addColumn('" + hs[0] + "', '" + hs[1] + "');\n"); } } return html.toString(); }
protected String getSimpleProcessedDataSetString() { StringBuffer htmlDataSet = new StringBuffer(); List<List<Object>> rows = element.getData(); if (rows == null) return ""; for (List<Object> row : rows) { StringBuffer rowData = new StringBuffer(); rowData.append("["); StringBuffer rowBuffer = new StringBuffer(); String timeColumn = ""; for (int i = 0; i < row.size(); i++) { Object column = row.get(i); if (column == null) { String dataType = headerIndexToTypeMap.get(i); if (dataType.equalsIgnoreCase(DashboardConstants.STRING)) rowBuffer.append("'',"); else if (dataType.equalsIgnoreCase(DashboardConstants.DATETIME)) rowBuffer.append("'',"); else rowBuffer.append("null,"); } else { String dataType = headerIndexToTypeMap.get(i); if (dataType.equalsIgnoreCase(DashboardConstants.STRING)) { rowBuffer.append("'" + column.toString() + "',"); } else if (dataType.equalsIgnoreCase(DashboardConstants.DATETIME)) { try { Date ts = sdf.parse(column.toString()); String timeString = (ts.getYear() + 1900) + "," + (ts.getMonth()) + "," + ts.getDate() + "," + ts.getHours() + "," + ts.getMinutes(); timeColumn = "new Date(" + timeString + "),"; } catch (ParseException e) { rowBuffer.append("'" + column.toString() + "',"); e.printStackTrace(); } } else rowBuffer.append(column.toString() + ","); } } if (timeColumn != null && !timeColumn.isEmpty()) rowData.append(timeColumn); rowData.append(rowBuffer.subSequence(0, rowBuffer.lastIndexOf(",")) + "],\n"); htmlDataSet.append(rowData); } if (htmlDataSet.lastIndexOf(",") > 1) return htmlDataSet.subSequence(0, htmlDataSet.lastIndexOf(",")) + "\n"; else return htmlDataSet.toString(); }
protected String getSimpleProcessedHeaderString() { StringBuffer toReturn = new StringBuffer(); StringBuffer html = new StringBuffer(); String keyColumn = ""; String timeColumn = ""; List<Object> headers = element.getHeader(); if (headers != null) { for (int i = 0; i < headers.size(); i++) { String head = ((String) headers.get(i)).replaceAll("'", ""); String hs[] = head.split(":"); headerIndexToTypeMap.put(i, hs[0]); if (hs[0].equalsIgnoreCase("string")) keyColumn = keyColumn + "data.addColumn('string','" + hs[1] + "');\n"; else if (hs[0].equalsIgnoreCase("datetime")) timeColumn = "data.addColumn('datetime','Time');\n"; else html.append("data.addColumn('" + hs[0] + "', '" + hs[1] + "');\n"); } } if (timeColumn != null && !timeColumn.isEmpty()) toReturn.append(timeColumn); if (keyColumn != null && !keyColumn.isEmpty()) toReturn.append(keyColumn); toReturn.append(html); return toReturn.toString(); }
private void normalizeData() { List<Object> headers = element.getHeader(); if (headers != null) { for (int i = 0; i < headers.size(); i++) { String head = ((String) headers.get(i)).replaceAll("'", ""); String hs[] = head.split(":"); headerIndexToTypeMap.put(i, hs[0]); indexToName.put(i, hs[1]); } } List<List<Object>> rows = element.getData(); if (rows == null) return; int maxIndex = 0; for (List<Object> row : rows) { String keyColumn = ""; Date timeStamp = null; int keyCount = 0; int timeCount = 0; List<Object> tempRow = new ArrayList<Object>(); for (int i = 0; i < row.size(); i++) { Object column = row.get(i); String dataType = headerIndexToTypeMap.get(i); if (dataType.equalsIgnoreCase(DashboardConstants.STRING)) { keyColumn = keyColumn + "_" + column.toString(); keyCount++; } else if (dataType.equalsIgnoreCase(DashboardConstants.DATETIME)) { timeCount++; try { timeStamp = sdf.parse(column.toString()); } catch (ParseException e) { e.printStackTrace(); } } else { tempRow.add(i + ":" + column); } } if (timeSeriesChart == false && timeCount > 0) timeSeriesChart = true; if (isSimpleDataSet == true && keyCount > 1) isSimpleDataSet = false; if (timeSeriesChart) isSimpleDataSet = false; for (Object r : tempRow) { String patterns[] = r.toString().split(":"); int index = Integer.parseInt(patterns[0]); String headerName = indexToName.get(index); String lookupKey = keyColumn + "_" + headerName; Integer ind = newHeaderToIndex.get(lookupKey); if (ind == null) { ind = maxIndex; newHeaderToIndex.put(lookupKey, maxIndex++); } if (timeSeriesChart) { Object rsd[] = timeSeries.get(timeStamp.getTime()); if (rsd == null) { rsd = new Object[100]; timeSeries.put(timeStamp.getTime(), rsd); } rsd[ind] = patterns[1]; } else { Object rsd[] = keySeries.get(keyColumn); if (rsd == null) { rsd = new Object[100]; keySeries.put(keyColumn, rsd); } rsd[ind] = patterns[1]; } } } }