@@ -61,6 +61,8 @@ public final class Runner<S extends Scenario> {
61
61
private static final String YEARLY_DATA_FILENAME = "yearly_data.csv" ;
62
62
private static final String FISHER_YEARLY_DATA_FILENAME = "fisher_yearly_data.csv" ;
63
63
private static final String FISHER_DAILY_DATA_FILENAME = "fisher_daily_data.csv" ;
64
+ private static final String FAD_DAILY_DATA_FILENAME = "fad_daily_data.csv" ;
65
+
64
66
private static final String RUNS_FILENAME = "runs.csv" ;
65
67
private static final String POLICIES_FILENAME = "policies.csv" ;
66
68
private static final String SCENARIOS_FOLDER = "scenarios" ;
@@ -69,7 +71,8 @@ public final class Runner<S extends Scenario> {
69
71
70
72
private final Supplier <? extends S > scenarioSupplier ;
71
73
private final Path outputPath ;
72
- private final Multimap <Path , AlgorithmFactory <Iterable <? extends RowProvider >>> rowProviderFactories =
74
+ private final Multimap <Path , AlgorithmFactory <Iterable <? extends RowProvider >>>
75
+ rowProviderFactories =
73
76
HashMultimap .create ();
74
77
private boolean parallel = true ;
75
78
private boolean writeScenarioToFile = false ;
@@ -237,23 +240,29 @@ private void writeScenarioToFile(final State runnerState) {
237
240
final Path scenariosFolder = outputPath .resolve (SCENARIOS_FOLDER );
238
241
Files .createDirectories (scenariosFolder );
239
242
final Path scenarioFile =
240
- scenariosFolder .resolve (runnerState .getPolicy ().getName ().replaceAll ("[^a-zA-Z0-9-_.]" , "_" ) + ".yaml" );
243
+ scenariosFolder .resolve (runnerState
244
+ .getPolicy ()
245
+ .getName ()
246
+ .replaceAll ("[^a-zA-Z0-9-_.]" , "_" ) + ".yaml" );
241
247
new FishYAML ().dump (runnerState .getScenario (), new FileWriter (scenarioFile .toFile ()));
242
248
} catch (final IOException e ) {
243
249
throw new RuntimeException (e );
244
250
}
245
251
}
246
252
247
253
private Multimap <Path , RowProvider > makeRowProviders (final State state ) {
248
- final ImmutableMultimap .Builder <Path , RowProvider > rowProviders = ImmutableMultimap .builder ();
254
+ final ImmutableMultimap .Builder <Path , RowProvider > rowProviders =
255
+ ImmutableMultimap .builder ();
249
256
rowProviders .put (outputPath .resolve (RUNS_FILENAME ), state );
250
257
rowProviders .put (outputPath .resolve (POLICIES_FILENAME ), state .policy );
251
- rowProviderFactories .forEach ((path , factory ) -> factory .apply (state .model ).forEach (rowProvider -> {
252
- if (rowProvider instanceof Startable ) {
253
- state .model .registerStartable ((Startable ) rowProvider );
254
- }
255
- rowProviders .put (path , rowProvider );
256
- }));
258
+ rowProviderFactories .forEach ((path , factory ) -> factory
259
+ .apply (state .model )
260
+ .forEach (rowProvider -> {
261
+ if (rowProvider instanceof Startable ) {
262
+ state .model .registerStartable ((Startable ) rowProvider );
263
+ }
264
+ rowProviders .put (path , rowProvider );
265
+ }));
257
266
return rowProviders .build ();
258
267
}
259
268
@@ -271,9 +280,17 @@ private void writeOutputs(
271
280
if (!activeProviders .isEmpty ()) {
272
281
synchronized (overwriteFiles ) {
273
282
final boolean overwrite =
274
- overwriteFiles .computeIfAbsent (outputPath , __ -> new AtomicBoolean (true )).getAndSet (false );
275
- try (final Writer fileWriter = new FileWriter (outputPath .toFile (), !overwrite )) {
276
- final CsvWriter csvWriter = new CsvWriter (new BufferedWriter (fileWriter ), csvWriterSettings );
283
+ overwriteFiles
284
+ .computeIfAbsent (outputPath , __ -> new AtomicBoolean (true ))
285
+ .getAndSet (false );
286
+ try (final Writer fileWriter = new FileWriter (
287
+ outputPath .toFile (),
288
+ !overwrite
289
+ )) {
290
+ final CsvWriter csvWriter = new CsvWriter (
291
+ new BufferedWriter (fileWriter ),
292
+ csvWriterSettings
293
+ );
277
294
writeRows (csvWriter , activeProviders , runNumber , overwrite );
278
295
} catch (final IOException e ) {
279
296
throw new IllegalStateException ("Writing to " + outputPath + " failed." , e );
@@ -326,6 +343,21 @@ public Runner<S> requestFisherDailyData(final Predicate<String> columnNamePredic
326
343
);
327
344
}
328
345
346
+ public Runner <S > requestFadDailyData (final Predicate <String > columnNamePredicate ) {
347
+ return registerRowProviders (
348
+ FAD_DAILY_DATA_FILENAME ,
349
+ fishState -> fishState
350
+ .getFishers ()
351
+ .stream ()
352
+ .map (fisher -> new TidyFisherDailyData (
353
+ fisher .getDailyData (),
354
+ columnNamePredicate ,
355
+ fisher .getTagsList ().get (0 )
356
+ ))
357
+ .collect (toImmutableList ())
358
+ );
359
+ }
360
+
329
361
@ SuppressWarnings ({"WeakerAccess" , "unused" })
330
362
public Runner <S > requestYearlyData (final Predicate <String > columnNamePredicate ) {
331
363
return registerRowProvider (YEARLY_DATA_FILENAME , fishState -> new TidyYearlyData (
@@ -338,7 +370,10 @@ public Runner<S> registerRowProvider(
338
370
@ SuppressWarnings ("SameParameterValue" ) final String fileName ,
339
371
final AlgorithmFactory <? extends RowProvider > rowProviderFactory
340
372
) {
341
- registerRowProviders (fileName , fishState -> ImmutableList .of (rowProviderFactory .apply (fishState )));
373
+ registerRowProviders (
374
+ fileName ,
375
+ fishState -> ImmutableList .of (rowProviderFactory .apply (fishState ))
376
+ );
342
377
return this ;
343
378
}
344
379
@@ -409,8 +444,17 @@ public LocalDateTime getStartTime() {
409
444
410
445
void printStep () {
411
446
logger .info (String .format (
412
- "Run %" + runDigits + "d / %" + runDigits + "d, " + "step %5d (year %" + yearDigits + "d / %" +
413
- yearDigits + "d, " + "day %3d), policy: %s" ,
447
+ "Run %" +
448
+ runDigits +
449
+ "d / %" +
450
+ runDigits +
451
+ "d, " +
452
+ "step %5d (year %" +
453
+ yearDigits +
454
+ "d / %" +
455
+ yearDigits +
456
+ "d, " +
457
+ "day %3d), policy: %s" ,
414
458
runNumber ,
415
459
numRuns ,
416
460
model .getStep (),
0 commit comments