/**
   * Updates survey table with weights
   *
   * @param tableSetup The hashtable that defines the database tables, fields, etc.
   * @param FinalWeights The object holding the final weight values to be written
   */
  public static void updateSurveyTableWeights(
      Hashtable<String, String> tableSetup, List<WeightData> FinalWeights) {
    File dFile = new File((String) tableSetup.get("dataFile"));
    // Logger logger=IPFMain.logger;
    try {
      Table table = Database.open(dFile).getTable((String) tableSetup.get("surveyTable"));
      Cursor cur = Cursor.createCursor(table);

      cur.reset();
      while (cur.moveToNextRow()) {
        Map<String, Object> row = cur.getCurrentRow();
        for (WeightData wd : FinalWeights) {
          Map<String, Object> newRow = new HashMap<String, Object>();
          // logger.debug("row\t"+row.get(tableSetup.get("routeField")).toString()+"\t"+row.get(tableSetup.get("directionField")).toString()+"\t"+row.get(tableSetup.get("timeField")).toString()+"\t"+CInt(row.get(tableSetup.get("BoardingLocationCode")))+"\t"+CInt(row.get(tableSetup.get("AlightingLocationCode"))));
          // logger.debug("wd
          // \t"+wd.RouteName+"\t"+wd.Direction+"\t"+wd.TimePeriod+"\t"+wd.BoardLocation+"\t"+wd.AlightLocation);
          if (row.get(tableSetup.get("routeField")).toString().equalsIgnoreCase(wd.RouteName)
              && row.get(tableSetup.get("directionField")).toString().equalsIgnoreCase(wd.Direction)
              && row.get(tableSetup.get("timeField")).toString().equalsIgnoreCase(wd.TimePeriod)
              && CInt(row.get(tableSetup.get("BoardingLocationCode"))) == wd.BoardLocation
              && CInt(row.get(tableSetup.get("AlightingLocationCode"))) == wd.AlightLocation) {
            // FIXME: Somehow in the last round of changes, execution never gets to this point.
            newRow.put("ODWeight", wd.ODWeightValue); // TODO: Hash
            if (wd.Direction.equalsIgnoreCase("Inbound")
                && wd.TimePeriod.equalsIgnoreCase("AM Peak")) {
              if (CInt(row.get(tableSetup.get("OriginAccess"))) <= 2) {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationWalkWeight);
              } else if (CInt(row.get(tableSetup.get("OriginAccess"))) == 5) {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationKNRWeight);
              } else {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationPNRWeight);
              }

            } else if (wd.Direction.equalsIgnoreCase("Outbound")
                && wd.TimePeriod.equalsIgnoreCase("PM Peak")) {
              if (CInt(row.get(tableSetup.get("DestinationEgress"))) <= 2) {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationWalkWeight);
              } else if (CInt(row.get(tableSetup.get("DestinationEgress"))) == 5) {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationKNRWeight);
              } else {
                newRow.put(tableSetup.get("StationWeightField"), wd.StationPNRWeight);
              }
            }
            Column col = table.getColumn(tableSetup.get("StationWeightField"));
            cur.setCurrentRowValue(col, newRow.get(tableSetup.get("StationWeightField")));
            col = table.getColumn("ODWeight"); // TODO: Hash
            cur.setCurrentRowValue(col, newRow.get("ODWeight"));
            // break;
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    }
  }
示例#2
0
  private static void writeData(Table t1, Table t2, int start, int end) throws Exception {
    Database db = t1.getDatabase();
    ((DatabaseImpl) db).getPageChannel().startWrite();
    try {
      for (int i = start; i < end; ++i) {
        t1.addRow(null, "rowdata-" + i + TestUtil.createString(100));
        t2.addRow(null, "rowdata-" + i + TestUtil.createString(100));
      }
    } finally {
      ((DatabaseImpl) db).getPageChannel().finishWrite();
    }

    Cursor c1 = t1.newCursor().setIndex(t1.getPrimaryKeyIndex()).toCursor();
    Cursor c2 = t2.newCursor().setIndex(t2.getPrimaryKeyIndex()).toCursor();

    Iterator<? extends Row> i1 = c1.iterator();
    Iterator<? extends Row> i2 = c2.newIterable().reverse().iterator();

    int t1rows = 0;
    int t2rows = 0;
    ((DatabaseImpl) db).getPageChannel().startWrite();
    try {
      while (i1.hasNext() || i2.hasNext()) {
        if (i1.hasNext()) {
          checkRow(i1.next());
          i1.remove();
          ++t1rows;
        }
        if (i2.hasNext()) {
          checkRow(i2.next());
          i2.remove();
          ++t2rows;
        }
      }
    } finally {
      ((DatabaseImpl) db).getPageChannel().finishWrite();
    }

    assertEquals(100, t1rows);
    assertEquals(100, t2rows);
  }