Search in sources :

Example 26 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReport method getReport.

/**
 * @param simulationRunMetadata the <code>SimulationRunMetadata</code> to print out
 * @param modelType
 * @return
 * @throws IOException
 */
public String getReport(SimulationRunMetadata simulationRunMetadata, ScenarioSimulationModel.Type modelType) {
    StringBuilder stringBuilder = new StringBuilder();
    try (CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT.withNullString(""))) {
        generateOverallStatsHeader(printer, modelType);
        printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
        Map<String, Integer> outputCounter = simulationRunMetadata.getOutputCounter();
        if (outputCounter != null && !outputCounter.isEmpty()) {
            printer.println();
            generateRulesCounterHeader(printer, modelType);
            for (Map.Entry<String, Integer> entry : outputCounter.entrySet()) {
                printRulesCounterLine(printer, entry.getKey(), entry.getValue());
            }
        }
        List<AuditLogLine> auditLogLines = simulationRunMetadata.getAuditLog().getAuditLogLines();
        if (auditLogLines != null && !auditLogLines.isEmpty()) {
            printer.println();
            generateAuditLogHeader(printer, modelType);
            for (AuditLogLine auditLogLine : auditLogLines) {
                printAuditLogLine(auditLogLine, printer);
            }
        }
    } catch (IOException e) {
        throw ExceptionUtilities.handleException(e);
    }
    return stringBuilder.toString();
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) IOException(java.io.IOException) Map(java.util.Map)

Example 27 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.

the class ScenarioCsvImportExport method exportData.

public String exportData(AbstractScesimModel<? extends AbstractScesimData> scesimModel) throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    List<FactMapping> factMappings = scesimModel.getScesimModelDescriptor().getUnmodifiableFactMappings();
    CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT);
    generateHeader(factMappings, printer);
    for (AbstractScesimData scesimData : scesimModel.getUnmodifiableData()) {
        List<Object> values = new ArrayList<>();
        for (FactMapping factMapping : factMappings) {
            Optional<FactMappingValue> factMappingValue = scesimData.getFactMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier());
            values.add(factMappingValue.map(FactMappingValue::getRawValue).orElse(""));
        }
        printer.printRecord(values.toArray());
    }
    printer.close();
    return stringBuilder.toString();
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ArrayList(java.util.ArrayList)

Example 28 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReportTest method printOverallStatsLine.

@Test
public void printOverallStatsLine() throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    CSVPrinter printer = getCSVPrinter(stringBuilder);
    AuditLog auditLog = new AuditLog();
    auditLog.addAuditLogLine(getAuditLogLine());
    SimulationRunMetadata simulationRunMetadata = getSimulationRunMetadata(auditLog);
    scenarioCsvDownloadReport.printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
    String retrieved = stringBuilder.toString();
    List<String> data = Arrays.asList(String.valueOf(simulationRunMetadata.getAvailable()), String.valueOf(simulationRunMetadata.getExecuted()), String.valueOf(simulationRunMetadata.getCoveragePercentage()));
    commonCheckRetrievedString(retrieved, data);
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Test(org.junit.Test)

Example 29 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReportTest method generateOverallStatsHeaderDMN.

@Test
public void generateOverallStatsHeaderDMN() throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    CSVPrinter printer = getCSVPrinter(stringBuilder);
    scenarioCsvDownloadReport.generateOverallStatsHeader(printer, DMN);
    String retrieved = stringBuilder.toString();
    commonCheckHeader(DMN_OVERALL_STATS_HEADER, retrieved);
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) Test(org.junit.Test)

Example 30 with CSVPrinter

use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReportTest method generateRulesCounterHeaderRULE.

@Test
public void generateRulesCounterHeaderRULE() throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    CSVPrinter printer = getCSVPrinter(stringBuilder);
    scenarioCsvDownloadReport.generateRulesCounterHeader(printer, ScenarioSimulationModel.Type.RULE);
    String retrieved = stringBuilder.toString();
    commonCheckHeader(RULE_COUNTER_HEADER, retrieved);
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) Test(org.junit.Test)

Aggregations

CSVPrinter (org.apache.commons.csv.CSVPrinter)75 IOException (java.io.IOException)26 CSVFormat (org.apache.commons.csv.CSVFormat)21 OutputStreamWriter (java.io.OutputStreamWriter)18 StringWriter (java.io.StringWriter)15 ArrayList (java.util.ArrayList)15 Writer (java.io.Writer)13 FileOutputStream (java.io.FileOutputStream)12 Test (org.junit.Test)11 FileWriter (java.io.FileWriter)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 BufferedWriter (java.io.BufferedWriter)7 PrintWriter (java.io.PrintWriter)5 JSONArray (org.json.JSONArray)5 File (java.io.File)4 Map (java.util.Map)4 Word (ai.elimu.model.content.Word)3 Path (java.nio.file.Path)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 Letter (ai.elimu.model.content.Letter)2