Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fix & improvements #567

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def exec(Connection connection, input) {
String create_query = "CREATE TABLE " + outTableName + '''(
PK integer PRIMARY KEY AUTO_INCREMENT,
FACILITY varchar(255),
ORIGIN_GEOM geometry,
THE_GEOM geometry,
ORIGIN_GEOM geometry,
TYPES varchar(255)
)'''
sql.execute(create_query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def exec(Connection connection, input) {
if (input["timeBinSize"]) {
timeBinSize = input["timeBinSize"] as int
}
int timeBinMin = 0;
if (input["timeBinMin"]) {
timeBinMin = input["timeBinMin"] as int
}
int timeBinMax = 86400;
if (input["timeBinMax"]) {
timeBinMax = input["timeBinMax"] as int
}

String SRID = "4326"
if (input['SRID']) {
Expand Down Expand Up @@ -303,6 +311,8 @@ def exec(Connection connection, input) {
ProcessOutputEventHandler evHandler = new ProcessOutputEventHandler()

evHandler.setTimeBinSize(timeBinSize)
evHandler.setTimeBinMin(timeBinMin)
evHandler.setTimeBinMax(timeBinMax)
evHandler.setSRID(SRID)
evHandler.setPopulationFactor(populationFactor)
evHandler.initLinks((Map<Id<Link>, Link>) links)
Expand All @@ -319,7 +329,7 @@ def exec(Connection connection, input) {
if (!link2GeometryFile.isEmpty()) {
logger.info("Start Reading link2geom file ...")
BufferedReader br = new BufferedReader(new FileReader(link2GeometryFile))
String line = null
String line = null;
while ((line = br.readLine()) != null) {
String[] str = line.split(",", 2)
if (str.size() > 1) {
Expand Down Expand Up @@ -360,7 +370,7 @@ def exec(Connection connection, input) {
roadStatement.setString(2, linkStatStruct.getOsmId())
roadStatement.setString(3, geomString)
roadStatement.execute()
for (int timeBin = 0 ; timeBin < 86400; timeBin += timeBinSize) {
for (int timeBin = timeBinMin ; timeBin < timeBinMax; timeBin += timeBinSize) {
int index = 1
lwStatement.setString(index, linkId)
List<Double> levels = linkStatStruct.getSourceLevels(timeBin)
Expand All @@ -374,7 +384,7 @@ def exec(Connection connection, input) {
}
lwStatement.executeBatch()
if (exportTraffic) {
for (int timeBin = 0 ; timeBin < 86400; timeBin += timeBinSize) {
for (int timeBin = timeBinMin ; timeBin < timeBinMax; timeBin += timeBinSize) {
int index = 1
trafficStatement.setString(index, linkId)
Trip.Type[] types = [Trip.Type.LV, Trip.Type.MV, Trip.Type.HV]
Expand Down Expand Up @@ -452,6 +462,8 @@ class ProcessOutputEventHandler implements
Map<Id<Link>, LinkStatStruct> links = new HashMap<Id<Link>, LinkStatStruct>()
Map<Id<Vehicle>, List<Id<Person>>> personsInVehicle = new HashMap<Id<Vehicle>, List<Id<Person>>>()
int timeBinSize = 3600;
int timeBinMin = 0;
int timeBinMax = 86400;
String SRID = 4326
double populationFactor = 1.0

Expand All @@ -462,6 +474,12 @@ class ProcessOutputEventHandler implements
void setTimeBinSize(int timeBinSize) {
this.timeBinSize = timeBinSize
}
void setTimeBinMin(int timeBinMin) {
this.timeBinMin = timeBinMin
}
void setTimeBinMax(int timeBinMax) {
this.timeBinMax = timeBinMax
}

void setPopulationFactor(double populationFactor) {
this.populationFactor = populationFactor
Expand Down Expand Up @@ -616,6 +634,8 @@ class LinkStatStruct {
public boolean isUsed = false

int timeBinSize = 3600
int timeBinMin = 0
int timeBinMax = 86400

LinkStatStruct(int timeBinSize, double populationFactor) {
this.timeBinSize = timeBinSize
Expand Down Expand Up @@ -721,7 +741,7 @@ class LinkStatStruct {
return min
}
private int getTimeBin(double time) {
return time - time % timeBinSize;
return (time - time % timeBinSize) % 86400;
}

void setLink(Link link) {
Expand Down Expand Up @@ -816,7 +836,7 @@ class LinkStatStruct {
vehicleCount = vehicleCount / populationFactor // rescale the vehicle count to match the population factor
List<Double> empty_levels = [-99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0, -99.0]

for (int timeBin = 0; timeBin < 86400; timeBin += timeBinSize) {
for (int timeBin = timeBinMin; timeBin < timeBinMax; timeBin += timeBinSize) {
if (!levels.containsKey(timeBin)) {
levels.put(timeBin, new ArrayList<Double>(empty_levels))
}
Expand Down