Jean-Francois Leveque

Ajout sortie

1 package org.legrog.recommendation.postprocess; 1 package org.legrog.recommendation.postprocess;
2 2
3 import org.apache.commons.csv.CSVFormat; 3 import org.apache.commons.csv.CSVFormat;
4 +import org.apache.commons.csv.CSVPrinter;
4 import org.apache.commons.csv.CSVRecord; 5 import org.apache.commons.csv.CSVRecord;
5 import org.slf4j.Logger; 6 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
...@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component; ...@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
12 import java.io.*; 13 import java.io.*;
13 import java.util.List; 14 import java.util.List;
14 import java.util.Properties; 15 import java.util.Properties;
16 +import java.util.Set;
15 import java.util.stream.Collectors; 17 import java.util.stream.Collectors;
16 import java.util.stream.StreamSupport; 18 import java.util.stream.StreamSupport;
17 19
...@@ -33,6 +35,9 @@ public class PostprocessingRunner implements ApplicationRunner { ...@@ -33,6 +35,9 @@ public class PostprocessingRunner implements ApplicationRunner {
33 @Value("${recommandations.filename}") 35 @Value("${recommandations.filename}")
34 private String recommandationsFilename; 36 private String recommandationsFilename;
35 37
38 + @Value("${coverage.filename}")
39 + private String coverageFilename;
40 +
36 private Logger logger = LoggerFactory.getLogger(getClass()); 41 private Logger logger = LoggerFactory.getLogger(getClass());
37 private String sampleFilename; 42 private String sampleFilename;
38 43
...@@ -47,10 +52,23 @@ public class PostprocessingRunner implements ApplicationRunner { ...@@ -47,10 +52,23 @@ public class PostprocessingRunner implements ApplicationRunner {
47 PostprocessingExpert expert = new PostprocessingExpert(samples, recommendations); 52 PostprocessingExpert expert = new PostprocessingExpert(samples, recommendations);
48 PostprocessingCoverage coverage = expert.getCoverage(); 53 PostprocessingCoverage coverage = expert.getCoverage();
49 54
55 + writeCsvCoverage(coverage, dataDir, coverageFilename);
50 //todo write coverage in a file to be read by user 56 //todo write coverage in a file to be read by user
51 //... 57 //...
52 } 58 }
53 59
60 + private void writeCsvCoverage(PostprocessingCoverage coverage, String dataDir, String coverageFilename) throws PostprocessingException {
61 + try {
62 + CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(new File(dataDir, coverageFilename)),
63 + CSVFormat.TDF.withHeader("c1 (item)", "c2 (item-user)", "c3 (item#)"));
64 + csvPrinter.printRecord(coverage.getC1(), coverage.getC2(), coverage.getC3());
65 + csvPrinter.close();
66 + } catch (IOException e) {
67 + throw new PostprocessingException("Can't write coverage file " + dataDir + coverageFilename, e);
68 + }
69 +
70 + }
71 +
54 /** 72 /**
55 * read csv (TDF) file and map it to a list of PostprocessingSample 73 * read csv (TDF) file and map it to a list of PostprocessingSample
56 * 74 *
......