package cz.muni.disa.adamiss.se.stats.collectors;

import cz.muni.disa.adamiss.core.objects.Transaction;
import cz.muni.disa.adamiss.core.objects.TransactionFile;
import cz.muni.disa.adamiss.se.stats.objects.DBReport;

public class DatabaseStatCollector {

    public DBReport collect(TransactionFile database){
        UniqueItemCounter uniqueItemCounter = new UniqueItemCounter();
        float avgLength = 0f;
        int n = 0;

        for(Transaction transaction :database.getTransactions()) {
                n += 1;
                avgLength = avgLength + ((transaction.getData().size()-avgLength)/n);
                uniqueItemCounter.processTransaction(transaction);

        }

        return new DBReport(
                database.getTransactions().size(),
                uniqueItemCounter.getUniqueItemCount(),
                avgLength,
                uniqueItemCounter.getUniqueItemDistribution());
    }


}
