Esempio n. 1
0
  private static String CreateGoogleDataTableJSON(boolean F, TemperatureSet... TSList) {

    /* merge temperature data sets */
    OrderedMap<Long, Double[]> rowMap = _MergeDataSets(F, TSList);

    /* create JSON "cols" Object */
    JSON._Array dataTable_cols = new JSON._Array();
    // -- DateTime
    JSON._Object col_dateTime = (new JSON._Object()).setFormatIndent(false);
    col_dateTime.addKeyValue("id", "date");
    col_dateTime.addKeyValue("label", "Date/Time");
    col_dateTime.addKeyValue("type", "datetime");
    dataTable_cols.addValue(col_dateTime);
    // -- data set titles
    if (!ListTools.isEmpty(TSList)) {
      for (int d = 0; d < TSList.length; d++) {
        TemperatureSet TS = TSList[d];
        JSON._Object col_temp = (new JSON._Object()).setFormatIndent(false);
        col_temp.addKeyValue("id", "temp" + (d + 1));
        col_temp.addKeyValue("label", "Temp-" + (d + 1));
        col_temp.addKeyValue("type", "number");
        dataTable_cols.addValue(col_temp);
      }
    }

    /* create JSON "rows" Object */
    JSON._Array dataTable_rows = new JSON._Array();
    for (Long ts : rowMap.keySet()) {
      JSON._Object col = new JSON._Object();
      // TODO
    }

    /* return */
    return null; // TODO:
  }
Esempio n. 2
0
  /**
   * ** Creates a Google DataTable containing the specified TemperatureSet Data ** @param F True for
   * Fahrenheit, false for Celsius ** @param TSList The TemperatureSet data array ** @return The
   * "DataTable" String.
   */
  public static String CreateGoogleDataTableJavaScript(boolean F, TemperatureSet... TSList) {
    // {
    //   cols: [
    //       { id: "date" , label: "Date/Time", type: "datetime" },
    //       { id: "temp1", label: "Temp-1"   , type: "number"   },
    //       { id: "temp2", label: "Temp-2"   , type: "number"   }
    //   ],
    //   rows: [
    //       { c: [ { v: new Date(1383914237000) }, { v: -12.6 }, { v: -18.1 } ] },
    //       { c: [ { v: new Date(1384914237000) }, { v:  -5.1 }, { v:  -7.3 } ] },
    //       { c: [ { v: new Date(1385914345000) }, { v:  null }, { v:  -2.1 } ] },
    //       { c: [ { v: new Date(1386924683000) }, { v:  -2.0 }, { v:  null } ] },
    //       { c: [ { v: new Date(1387934245000) }, { v:   5.8 }, { v:   6.7 } ] }
    //   ]
    // }

    /* merge temperature data sets */
    OrderedMap<Long, Double[]> rowMap = _MergeDataSets(F, TSList);

    /* init */
    StringBuffer sb = new StringBuffer();
    sb.append("{").append("\n");

    /* "cols" */
    sb.append("  cols: [").append("\n");
    // --
    sb.append("    { id:\"date\", label:\"Date/Time\", type:\"datetime\" },").append("\n");
    // --
    for (int d = 0; d < TSList.length; d++) {
      String id = "temp" + (d + 1);
      String label = "Temp-" + (d + 1);
      String type = "number";
      sb.append("    { id:\"" + id + "\", label:\"" + label + "\", type:\"" + type + "\" },")
          .append("\n");
    }
    // --
    sb.append("  ],").append("\n");

    /* "rows" */
    // { c: [ { v: new Date(1383914237000) }, { v: -12.6 }, { v: -18.1 } ] },
    sb.append("  rows: [").append("\n");
    int rows = 0, rowCnt = rowMap.size();
    for (Long ts : rowMap.keySet()) {
      sb.append("    { c: [ ");
      sb.append("{v:new Date(" + (ts.longValue() * 1000L) + ")}, ");
      Double tmp[] = rowMap.get(ts);
      for (int t = 0; t < tmp.length; t++) {
        Double D = tmp[t];
        if (t > 0) {
          sb.append(", ");
        }
        String Ds = (D != null) ? StringTools.format(D, "0.0") : "null";
        sb.append("{v:" + Ds + "}");
      }
      sb.append(" ]}");
      if (rows < (rowCnt - 1)) {
        sb.append(",");
      }
      sb.append("\n");
      rows++;
    }
    sb.append("  ]").append("\n");

    /* return */
    sb.append("}");
    return sb.toString();
  }