Skip to content

Commit

Permalink
fix missing insert column ?
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Feb 4, 2025
1 parent 6be0780 commit da0dc83
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public class SceneWithEmission extends SceneWithAttenuation {
Map<String, Integer> sourceFieldsCache = new HashMap<>();
Map<String, Integer> sourceEmissionFieldsCache = new HashMap<>();

/**
* Set of unique power spectrum. Key is the hash of the spectrum. Power spectrum in energetic e = pow(10, dbVal / 10.0)
*/
public Map<Integer, double[]> powerSpectrum = new HashMap<>();

// For each source primary key give the map between period and source power spectrum hash value
public Map<Long, ArrayList<PeriodEmission>> wjSources = new HashMap<>();

Expand All @@ -44,12 +39,6 @@ public SceneWithEmission(ProfileBuilder profileBuilder) {
public SceneWithEmission() {
}

int updatePowerSpectrumSet(double[] wj) {
int hashCode = Arrays.hashCode(wj);
powerSpectrum.putIfAbsent(hashCode, wj);
return hashCode;
}

public void processTrafficFlowDEN(Long pk, SpatialResultSet rs) throws SQLException {
// Source table PK, GEOM, LV_D, LV_E, LV_N ...
double[][] lw = EmissionTableGenerator.computeLw(rs, sceneDatabaseInputSettings.coefficientVersion, sourceFieldsCache);
Expand Down Expand Up @@ -119,7 +108,9 @@ private void processEmissionDEN(Long pk, SpatialResultSet rs) throws SQLExceptio
String periodFieldName = EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()];
for (int i = 0, frequencyArraySize = frequencyArray.size(); i < frequencyArraySize; i++) {
Integer frequency = frequencyArray.get(i);
lw[i] = AcousticIndicatorsFunctions.dBToW(rs.getDouble(sceneDatabaseInputSettings.lwFrequencyPrepend + periodFieldName + frequency));
final String tableFieldName = sceneDatabaseInputSettings.lwFrequencyPrepend + periodFieldName + frequency;
lw[i] = AcousticIndicatorsFunctions.dBToW(
rs.getDouble(tableFieldName));
}
addSourceEmission(pk, periodFieldName, lw);
lden = sumArray(lden, AcousticIndicatorsFunctions.multiplicationArray(lw, EmissionTableGenerator.RATIOS[period.ordinal()]));
Expand All @@ -145,24 +136,23 @@ public void addSourceEmission(Long pk, ResultSet rs) throws SQLException {
* @param wj
*/
public void addSourceEmission(Long sourcePrimaryKey, String period, double[] wj) {
int powerSpectrumHash = updatePowerSpectrumSet(wj);
ArrayList<PeriodEmission> sourceEmissions;
if(wjSources.containsKey(sourcePrimaryKey)) {
sourceEmissions = wjSources.get(sourcePrimaryKey);
} else {
sourceEmissions = new ArrayList<>();
wjSources.put(sourcePrimaryKey, sourceEmissions);
}
sourceEmissions.add(new PeriodEmission(period, powerSpectrumHash));
sourceEmissions.add(new PeriodEmission(period, wj));
}

public static class PeriodEmission {
public final String period;
public final int emissionHash;
public final double[] emission;

public PeriodEmission(String period, int emissionHash) {
public PeriodEmission(String period, double[] emission) {
this.period = period;
this.emissionHash = emissionHash;
this.emission = emission;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public PathSearchStrategy onNewCutPlane(CutProfile cutProfile) {
defaultAttenuation = dBToW(multiThread.computeCnossosAttenuation(scene.defaultCnossosParameters, cnossosPath));
attenuation = defaultAttenuation;
}
double[] levels = multiplicationArray(attenuation, scene.powerSpectrum.get(periodEmission.emissionHash));
double[] levels = multiplicationArray(attenuation, periodEmission.emission);
ReceiverNoiseLevel receiverNoiseLevel =
new ReceiverNoiseLevel(new PathFinder.SourcePointInfo(source),
new PathFinder.ReceiverPointInfo(receiver), period, levels);
Expand Down Expand Up @@ -251,7 +251,7 @@ public void startReceiver(PathFinder.ReceiverPointInfo receiver, Collection<Path
if(scene.wjSources.containsKey(sourcePointInfo.sourcePk)) {
ArrayList<SceneWithEmission.PeriodEmission> emissions = scene.wjSources.get(sourcePointInfo.sourcePk);
for (SceneWithEmission.PeriodEmission periodEmission : emissions) {
double[] wjAtReceiver = multiplicationArray(attenuation, scene.powerSpectrum.get(periodEmission.emissionHash));
double[] wjAtReceiver = multiplicationArray(attenuation, periodEmission.emission);
double sumPower = sumArray(wjAtReceiver);
double previousPowerAtLocation = maximumWjExpectedSplAtReceiver.getOrDefault(sourceHashCode, 0.0);
if(sumPower > previousPowerAtLocation) {
Expand Down Expand Up @@ -363,7 +363,7 @@ public void finalizeReceiver(PathFinder.ReceiverPointInfo receiver) {
for (Map.Entry<Integer, TimePeriodParameters> periodParametersEntry : receiverAttenuationList.entrySet()) {
TimePeriodParameters periodParameters = periodParametersEntry.getValue();
for (Map.Entry<String, double[]> levelsAtPeriod : periodParameters.levelsPerPeriod.entrySet()) {
pushInStack(multiThread.receiversAttenuationLevels, new ReceiverNoiseLevel(periodParameters.source,
pushInStack(multiThread.resultsCache.receiverLevels, new ReceiverNoiseLevel(periodParameters.source,
receiver, levelsAtPeriod.getKey(),
AcousticIndicatorsFunctions.wToDb(levelsAtPeriod.getValue())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<ReceiverNoiseLevel> st
if(!databaseParameters.mergeSources) {
query.append(", ?"); // ID_SOURCE
}
if(!exportPeriod) {
if(exportPeriod) {
query.append(", ?"); // PERIOD
}
if(databaseParameters.exportReceiverPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package org.noise_planet.noisemodelling.jdbc;

import org.h2gis.api.EmptyProgressVisitor;
import org.h2gis.functions.factory.H2GISDBFactory;
import org.h2gis.utilities.JDBCUtilities;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.*;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
Expand All @@ -28,7 +30,9 @@
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -503,7 +507,7 @@ public void eastWestGroundTest() {
// }
//
//
private double testIgnoreNonSignificantSourcesParam(Connection connection, double maxError) throws SQLException, IOException {
private List<Long> testIgnoreNonSignificantSourcesParam(Connection connection, double maxError) throws SQLException, IOException {
// Init NoiseModelling
NoiseMapByReceiverMaker noiseMap = new NoiseMapByReceiverMaker("BUILDINGS",
"LW_ROADS", "RECEIVERS");
Expand All @@ -513,16 +517,27 @@ private double testIgnoreNonSignificantSourcesParam(Connection connection, doubl
noiseMap.setThreadCount(1);
noiseMap.setComputeHorizontalDiffraction(true);
noiseMap.setComputeVerticalDiffraction(true);
noiseMap.getNoiseMapDatabaseParameters().maximumError = maxError;
NoiseMapDatabaseParameters parameters = noiseMap.getNoiseMapDatabaseParameters();
parameters.mergeSources = false;
parameters.maximumError = maxError;
noiseMap.setInputMode(SceneWithEmission.SceneDatabaseInputSettings.INPUT_MODE.INPUT_MODE_LW_DEN);

// Building height field name
noiseMap.setHeightField("HEIGHT");


noiseMap.setGridDim(1);

noiseMap.run(connection, new EmptyProgressVisitor());

return 0;
Statement st = connection.createStatement();
List<Long> sourcePks = new LinkedList<>();
try(ResultSet rs = st.executeQuery("SELECT DISTINCT IDSOURCE FROM " + parameters.receiversLevelTable)) {
while (rs.next()) {
sourcePks.add(rs.getLong(1));
}
}
return sourcePks;
}

static public void assertInferiorThan(double expected, double actual) {
Expand All @@ -542,10 +557,10 @@ public void testIgnoreNonSignificantSources() throws Exception {
"testReceiverOverBuilding", true, ""))) {
try (Statement st = connection.createStatement()) {
st.execute(Utils.getRunScriptRes("scenario_skip_far_source.sql"));
double levelAllSources = testIgnoreNonSignificantSourcesParam(connection, 0.);
double levelIgnoreFarSources = testIgnoreNonSignificantSourcesParam(connection, maxError);
assertNotEquals(levelAllSources, levelIgnoreFarSources, 0.0001);
assertInferiorThan(Math.abs(levelAllSources - levelIgnoreFarSources), maxError);
List<Long> allSourcesPk = testIgnoreNonSignificantSourcesParam(connection, 0.);
List<Long> ignoreFarSourcesPk = testIgnoreNonSignificantSourcesParam(connection, maxError);
assertEquals(2, allSourcesPk.size());
assertEquals(1, ignoreFarSourcesPk.size());
}
}
}
Expand Down

0 comments on commit da0dc83

Please sign in to comment.