package com.capgemini.reports.formatting.statsgen;

import com.capgemini.reports.database.stats.GenJspStats;
import com.capgemini.reports.database.stats.ReportStatBean;
import org.hibernate.Session;

import javax.servlet.annotation.WebServlet;
import java.text.ParseException;

/**
 * This class generates a CSV file whose contents are statistics on time taken to generate each report (min, avg, max) as well as error and failure rates.
 */
@WebServlet("/downloadStats2")
public class TimingsTableGenerator extends AbstractTableGenerator {
    private static final long serialVersionUID = 8643578161235309835L;

    @Override
    protected String generateTableAsCSV(final String aStartPeriod, final String aEndPeriod) throws ParseException {
        StringBuilder csvContent = new StringBuilder("Code du rapport,Nombre d'exécutions,Erreurs de saisie,Erreurs techniques,Durée minimale,Durée moyenne,Durée maximale");
        for (ReportStatBean report : GenJspStats.getReportStatList(aStartPeriod, aEndPeriod)) {
            csvContent.append('\n').append(report.toCsv());
        }
        return csvContent.toString();
    }

    @Override
    protected String getFilename() {
        return "StatsTempsExecutions";
    }
}
