From 188aa3bd4522439cdbf17d25d0a6dcd0cffe40b4 Mon Sep 17 00:00:00 2001 From: Valentin LE BESCOND Date: Tue, 4 Apr 2023 10:48:05 +0200 Subject: [PATCH 1/3] fix: invert geometry columns in activities_receivers table --- .../Receivers_From_Activities_Closest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Receivers_From_Activities_Closest.groovy b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Receivers_From_Activities_Closest.groovy index d6c21d3d6..9e5230463 100644 --- a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Receivers_From_Activities_Closest.groovy +++ b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Receivers_From_Activities_Closest.groovy @@ -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) From 7d4c2c13f21f38bd4291a63403d7e0d79a3a7b1d Mon Sep 17 00:00:00 2001 From: Valentin LE BESCOND Date: Tue, 4 Apr 2023 10:50:04 +0200 Subject: [PATCH 2/3] introduce timeBinMin and timeBinMax (undocumented for now) & wrap events after 24:00 back to 00:00+ --- .../Experimental_Matsim/Traffic_From_Events.groovy | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy index b1d0fa577..f08fc7c24 100644 --- a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy +++ b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy @@ -194,6 +194,14 @@ def exec(Connection connection, input) { if (input["timeBinSize"]) { timeBinSize = input["timeBinSize"] as int } + int timeBinMin = 0; + if (input["timeBinMin"]) { + timeBinSize = input["timeBinMin"] as int + } + int timeBinMax = 86400; + if (input["timeBinMax"]) { + timeBinSize = input["timeBinMax"] as int + } String SRID = "4326" if (input['SRID']) { @@ -360,7 +368,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 levels = linkStatStruct.getSourceLevels(timeBin) @@ -374,7 +382,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] @@ -721,7 +729,7 @@ class LinkStatStruct { return min } private int getTimeBin(double time) { - return time - time % timeBinSize; + return (time - time % timeBinSize) % 86400; } void setLink(Link link) { From 5e3cd3c121fe932a6af1e6e854436b32d8714a6b Mon Sep 17 00:00:00 2001 From: Valentin LE BESCOND Date: Wed, 19 Apr 2023 15:38:12 +0200 Subject: [PATCH 3/3] fix: timeBinSize was not assigned properly --- .../Traffic_From_Events.groovy | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy index f08fc7c24..fa6bd4dbc 100644 --- a/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy +++ b/wps_scripts/src/main/groovy/org/noise_planet/noisemodelling/wps/Experimental_Matsim/Traffic_From_Events.groovy @@ -196,11 +196,11 @@ def exec(Connection connection, input) { } int timeBinMin = 0; if (input["timeBinMin"]) { - timeBinSize = input["timeBinMin"] as int + timeBinMin = input["timeBinMin"] as int } int timeBinMax = 86400; if (input["timeBinMax"]) { - timeBinSize = input["timeBinMax"] as int + timeBinMax = input["timeBinMax"] as int } String SRID = "4326" @@ -311,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, Link>) links) @@ -327,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) { @@ -460,6 +462,8 @@ class ProcessOutputEventHandler implements Map, LinkStatStruct> links = new HashMap, LinkStatStruct>() Map, List>> personsInVehicle = new HashMap, List>>() int timeBinSize = 3600; + int timeBinMin = 0; + int timeBinMax = 86400; String SRID = 4326 double populationFactor = 1.0 @@ -470,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 @@ -624,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 @@ -824,7 +836,7 @@ class LinkStatStruct { vehicleCount = vehicleCount / populationFactor // rescale the vehicle count to match the population factor List 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(empty_levels)) }