/** * Read all PeMS data in the given time range and having a VDS ID in the given list. * * @see #read() if you want a transaction and logging around the operation. */ public PeMSSet readSet(Interval interval, List<Long> vdsIds) throws DatabaseException { PeMSSet set = new PeMSSet(); List<PeMSMap> mapList = set.getPemsMapList(); PeMS pems; String query = null; try { query = runQuerySet(interval, vdsIds); org.joda.time.DateTime prevTime = null; PeMSMap map = null; while (null != (pems = pemsFromQueryRS(query))) { org.joda.time.DateTime curTime = pems.getJodaTimeMeasured(); if (map == null || !prevTime.equals(curTime)) { map = new PeMSMap(); mapList.add(map); prevTime = curTime; } map.getMap().put(pems.getVdsId().toString(), pems); } } finally { if (query != null) { dbr.psDestroy(query); } } return set; }
/** * Instantiate and populate a pems object from the next item in the result set of a pems query. * * @param query string * @return PeMS */ protected PeMS pemsFromQueryRS(String query) throws DatabaseException { PeMS pems = null; if (dbr.psRSNext(query)) { // String columns = org.apache.commons.lang.StringUtils.join(dbr.psRSColumnNames(query), ", // "); // System.out.println("columns: [" + columns + "]"); pems = new PeMS(); Long vdsId = dbr.psRSGetBigInt(query, "VDS_ID"); edu.berkeley.path.model_elements.DateTime timeMeasured = new edu.berkeley.path.model_elements.DateTime( dbr.psRSGetTimestampMilliseconds(query, "MEASURE_DT")); Double flow = dbr.psRSGetDouble(query, "FLOW"); Double density = dbr.psRSGetDouble(query, "DENSITY"); Double densityError = dbr.psRSGetDouble(query, "DENSITY_ERR"); Double speed = dbr.psRSGetDouble(query, "SPEED"); Double speedError = dbr.psRSGetDouble(query, "SPEED_ERROR"); Double ffSpeed = dbr.psRSGetDouble(query, "FF_SPEED"); Double funcLoopFact = dbr.psRSGetDouble(query, "FUNC_LOOP_FACT"); ArrayList<Double> gFactorLane = new ArrayList<Double>(); for (int i = 0; i <= 9; i++) { gFactorLane.add(dbr.psRSGetDouble(query, "G_FACTOR_LANE_" + i)); } pems.setVdsId(vdsId); pems.setTimeMeasured(timeMeasured); pems.setFlow(flow); pems.setDensity(density); pems.setDensityError(densityError); pems.setSpeed(speed); pems.setSpeedError(speedError); pems.setFreeFlowSpeed(ffSpeed); pems.setFuncLoopFact(funcLoopFact); pems.setGFactorLane(gFactorLane); } return pems; }