Jean-Francois Leveque

Ajout sortie

package org.legrog.recommendation.postprocess;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.io.*;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
......@@ -33,6 +35,9 @@ public class PostprocessingRunner implements ApplicationRunner {
@Value("${recommandations.filename}")
private String recommandationsFilename;
@Value("${coverage.filename}")
private String coverageFilename;
private Logger logger = LoggerFactory.getLogger(getClass());
private String sampleFilename;
......@@ -47,10 +52,23 @@ public class PostprocessingRunner implements ApplicationRunner {
PostprocessingExpert expert = new PostprocessingExpert(samples, recommendations);
PostprocessingCoverage coverage = expert.getCoverage();
writeCsvCoverage(coverage, dataDir, coverageFilename);
//todo write coverage in a file to be read by user
//...
}
private void writeCsvCoverage(PostprocessingCoverage coverage, String dataDir, String coverageFilename) throws PostprocessingException {
try {
CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(new File(dataDir, coverageFilename)),
CSVFormat.TDF.withHeader("c1 (item)", "c2 (item-user)", "c3 (item#)"));
csvPrinter.printRecord(coverage.getC1(), coverage.getC2(), coverage.getC3());
csvPrinter.close();
} catch (IOException e) {
throw new PostprocessingException("Can't write coverage file " + dataDir + coverageFilename, e);
}
}
/**
* read csv (TDF) file and map it to a list of PostprocessingSample
*
......