Skip to content

Commit

Permalink
- fixed a bug where settlement codes where not treated specifically f…
Browse files Browse the repository at this point in the history
…or a given simulation
  • Loading branch information
Alain Schengen committed Jun 7, 2021
1 parent 924641c commit 5ec3f71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.dlr.ivf.tapas.persistence.db.TPS_DB_Connector;
import de.dlr.ivf.tapas.persistence.db.TPS_DB_IO;
import de.dlr.ivf.tapas.persistence.db.TPS_DB_IOManager;
import de.dlr.ivf.tapas.util.FuncUtils;
import de.dlr.ivf.tapas.util.parameters.TPS_ParameterClass;

import javax.swing.text.BadLocationException;
Expand Down Expand Up @@ -280,7 +281,8 @@ public DBTripFetcher(BlockingQueue<TapasTrip> q, String simulation, String hhkey
TPS_DB_IOManager dbIOM = new TPS_DB_IOManager(dbCon.getParameters());
TPS_DB_IO dbIO = new TPS_DB_IO(dbIOM);
dbIO.initStart();
dbIO.readSettlementSystemCodes();

dbIO.readSettlementSystemCodes(FuncUtils.toRawSimKey.apply(this.simulation));

} catch (IOException | ClassNotFoundException e) {
throw e; // handle that outside of the class
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/de/dlr/ivf/tapas/persistence/db/TPS_DB_IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ void readConstants() {
this.readLocationConstantCodes();
this.readModes();
this.readPersonGroupCodes();
this.readSettlementSystemCodes();
this.readSettlementSystemCodes("");
this.readSexCodes();

//must be after reading of activities and locations because they are used in it
Expand Down Expand Up @@ -1861,8 +1861,16 @@ public TPS_SchemeSet readSchemeSet() throws SQLException {
* A SettlementSystem has the form (id, 3-tuples of (name, code, type))
* Example: (7, ("R1, K1, Kernstadt > 500000", "1", "FORDCP"))
*/
public void readSettlementSystemCodes() {
String query = "SELECT * FROM " + this.PM.getParameters().getString(ParamString.DB_TABLE_CONSTANT_SETTLEMENT);
public void readSettlementSystemCodes(String simulation) {

String settlement_systems_table = "";

if(simulation.equals(""))
settlement_systems_table = this.PM.getParameters().getString(ParamString.DB_TABLE_CONSTANT_SETTLEMENT);
else
settlement_systems_table = this.PM.getDbConnector().readSingleParameter(simulation,ParamString.DB_TABLE_CONSTANT_SETTLEMENT.toString());

String query = "SELECT * FROM core." + settlement_systems_table;
try (ResultSet rs = PM.executeQuery(query)) {
TPS_SettlementSystem tss;
while (rs.next()) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/dlr/ivf/tapas/util/FuncUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.dlr.ivf.tapas.util;

import java.util.function.Function;

public class FuncUtils {

public static Function<Integer, Integer> secondsToRoundedMinutes = i -> (int) (i * 1.66666666e-2 +0.5);

public static Function<String,String> toRawSimKey = s -> s.replaceFirst("[^\\s]*_trips_", "");
}

0 comments on commit 5ec3f71

Please sign in to comment.