Commit b4fbc276 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

Log for population dynamics and Logger API syntax enhancements

parent 6b753892
Pipeline #40572 passed with stages
in 5 minutes and 19 seconds
......@@ -19,7 +19,7 @@ public class DynamicsLogger {
private String separator = ", ";
private String path = "data/out";
public DynamicsLogger(String className, String timeStamp, String header) {
public DynamicsLogger(String className, String timeStamp, String... headers) {
try {
Files.createDirectories(Paths.get("data/out/" + timeStamp + "/logs/"));
fileHandler = new FileHandler("data/out/" + timeStamp + "/logs/" + className + ".csv", false);
......@@ -29,7 +29,7 @@ public class DynamicsLogger {
logger = Logger.getLogger(className);
logger.setUseParentHandlers(false);
logger.addHandler(fileHandler);
fileHandler.setFormatter(new DynamicsLogFormatter(header));
fileHandler.setFormatter(new DynamicsLogFormatter(String.join(separator, headers)));
}
......@@ -41,6 +41,16 @@ public class DynamicsLogger {
logger.info(timestep + separator + message);
}
public void log(int timestep, Object... objects) {
StringBuilder buffer = new StringBuilder();
buffer.append(timestep);
for (Object object : objects) {
buffer.append(separator);
buffer.append(object);
}
logger.info(buffer.toString());
}
public void logQuantities(int timestep, GeoArea geoArea, Stocks quantities, String label) {
for (Map.Entry<Product, Float> quantity: quantities.entrySet()) {
logger.info(timestep + separator + geoArea.getLabel() + separator + quantity.getKey() + separator
......
......@@ -55,6 +55,7 @@ public class PopulationDynamicsByAgeClass extends Dynamics {
idx -> idx>=r_threshold ? (int)Math.round(r_factor * ageclasses[idx]) : 0
).toArray();
transmission.process(context, geoAreas, farmers, installationsAges, retirements);
logger.log(context.getTimestep(), farmers.size(), Arrays.stream(installations).sum(), Arrays.stream(retirements).sum());
}
private int getAge(int ageclass) {
......@@ -63,7 +64,7 @@ public class PopulationDynamicsByAgeClass extends Dynamics {
@Override
public void initLogger() {
logger = new DynamicsLogger(this.getClass().getSimpleName(), super.timeStamp, "HEADER");
logger = new DynamicsLogger(this.getClass().getSimpleName(), super.timeStamp, "Timestep", "nb farmers","nb installations", "nb retirements");
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment