Exemple #1
0
  public static StreamElement createElementFromREST(
      DataField[] outputFormat, String[] fieldNames, Object[] fieldValues) {
    ArrayList<Serializable> values = new ArrayList<Serializable>();
    // ArrayList<String> fields = new ArrayList<String>();

    long timestamp = -1;
    for (int i = 0; i < fieldNames.length; i++) {
      if (fieldNames[i].equalsIgnoreCase("TIMED")) {
        timestamp = Long.parseLong((String) fieldValues[i]);
        continue;
      }
      boolean found = false;
      for (DataField f : outputFormat) {
        if (f.getName().equalsIgnoreCase(fieldNames[i])) {
          //     fields.add(fieldNames[i]);
          found = true;
          break;
        }
      }
      if (found == false) continue;

      switch (findIndexInDataField(outputFormat, fieldNames[i])) {
        case DataTypes.DOUBLE:
          values.add(Double.parseDouble((String) fieldValues[i]));
          break;
        case DataTypes.BIGINT:
          values.add(Long.parseLong((String) fieldValues[i]));
          break;
        case DataTypes.TINYINT:
          values.add(Byte.parseByte((String) fieldValues[i]));
          break;
        case DataTypes.SMALLINT:
          values.add(Short.parseShort((String) fieldValues[i]));
          break;
        case DataTypes.INTEGER:
          values.add(Integer.parseInt((String) fieldValues[i]));
          break;
        case DataTypes.CHAR:
        case DataTypes.VARCHAR:
          values.add(new String((byte[]) fieldValues[i]));
          break;
        case DataTypes.BINARY:
          try {
            //          StreamElementTest.md5Digest(fieldValues[ i ]);
          } catch (Exception e) {
            e.printStackTrace();
          }
          values.add((byte[]) fieldValues[i]);
          break;
        case -1:
        default:
          logger.error(
              "The field name doesn't exit in the output structure : FieldName : "
                  + (String) fieldNames[i]);
      }
    }
    if (timestamp == -1) timestamp = System.currentTimeMillis();
    return new StreamElement(outputFormat, values.toArray(new Serializable[] {}), timestamp);
  }
  /**
   * Save the data fields.
   *
   * @param out The output file.
   */
  private void saveData(final EncogWriteHelper out) {
    saveSubSection(out, "DATA", "CONFIG");
    out.addSubSection("STATS");
    out.addColumn("name");
    out.addColumn("isclass");
    out.addColumn("iscomplete");
    out.addColumn("isint");
    out.addColumn("isreal");
    out.addColumn("amax");
    out.addColumn("amin");
    out.addColumn("mean");
    out.addColumn("sdev");
    out.writeLine();

    for (final DataField field : this.script.getFields()) {
      out.addColumn(field.getName());
      out.addColumn(field.isClass());
      out.addColumn(field.isComplete());
      out.addColumn(field.isInteger());
      out.addColumn(field.isReal());
      out.addColumn(field.getMax());
      out.addColumn(field.getMin());
      out.addColumn(field.getMean());
      out.addColumn(field.getStandardDeviation());
      out.writeLine();
    }
    out.flush();

    out.addSubSection("CLASSES");
    out.addColumn("field");
    out.addColumn("code");
    out.addColumn("name");
    out.writeLine();

    for (final DataField field : this.script.getFields()) {
      if (field.isClass()) {
        for (final AnalystClassItem col : field.getClassMembers()) {
          out.addColumn(field.getName());
          out.addColumn(col.getCode());
          out.addColumn(col.getName());
          out.addColumn(col.getCount());
          out.writeLine();
        }
      }
    }
  }
 public void print() {
   System.out.println(
       "PK "
           + getUri()
           + " "
           + fieldStr.getName()
           + " "
           + getStringField(fieldStr)
           + " "
           + getLongField(fieldInt)
           + " "
           + getNumericField(fieldDbl)
           + " "
           + getDateField(fieldDate)
           + " "
           + getBooleanField(fieldBool));
 }