/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucp.plan;

import ucp.model.UcpMetrics;

/**
 * Class provides a method to count UCP metrics.
 * 
 * @author Trifolium Alpestre
 */
public class UcpAlgorithm {
    
    /**
     * 
     * Method uses UCP algorithm to count UCP metrics.
     * 
     * @param metrics
     */
    public void apply(UcpMetrics metrics)//z obsazenych dat v metrics dopocita zbyle atributy metrics
    {
    
    //vahy pro jednotlive technical factors dle metodiky UCP
    double tWeight [] = {2,2,1,1,1,0.5,0.5,2,1,1,1,1,1};
    //vahy pro jednotlive environmental factors dle metodiky UCP
    double eWeight [] = {1.5,0.5,1,0.5,1,2,-1,-1};
    //tFactor z metodiky UCP 
    double tFactor = 0;
    //eFactor z metodiky UCP 
    double eFactor = 0;
    //Schneider Winters referencni hodnota
    double sw = 0;
    
    int t[] = new int [13];
    int e[] = new int [8];
    
    t = metrics.getT();
    e = metrics.getE();
    
    for (int i=0; i<13; i++)
    {//TFactor = sum (Weight * Assessment)
        tFactor = tFactor + (tWeight[i]*t[i]);
    }

    for (int i=0; i<8; i++)
    {//EFactor = sum (Weight * Assessment)
        eFactor = eFactor + (eWeight[i]*e[i]);
     
     //pocitani referencni hodnoty pro Schneider Winters
     //scitaji se hodnoty e1 az e6 mensi nez 3 a hodnoty e7 az e8 vetsi nez 3
     if ((e[i]<3 && i<6)||(e[i]>3 && i>=6))
     {
        sw = sw + e[i];
     }
    }
    //nastaveni Schneider Winters
    if (sw <= 2){metrics.setSchneiderwinters(20);}
    if (sw == 3 || sw == 4){metrics.setSchneiderwinters(28);}
    if (sw >= 5){metrics.setSchneiderwinters(36);}
    
    //TCF = 0.6 + (0.01 * TFactor)
    metrics.setTcf(0.6+(0.01*tFactor));
    //EF = 1.4 + (-0.03 * EFactor)
    metrics.setEf(1.4+(-0.03*eFactor));
    
    //UCP = UUCP * TCF * EF, kde UUCP = UUCW + UAW
    //zde ale UUCP = complexity, protoze pocitam jen jeden element
    metrics.setUcp(metrics.getComplexity()*metrics.getTcf()*metrics.getEf());
    
    //hours = UCP * hours per UCP
    metrics.setHours(metrics.getUcp()*metrics.getHoursPerUc());
    
    //hours sw = UCP * SchneiderWinters
    metrics.setHoursSW(metrics.getUcp()*metrics.getSchneiderwinters());
    
    //vypocet metrik pro sub elementy
    //subUCP = subUUCP * TCF * EF
    metrics.setSubUCP(metrics.getSubUUCP()*metrics.getTcf()*metrics.getEf());
    //subCasesHours = subCaseHours + subUCP * hours per UCP
    metrics.setSubCasesHours(metrics.getSubCasesHours() + (metrics.getSubUCP()*metrics.getHoursPerUc()));
    //subCasesHours = subCaseHours + subUCP * hours per UCP
    metrics.setSubCasesHoursSW(metrics.getSubCasesHoursSW() + (metrics.getSubUCP()*metrics.getSchneiderwinters()));

    //subUUCP bylo pouzito pro vypocet subCasesHours
    //musi se proto vynulovat aby se v nadrazenych elementech nevyscitavaly subUUCP i subCasesHours
    //duplicitne by se totiz prenasela na nadrazeny element pracnost jak v hodinach tak v komplexnosti
    metrics.setSubUUCP(0);
    }

}
