Beispiel #1
0
  public String toString() {
    StringBuffer sb = new StringBuffer();

    /* standard event fields */
    int sc = this.getStatusCode();
    sb.append("Event values:\n");
    sb.append("  DeviceID  : " + this.getAccountID() + "/" + this.getDeviceID() + "\n");
    sb.append("  UniqueID  : " + this.getUniqueID() + "\n");
    sb.append(
        "  Fixtime   : " + this.getTimestamp() + " [" + new DateTime(this.getTimestamp()) + "]\n");
    sb.append(
        "  StatusCode: [" + StatusCodes.GetHex(sc) + "] " + StatusCodes.GetDescription(sc, null));
    sb.append("  GPS       : " + this.getGeoPoint() + " [age " + this.getGpsAge() + " sec]\n");
    sb.append(
        "  SpeedKPH  : "
            + StringTools.format(this.getSpeedKPH(), "0.0")
            + " ["
            + this.getHeading()
            + "]\n");

    /* remaining event fields (not already displayed) */
    OrderedSet<?> fldn = new OrderedSet<Object>(this.fieldValues.getPropertyKeys());
    fldn.remove(EventData.FLD_timestamp);
    fldn.remove(EventData.FLD_statusCode);
    fldn.remove(EventData.FLD_latitude);
    fldn.remove(EventData.FLD_longitude);
    fldn.remove(EventData.FLD_gpsAge);
    fldn.remove(EventData.FLD_speedKPH);
    fldn.remove(EventData.FLD_heading);
    for (Object k : fldn) {
      Object v = this.fieldValues.getProperty(k, "?");
      sb.append("  ");
      sb.append(StringTools.leftAlign(k.toString(), 10)).append(": ");
      sb.append(v.toString()).append("\n");
    }

    /* alternate fields */
    if (this.otherValues != null) {
      for (String k : this.otherValues.keySet()) {
        String v = StringTools.trim(this.otherValues.get(k));
        sb.append("  ");
        sb.append(StringTools.leftAlign(k, 10)).append(": ");
        sb.append(v).append("\n");
      }
    }

    /* return string */
    return sb.toString();
  }
  protected void _initChart() throws Exception {

    /* already initialized? */
    if (this.didInitChart) {
      return;
    }

    /* axis tick counts */
    int yTickCnt = this.getTemperatureTickCount();
    int xTickCnt = this.getDateTickCount();

    /* horizontal grid */
    this.setGrid(0, yTickCnt);

    /* Y-axis labels */
    StringBuffer ya = new StringBuffer();
    double deltaC = this.maxTempC - this.minTempC;
    for (int y = 0; y <= yTickCnt; y++) {
      double C = this.minTempC + (deltaC * ((double) y / (double) yTickCnt));
      double v = (this.dispUnits == TEMP_C) ? C : C2F(C);
      ya.append("|").append(StringTools.format(v, "0.0"));
    }
    if ((this.maxTempC > 0.0) && (this.minTempC < 0.0)) {
      double sep = Math.abs(this.minTempC) / (this.maxTempC - this.minTempC);
      this.addShapeMarker(
          "r,AA4444,0,"
              + StringTools.format(sep, "0.000")
              + ","
              + StringTools.format(sep + 0.002, "0.000"));
    }

    /* X-axis labels */
    StringBuffer xat = new StringBuffer();
    StringBuffer xad = new StringBuffer();
    double deltaTS = (double) (this.maxDateTS - this.minDateTS);
    long lastDN = 0L;
    for (int x = 0; x <= xTickCnt; x++) {
      long ts = this.minDateTS + Math.round(deltaTS * ((double) x / (double) xTickCnt));
      DateTime dt = new DateTime(ts, this.timeZone);
      long dn = DateTime.getDayNumberFromDate(dt);
      xat.append("|").append(dt.format(this.getTimeFormat()));
      xad.append("|").append(dt.format(this.getDateFormat()));
      if (dn != lastDN) {
        long ds = dt.getDayStart();
        if (ds > this.minDateTS) {
          double sep = (double) (ds - this.minDateTS) / deltaTS;
          this.addShapeMarker(
              "R,444444,0,"
                  + StringTools.format(sep, "0.000")
                  + ","
                  + StringTools.format(sep + 0.001, "0.000"));
        }
        lastDN = dn;
      }
    }

    /* axis labels */
    this.setAxisLabels(
        "y,x,x", "0:" + ya.toString() + "|1:" + xad.toString() + "|2:" + xat.toString());

    /* did init */
    this.didInitChart = true;
  }
Beispiel #3
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();
  }
Beispiel #4
0
 public static String GetFaultDescription(long fault, Locale locale) {
   if (fault != 0L) {
     String fmt = "000";
     StringBuffer sb = new StringBuffer();
     if ((fault & TYPE_MASK) == TYPE_J1708) {
       int mid = DTOBDFault.DecodeSystem(fault); // MID
       boolean isSid = DTOBDFault.IsJ1708_SID(fault);
       int pidSid = DTOBDFault.DecodePidSid(fault); // PID|SID "128/[s]123/1"
       int fmi = DTOBDFault.DecodeFMI(fault); // FMI
       Properties p =
           (j1587DescProvider != null)
               ? j1587DescProvider.getJ1587Descriptions(fault)
               : new Properties();
       // MID
       sb.append(
           NAME_MID
               + "("
               + StringTools.format(mid, fmt)
               + ") "
               + p.getProperty(NAME_MID_DESC, "")
               + "\n");
       // PID/SID
       if (isSid) {
         sb.append(
             NAME_SID
                 + "("
                 + StringTools.format(pidSid, fmt)
                 + ") "
                 + p.getProperty(NAME_SID_DESC, "")
                 + "\n");
       } else {
         sb.append(
             NAME_PID
                 + "("
                 + StringTools.format(pidSid, fmt)
                 + ") "
                 + p.getProperty(NAME_PID_DESC, "")
                 + "\n");
       }
       // FMI
       sb.append(
           NAME_FMI
               + "("
               + StringTools.format(fmi, fmt)
               + ") "
               + p.getProperty(NAME_FMI_DESC, ""));
       return sb.toString();
     } else if ((fault & TYPE_MASK) == TYPE_J1939) {
       int spn = DTOBDFault.DecodeSystem(fault); // SPN
       int fmi = DTOBDFault.DecodeFMI(fault); // FMI
       Properties p = new Properties();
       // SPN
       sb.append(
           NAME_SPN
               + "("
               + StringTools.format(spn, fmt)
               + ") "
               + p.getProperty(NAME_SPN, "")
               + "\n");
       // FMI
       sb.append(
           NAME_FMI + "(" + StringTools.format(fmi, fmt) + ") " + p.getProperty(NAME_FMI, ""));
       return sb.toString();
     } else if ((fault & TYPE_MASK) == TYPE_OBDII) {
       String dtc = DTOBDFault.GetFaultString(fault); // DTC
       Properties p = new Properties();
       // DTC
       sb.append(NAME_DTC + "(" + dtc + ") " + p.getProperty(NAME_DTC, ""));
       return sb.toString();
     }
   }
   return "";
 }