Exemple #1
0
  /**
   * Reads the data from database and writes into detectors hashmap
   *
   * @throws SQLException
   */
  public void readDataIntoDetectorListFromDatabase() throws SQLException {

    // TestConfiguration.dbSetup();

    PeMSStationAggregateReader stationAggregateReader =
        new PeMSStationAggregateReader(oraDatabase.doConnect());
    ArrayList<Long> vdsIDs = new ArrayList<Long>();

    for (int key : detectors.keySet()) {
      vdsIDs.add((long) key);
    }
    List<PeMSStationAggregate> stationsAggregate =
        stationAggregateReader.read(
            this.timeInterval, vdsIDs, PeMSAggregate.AggregationLevel.PEMS_5MIN);

    // Read absolute detector info into the hashmap
    VDSReader stationReader = new VDSReader(oraDatabase.doConnect());
    for (int key : detectors.keySet()) {
      VDS station = stationReader.read((long) key);
      Detector d = detectors.get(key);
      d.setAbsolutePM(station.getAbsolutePostmile());
      d.setDetectorLength(station.getDetectorLength());
      d.setDetectorName(station.getDetectorName());
      d.setFreewayDirection(station.getDirection());
      d.setFreewayNumber(station.getFreewayNum());
      d.setLatitude(station.getPosition().getPoint().get(0).getLat());
      d.setLongitude(station.getPosition().getPoint().get(0).getLng());
      d.setNumberOfLanes(station.getLaneCount());
    }

    // Read 5 minute data into the hashmap
    for (int i = 0; i < stationsAggregate.size(); i++) {
      // find the detector corresponding to the current ID in the data vector and fill the fields
      // accordingly
      Detector d = detectors.get((int) stationsAggregate.get(i).getVdsId());
      d.addDatumToSpeed(stationsAggregate.get(i).getTotal().getAvgSpeed());
      d.addDatumToFlow(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / d
                  .getNumberOfLanes()); // to get the hourly rate at 5 minute granularity, multiply
                                        // by 12
      d.addDatumToDensity(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / stationsAggregate.get(i).getTotal().getAvgSpeed()
              / d.getNumberOfLanes());
      if (i < detectors.size()) {
        d.setHealthStatus(stationsAggregate.get(i).getTotal().getObserved());
      }
    }
  }