示例#1
0
  // TODO: fix. Returning Object[] is not the right design
  public Object[] getWaveServerRaw(
      final String s,
      final String c,
      final String n,
      final String l,
      final double t1,
      final double t2) {
    String lc = "";
    if (l != null && !l.equals("--")) {
      lc = "$" + l;
    }
    final String code = s + "$" + c + "$" + n + lc;
    if (!winston.checkConnect() || !winston.useDatabase(code)) {
      return null;
    }
    List<byte[]> bufs = null;
    try {
      bufs = data.getTraceBufBytes(code, t1, t2, 0);
    } catch (final UtilException e) {
    }
    if (bufs == null || bufs.size() == 0) {
      return null;
    }

    try {
      final int sid = channels.getChannelID(code);
      final TraceBuf tb0 = new TraceBuf(bufs.get(0));
      final TraceBuf tbN = new TraceBuf(bufs.get(bufs.size() - 1));
      int total = 0;
      for (final byte[] buf : bufs) {
        total += buf.length;
      }

      String lr = "";
      if (l != null) {
        lr = " " + l;
      }
      final String hdr =
          sid
              + " "
              + s
              + " "
              + c
              + " "
              + n
              + lr
              + " F "
              + tb0.dataType()
              + " "
              + tb0.getStartTime()
              + " "
              + tbN.getEndTime()
              + " "
              + total;
      return new Object[] {hdr, new Integer(total), bufs};
    } catch (final Exception e) {
      LOGGER.error("Could not get raw wave.", e.getLocalizedMessage());
    }
    return null;
  }
示例#2
0
  public String getWaveServerMenuItem(final int p, final double embargo, final double span) {
    if (!winston.checkConnect()) {
      return null;
    }

    try {
      String result = null;
      winston.useRootDatabase();
      final ResultSet rs =
          winston.getStatement().executeQuery("SELECT code FROM channels WHERE sid=" + p);
      if (rs.next()) {
        final String code = rs.getString(1);
        final double[] ts = data.getTimeSpan(code);

        /*
         * if (embargo != 0)
         * {
         * double now = CurrentTime.nowJ2K();
         * double emnow = now - embargo;
         * maxt = Math.min(emnow, maxt);
         * }
         * if (span != 0)
         * mint = Math.max(mint, maxt - span);
         */
        final StringTokenizer st = new StringTokenizer(code, "$");
        final String sta = st.nextToken();
        final String ch = st.nextToken();
        final String nw = st.nextToken();

        result =
            " "
                + p
                + " "
                + sta
                + " "
                + ch
                + " "
                + nw
                + " "
                + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[0])))
                + " "
                + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[1])))
                + " s4 ";
      }
      rs.close();
      return result;
    } catch (final Exception e) {
      LOGGER.error("Could not get wave server menu item. ({})", e.getLocalizedMessage());
    }
    return null;
  }
示例#3
0
  public List<String> getWaveServerMenu(
      final boolean scnl, final double embargo, final double span, final double maxDays) {
    if (!winston.checkConnect()) {
      return null;
    }

    final List<Channel> sts = channels.getChannels();
    if (sts == null) {
      return null;
    }

    final List<String> list = new ArrayList<String>(sts.size());
    for (final Channel st : sts) {
      final String[] ss = st.getCode().split("\\$");
      final double[] ts = {st.getMinTime(), st.getMaxTime()};

      if (maxDays > 0) {
        ts[0] = Math.max(ts[0], J2kSec.now() - (maxDays * ONE_DAY));
      }

      if (ts != null && ts[0] < ts[1]) {

        if (!scnl && ss.length == 3) {
          list.add(
              " "
                  + st.getSID()
                  + " "
                  + ss[0]
                  + " "
                  + ss[1]
                  + " "
                  + ss[2]
                  + " "
                  + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[0])))
                  + " "
                  + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[1])))
                  + " s4 ");
        } else if (scnl) {
          final String loc = (ss.length == 4 ? ss[3] : "--");
          final String line =
              " "
                  + st.getSID()
                  + " "
                  + ss[0]
                  + " "
                  + ss[1]
                  + " "
                  + ss[2]
                  + " "
                  + loc
                  + " "
                  + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[0])))
                  + " "
                  + decimalFormat.format(Ew.fromEpoch(J2kSec.asEpoch(ts[1])))
                  + " s4 ";
          list.add(line);
        }
      }
    }
    return list;
  }
示例#4
0
  public void mergeHelicorders(final String code, final String date) {
    try {
      LOGGER.info("Begin merging helicorders.");
      final Set<Integer> sourceTimes = new HashSet<Integer>();
      int total = 0;
      LOGGER.info("Getting source times.");
      source.useDatabase(code);
      ResultSet srs =
          source.getStatement().executeQuery("SELECT j2ksec FROM `" + code + "$$H" + date + "`");
      while (srs.next()) {
        total++;
        sourceTimes.add((int) Math.round(srs.getDouble(1)));
      }

      LOGGER.info("Getting destination times.");
      dest.useDatabase(code);
      final ResultSet drs =
          dest.getStatement().executeQuery("SELECT j2ksec FROM `" + code + "$$H" + date + "`");
      total = 0;
      while (drs.next()) {
        total++;
        sourceTimes.remove(new Integer((int) Math.round(drs.getDouble(1))));
      }

      total = 0;
      double read = 0;
      double write = 0;
      LOGGER.info("Begin merging.");
      final PreparedStatement insert =
          dest.getConnection()
              .prepareStatement(
                  "INSERT IGNORE INTO `" + code + "$$H" + date + "` VALUES (?,?,?,?,?)");
      final CodeTimer readTimer = new CodeTimer();
      for (final Iterator<Integer> it = sourceTimes.iterator(); it.hasNext(); ) {
        final int d = it.next().intValue();
        srs =
            source
                .getStatement()
                .executeQuery(
                    "SELECT j2ksec, smin, smax, rcnt, rsam FROM `"
                        + code
                        + "$$H"
                        + date
                        + "` WHERE j2ksec="
                        + d);
        if (srs.next()) {
          insert.setDouble(1, srs.getDouble(1));
          insert.setInt(2, srs.getInt(2));
          insert.setInt(3, srs.getInt(3));
          insert.setInt(4, srs.getInt(4));
          insert.setDouble(5, srs.getDouble(5));
          final CodeTimer writeTimer = new CodeTimer();
          insert.execute();
          writeTimer.stopAndReport();
          write += writeTimer.getRunTimeMillis();
          total++;
        }
      }
      readTimer.stop();
      read = readTimer.getRunTimeMillis() - write;
      LOGGER.info("Done merging, " + read + "ms reading, " + write + "ms writing.");
      LOGGER.info("Merged " + total + " helicorder rows.");
    } catch (final Exception e) {
      LOGGER.error("Could not merge waves. {}", e);
    }
  }
示例#5
0
  public void mergeWaves(final String code, final String date) {
    try {
      LOGGER.info("Begin merging waves.");
      final Set<Double> sourceTimes = new HashSet<Double>();
      int total = 0;
      LOGGER.info("Getting source times.");
      source.useDatabase(code);
      ResultSet srs =
          source.getStatement().executeQuery("SELECT st FROM `" + code + "$$" + date + "`");
      while (srs.next()) {
        total++;
        sourceTimes.add(DataUtils.register(srs.getDouble(1), EPSILON));
      }

      LOGGER.info("Getting destination times.");
      dest.useDatabase(code);
      final ResultSet drs =
          dest.getStatement().executeQuery("SELECT st FROM `" + code + "$$" + date + "`");
      total = 0;
      while (drs.next()) {
        total++;
        sourceTimes.remove(new Double(DataUtils.register(drs.getDouble(1), EPSILON)));
      }

      total = 0;
      LOGGER.info("Begin merging.");
      double read = 0;
      double write = 0;
      final PreparedStatement insert =
          dest.getConnection()
              .prepareStatement(
                  "INSERT IGNORE INTO `" + code + "$$" + date + "` VALUES (?,?,?,?,?)");
      final CodeTimer readTimer = new CodeTimer();
      for (final Iterator<Double> it = sourceTimes.iterator(); it.hasNext(); ) {
        final double d = it.next().doubleValue();
        srs =
            source
                .getStatement()
                .executeQuery(
                    "SELECT st, et, sr, datatype, tracebuf FROM `"
                        + code
                        + "$$"
                        + date
                        + "` WHERE st>="
                        + (d - EPSILON)
                        + " AND st<="
                        + (d + EPSILON));
        if (srs.next()) {
          insert.setDouble(1, srs.getDouble(1));
          insert.setDouble(2, srs.getDouble(2));
          insert.setDouble(3, srs.getDouble(3));
          insert.setString(4, srs.getString(4));
          insert.setBlob(5, srs.getBlob(5));
          final CodeTimer writeTimer = new CodeTimer();
          insert.execute();
          writeTimer.stopAndReport();
          write += writeTimer.getRunTimeMillis();
          total++;
        }
      }
      readTimer.stop();
      read = readTimer.getRunTimeMillis() - write;
      LOGGER.info("Done merging, " + read + "ms reading, " + write + "ms writing.");
      LOGGER.info("Merged " + total + " wave rows.");
    } catch (final Exception e) {
      LOGGER.error("Could not merge waves. {}", e);
    }
  }