Exemple #1
0
 /**
  * _more_
  *
  * @param range _more_
  * @param var _more_
  * @return _more_
  * @throws Exception _more_
  */
 protected double[] getDoubleData(Range range, String var) throws Exception {
   double[] d =
       SqlUtil.readDouble(
           SqlUtil.getIterator(select(var, TABLE_DATA, "order by " + varTime)),
           1,
           getMissingValue(var));
   if (d.length == 0) {
     throw new BadDataException("No observations found in data base");
   }
   return d;
 }
Exemple #2
0
 /**
  * _more_
  *
  * @param range _more_
  * @param var _more_
  * @return _more_
  * @throws Exception _more_
  */
 protected float[] getFloatData(Range range, String var) throws Exception {
   long t1 = System.currentTimeMillis();
   float[] f =
       SqlUtil.readFloat(
           SqlUtil.getIterator(select("(" + var + ")", TABLE_DATA, "order by " + varTime)),
           1,
           (float) getMissingValue(var));
   long t2 = System.currentTimeMillis();
   //            System.err.println("length:" + f.length + " time:" + (t2-t1));
   if (f.length == 0) {
     throw new BadDataException("No observations found in data base");
   }
   return f;
 }
Exemple #3
0
 /**
  * _more_
  *
  * @return _more_
  * @throws Exception _more_
  */
 public int getNumberPoints() throws Exception {
   if (numberOfPoints < 0) {
     Statement stmt = select("COUNT(" + varTime + ")", TABLE_DATA);
     ResultSet results;
     int cnt = 0;
     SqlUtil.Iterator iter = SqlUtil.getIterator(stmt);
     while ((results = iter.getNext()) != null) {
       cnt++;
     }
     numberOfPoints = cnt;
   }
   return numberOfPoints;
 }
Exemple #4
0
 /**
  * _more_
  *
  * @param range _more_
  * @param var _more_
  * @return _more_
  * @throws Exception _more_
  */
 protected String[] getStringData(Range range, String var) throws Exception {
   return SqlUtil.readString(
       SqlUtil.getIterator(select(var, TABLE_DATA, "order by " + varTime)), 1);
 }
Exemple #5
0
  /**
   * _more_
   *
   * @return _more_
   * @throws Exception _more_
   */
  private boolean initConnection() throws Exception {
    if (getConnection() == null) {
      return false;
    }
    // jdbc:postgresql://eol-rt-data.guest.ucar.edu/real-time
    //        evaluate("CREATE RULE update AS ON UPDATE TO global_attributes DO NOTIFY current;");

    Statement stmt;
    ResultSet results;
    SqlUtil.Iterator iter;
    EolDbTrackInfo trackInfo = new EolDbTrackInfo(this, "TRACK");
    Hashtable cats = new Hashtable();
    try {
      stmt = select("*", TABLE_CATEGORIES);
      iter = SqlUtil.getIterator(stmt);
      while ((results = iter.getNext()) != null) {
        cats.put(results.getString(COL_VARIABLE), results.getString(COL_CATEGORY));
      }
    } catch (Exception exc) {
      //                exc.printStackTrace();
    }

    missingMap = new Hashtable();
    stmt = select("*", TABLE_GLOBALS);
    globals = new Hashtable();
    boolean gotCoords = false;
    description = "<b>Globals</b><br>";
    iter = SqlUtil.getIterator(stmt);
    while ((results = iter.getNext()) != null) {
      String globalName = results.getString(1).trim();
      String globalValue = results.getString(2).trim();
      globals.put(globalName, globalValue);
      description =
          description
              + "<tr valign=\"top\"><td>"
              + globalName
              + "</td><td>"
              + globalValue
              + "</td></tr>";

      //            System.err.println(globalName +"=" + globalValue);

      if (globalName.equals(GLOBAL_STARTTIME)) {
        startTime = new DateTime(DateUtil.parse(globalValue));
      } else if (globalName.equals(GLOBAL_ENDTIME)) {
        endTime = new DateTime(DateUtil.parse(globalValue));
      } else if (globalName.equals(GLOBAL_COORDINATES)) {
        List toks = StringUtil.split(globalValue, " ", true, true);
        if (toks.size() != 4) {
          throw new BadDataException("Incorrect coordinates value in database:" + globalValue);
        }
        gotCoords = true;
        System.err.println("coords:" + toks);
        trackInfo.setCoordinateVars(
            (String) toks.get(0), (String) toks.get(1), (String) toks.get(2), (String) toks.get(3));

        trackInfo.setCoordinateVars("GGLON", "GGLAT", "GGALT", "datetime");
      }
    }
    description = description + "</table>";

    if (!gotCoords) {
      throw new BadDataException("No coordinates found in database");
    }

    this.name = (String) globals.get(GLOBAL_PROJECTNAME);
    String flight = (String) globals.get(GLOBAL_FLIGHTNUMBER);
    if ((this.name != null) && (flight != null) && (flight.length() != 0)) {
      this.name += " - " + flight;
    }

    stmt = select("*", TABLE_VARIABLE_LIST);
    iter = SqlUtil.getIterator(stmt);
    while ((results = iter.getNext()) != null) {
      String name = results.getString(COL_NAME).trim();
      String desc = results.getString(COL_LONG_NAME).trim();
      Unit unit = DataUtil.parseUnit(results.getString(COL_UNITS).trim());
      String cat = (String) cats.get(name);
      double missing = results.getDouble(COL_MISSING_VALUE);
      VarInfo variable = new VarInfo(name, desc, cat, unit, missing);
      trackInfo.addVariable(variable);
    }
    addTrackInfo(trackInfo);
    return true;
  }
Exemple #6
0
 /**
  * _more_
  *
  * @param what _more_
  * @param where _more_
  * @return _more_
  * @throws SQLException _more_
  */
 private Statement select(String what, String where) throws SQLException {
   return evaluate(SqlUtil.makeSelect(what, Misc.newList(where)));
 }