package cz.muni.disa.adamiss.se;

import cz.muni.disa.adamiss.core.objects.TransactionFile;
import cz.muni.disa.adamiss.se.common.Dataset;
import cz.muni.disa.adamiss.se.stats.objects.DBReport;
import cz.muni.disa.adamiss.se.structures.DatasetContainer;
import javafx.util.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Ignore;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainTest {

    Logger logger = LogManager.getLogger(MainTest.class);


    @Test
    @Ignore
    public void MainTest(){
        logger.debug("Loading datasets.");
        List<Pair<Dataset, TransactionFile>> datasets = Main.getDatasets();

        logger.debug("Analysing datasets.");
        List<DatasetContainer> containers = new ArrayList<>();
        List<DBReport> reports = new ArrayList<>();
        for (var pair : datasets) {
            logger.debug("Analysing: " + pair.getKey().name());
            DBReport report = Main.getDatabaseStats(pair.getKey(), pair.getValue());
            reports.add(report);

            containers.add(new DatasetContainer(pair.getKey(), pair.getValue(), report));
        }

        SimpleDateFormat formatter = new SimpleDateFormat();
        String outputFileDate = formatter.format(new Date());

        logger.debug("Saving dataset stats.");
        String dbReportCSV = DBReport.toCSVWithHeader(reports);
        Main.saveAsCSV(dbReportCSV.toString(), "DatasetStats" + outputFileDate);
    }
}
