Beispiel #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:
  }
Beispiel #2
0
  private static OrderedMap<Long, Double[]> _MergeDataSets(boolean F, TemperatureSet TSList[]) {

    /* merge temperature data sets */
    OrderedMap<Long, Double[]> rowMap = new OrderedMap<Long, Double[]>();
    if (!ListTools.isEmpty(TSList)) {
      for (int d = 0; d < TSList.length; d++) {
        TemperatureSet TS = TSList[d];
        if (TS != null) {
          Collection<Temperature> TList = TS.getTemperatures();
          for (Temperature T : TList) {
            Long ts = new Long(T.getTimestamp());
            Double tmp = new Double(T.getTemperature(F));
            Double row[] = rowMap.get(ts);
            if (row == null) {
              row = new Double[TSList.length];
              rowMap.put(ts, row);
            }
            row[d] = tmp;
          }
        }
      }
    }

    /* sort by timestamp */
    rowMap.sortKeys(new ListTools.NumberComparator<Long>());

    /* return */
    return rowMap;
  }
Beispiel #3
0
 /**
  * ** Gets an <code>OrderedMap</code> of the argument key/value pairs indexed ** by their keys
  * ** @return An <code>OrderedMap</code> of the argument key/value pairs
  */
 protected OrderedMap<String, KeyVal> getKeyValMap() {
   OrderedMap<String, KeyVal> kvMap = new OrderedMap<String, KeyVal>();
   for (KeyVal kv : this.getKeyValList()) {
     // only the first occurance is retained
     String kn = kv.getKey();
     if (!kvMap.containsKey(kn)) {
       kvMap.put(kn, kv);
     }
   }
   return kvMap;
 }
Beispiel #4
0
 /* write mapping support JS to stream */
 public static void writePushpinArray(PrintWriter out, RequestProperties reqState)
     throws IOException {
   MapProvider mapProv = reqState.getMapProvider();
   out.write("// Icon URLs\n");
   out.write("var jsvPushpinIcon = new Array(\n");
   OrderedMap<String, PushpinIcon> iconMap = mapProv.getPushpinIconMap(reqState);
   for (Iterator<String> k = iconMap.keyIterator(); k.hasNext(); ) {
     String key = k.next();
     PushpinIcon ppi = iconMap.get(key);
     String I = ppi.getIconURL();
     boolean iE = ppi.getIconEval();
     int iW = ppi.getIconWidth();
     int iH = ppi.getIconHeight();
     int iX = ppi.getIconHotspotX();
     int iY = ppi.getIconHotspotY();
     String S = ppi.getShadowURL();
     int sW = ppi.getShadowWidth();
     int sH = ppi.getShadowHeight();
     String B = ppi.getBackgroundURL();
     int bW = ppi.getBackgroundWidth();
     int bH = ppi.getBackgroundHeight();
     int bX = ppi.getBackgroundOffsetX();
     int bY = ppi.getBackgroundOffsetY();
     out.write("    {");
     out.write(" key:\"" + key + "\",");
     if (iE) {
       out.write(" iconEval:\"" + I + "\",");
     } else {
       out.write(" iconURL:\"" + I + "\",");
     }
     out.write(" iconSize:[" + iW + "," + iH + "],");
     out.write(" iconOffset:[" + iX + "," + iY + "],");
     out.write(" iconHotspot:[" + iX + "," + iY + "],");
     out.write(" shadowURL:\"" + S + "\",");
     out.write(" shadowSize:[" + sW + "," + sH + "]");
     if (!StringTools.isBlank(B)) {
       out.write(",");
       out.write(" bgURL:\"" + B + "\",");
       out.write(" bgSize:[" + bW + "," + bH + "],");
       out.write(" bgOffset:[" + bX + "," + bY + "]");
     }
     out.write(" }");
     if (k.hasNext()) {
       out.write(",");
     }
     out.write("\n");
   }
   out.write("    );\n");
 }
Beispiel #5
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();
  }