Skip to content

Commit

Permalink
uncomment more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Feb 5, 2025
1 parent e026977 commit 2fd2235
Show file tree
Hide file tree
Showing 11 changed files with 850 additions and 1,124 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
public class SceneWithEmission extends SceneWithAttenuation {
/** Old style DEN columns traffic period */
Map<String, Integer> sourceFieldsCache = new HashMap<>();
Map<String, Integer> sourceEmissionFieldsCache = new HashMap<>();

// For each source primary key give the map between period and source power spectrum values
Expand All @@ -41,7 +40,7 @@ public SceneWithEmission() {

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);
double[][] lw = EmissionTableGenerator.computeLw(rs, sceneDatabaseInputSettings.coefficientVersion, sourceFieldNames);
// Will generate D E N and DEN emission
for (EmissionTableGenerator.STANDARD_PERIOD period : EmissionTableGenerator.STANDARD_PERIOD.values()) {
addSourceEmission(pk, EmissionTableGenerator.STANDARD_PERIOD_VALUE[period.ordinal()], lw[period.ordinal()]);
Expand Down Expand Up @@ -146,6 +145,13 @@ public void addSourceEmission(Long sourcePrimaryKey, String period, double[] wj)
sourceEmissions.add(new PeriodEmission(period, wj));
}

@Override
public void clearSources() {
super.clearSources();
sourceEmissionFieldsCache.clear();
wjSources.clear();
}

public static class PeriodEmission {
public final String period;
public final double[] emission;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@
import org.noise_planet.noisemodelling.jdbc.NoiseMapDatabaseParameters;
import org.noise_planet.noisemodelling.jdbc.input.SceneWithEmission;
import org.noise_planet.noisemodelling.pathfinder.CutPlaneVisitorFactory;
import org.noise_planet.noisemodelling.pathfinder.ThreadPool;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.JVMMemoryMetric;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ProfilerThread;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ProgressMetric;
import org.noise_planet.noisemodelling.pathfinder.utils.profiler.ReceiverStatsMetric;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class DefaultCutPlaneProcessing implements NoiseMapByReceiverMaker.IComputeRaysOutFactory {
public int DEFAULT_END_WRITING_THREAD_TIMEOUT = 30; // timeout for write thread stop in seconds
ResultsCache resultsCache = new ResultsCache();
final NoiseMapDatabaseParameters noiseMapDatabaseParameters;
NoiseMapWriter noiseMapWriter;
Thread tableWriterThread;
ProfilerThread profilerThread;
Connection connection;
// Process status
AtomicBoolean exitWhenDone;
AtomicBoolean aborted;
NoiseMapByReceiverMaker noiseMapByReceiverMaker;
ThreadPool postProcessingThreadPool = new ThreadPool();
Future<Boolean> noiseMapWriterFuture;

/**
* @param noiseMapDatabaseParameters Database settings
Expand All @@ -51,52 +56,46 @@ public CutPlaneVisitorFactory create(SceneWithEmission scene) {
public void initialize(Connection connection, NoiseMapByReceiverMaker noiseMapByReceiverMaker) throws SQLException {
this.connection = connection;
this.noiseMapByReceiverMaker = noiseMapByReceiverMaker;
if(noiseMapDatabaseParameters.CSVProfilerOutputPath != null) {
profilerThread = new ProfilerThread(noiseMapDatabaseParameters.CSVProfilerOutputPath);
profilerThread.addMetric(resultsCache);
profilerThread.addMetric(new JVMMemoryMetric());
profilerThread.addMetric(new ReceiverStatsMetric());
profilerThread.setWriteInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
profilerThread.setFlushInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
}
}

/**
* Start creating and filling database tables.
* This method is blocked until the computation is completed or if there is an issue
*/
@Override
public void start(ProgressVisitor progressLogger) {
public void start(ProgressVisitor progressLogger) throws SQLException {
noiseMapWriter = new NoiseMapWriter(connection, noiseMapByReceiverMaker, resultsCache, exitWhenDone, aborted);
exitWhenDone.set(false);
tableWriterThread = new Thread(noiseMapWriter);
tableWriterThread.start();
if(noiseMapDatabaseParameters.CSVProfilerOutputPath != null) {
profilerThread = new ProfilerThread(noiseMapDatabaseParameters.CSVProfilerOutputPath);
profilerThread.addMetric(resultsCache);
if(profilerThread != null) {
profilerThread.addMetric(new ProgressMetric(progressLogger));
profilerThread.addMetric(new JVMMemoryMetric());
profilerThread.addMetric(new ReceiverStatsMetric());
profilerThread.setWriteInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
profilerThread.setFlushInterval(noiseMapDatabaseParameters.CSVProfilerWriteInterval);
new Thread(profilerThread).start();
postProcessingThreadPool.submit(profilerThread);
}
while (!noiseMapWriter.started && !aborted.get()) {
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// ignore
break;
}
try {
noiseMapWriter.init();
} catch (Exception ex) {
throw new SQLException(ex);
}
noiseMapWriterFuture = postProcessingThreadPool.submitBlocking(noiseMapWriter);
}

/**
* Write the last results and stop the sql writing thread
* This method is blocked until the data is written or if there is an issue
*/
@Override
public void stop() {
public void stop() throws SQLException {
exitWhenDone.set(true);
while (tableWriterThread != null && tableWriterThread.isAlive()) {
try {
Thread.sleep(150);
} catch (InterruptedException e) {
// ignore
break;
}
try {
noiseMapWriterFuture.get(DEFAULT_END_WRITING_THREAD_TIMEOUT, TimeUnit.SECONDS);
} catch (Exception e) {
throw new SQLException(e);
}
}
}
Loading

0 comments on commit 2fd2235

Please sign in to comment.