package br.uem.din.architectureEvolution.caseStudy;

import br.uem.din.architectureEvolution.representation.Architecture;
import br.uem.din.metrics.concernDrivenMetrics.concernCohesion.LCC;
import br.uem.din.metrics.concernDrivenMetrics.concernCohesion.LCCComponentResult;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAC;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDACResult;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAI;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAIResult;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAO;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAOResult;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.CIBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.CIBCResult;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.IIBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.IIBCResult;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.OOBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.OOBCResult;

public class MetricsMeasurer {

	public void evalArchitecture(Architecture architecture, int number) {
		System.out.println("-----------------------------------");
		System.out.println("Architecture " + number);
		System.out.println();
		
		LCC lcc = new LCC(architecture);
		long sum = 0;
		for (LCCComponentResult result : lcc.getResults())
			sum += result.numberOfConcerns();
		float lccAverage = sum / (float)lcc.getResults().size();
	
		System.out.println("------ CBI: " + lccAverage);
		
		long cdacSum = 0;
		long cdaiSum = 0;
		long cdaoSum = 0;
		
		CDAC cdac = new CDAC(architecture);
		for (CDACResult result : cdac.getResults()) {
			cdacSum += result.getElements().size();
			System.out.println(result.toString());
		}
		System.out.println("--- CDAC: " + cdacSum);
		
		CDAI cdai = new CDAI(architecture);
		for (CDAIResult result : cdai.getResults()){
			cdaiSum += result.getElements().size();
			System.out.println(result.toString());			
		}
		
		System.out.println("--- CDAI: " + cdaiSum);
		
		CDAO cdao = new CDAO(architecture);
		for (CDAOResult result : cdao.getResults()){
			cdaoSum += result.getElements().size();
			System.out.println(result.toString());			
		}
		System.out.println("--- CDAO: " + cdaoSum);
		System.out.println("------ DDI: " + (cdacSum + cdaiSum + cdaoSum));
		
		long cibcSum = 0;
		long iibcSum = 0;
		long oobcSum = 0;
		
		CIBC cibc = new CIBC(architecture);
		for (CIBCResult c : cibc.getResults().values()){
			cibcSum += c.getInterlacedConcerns().size();
			System.out.println(c.toString());			
		}
		System.out.println("--- CIBC: " + cibcSum);
		
		IIBC iibc = new IIBC(architecture);
		for (IIBCResult c : iibc.getResults().values()){
			iibcSum += c.getInterlacedConcerns().size();
			System.out.println(c.toString());
		}
		System.out.println("--- IIBC: " + iibcSum);
		
		OOBC oobc = new OOBC(architecture);
		for (OOBCResult c : oobc.getResults().values()){
			oobcSum += c.getInterlacedConcerns().size();
			System.out.println(c.toString());			
		}
		System.out.println("--- OOBC: " + oobcSum);
		
		System.out.println("------ EEI: " + (cibcSum + iibcSum + oobcSum));
		
		float finalSum = lccAverage + cdacSum + cdaiSum + cdaoSum + cibcSum + iibcSum + oobcSum;
		
		System.out.println("--------- Final Sum: " + finalSum);
		architecture.save("", number);
	}
}
