#include "stdafx.h"
#include "ServiceInfoDTO.h"

void ServiceInfoDTO::setID(string _serviceName)
{
	serviceName = _serviceName;
}

string ServiceInfoDTO::getID()
{
	return serviceName;
}

double ServiceInfoDTO::getServiceAvgQueueSize()
{
	return avgQueueSize;	
}

/*double ServiceInfoDTO::getServiceAvgServiceTime()
{
	return avgServiceTime;
}

void ServiceInfoDTO::updateServiceLife(double serviceTime){
	numIterations++;
	serviceTimes->push_back(serviceTime);
}*/

int ServiceInfoDTO::getServiceActualQueueSize()
{
	return serviceActualQueueSize;
}

int ServiceInfoDTO::getMaximumQueueSize()
{
	return maximumQueueSize;
}

double ServiceInfoDTO::getServiceUseRate()
{
	return serviceUseRate;
}

void ServiceInfoDTO::updateQueue(int queueSize){

	if (queueSize > 0)
		queueBusy->push_back(1);
	else
		queueBusy->push_back(0);

	numIterationsQueue++;
	serviceActualQueueSize = queueSize;
	if (queueSize > maximumQueueSize){
		maximumQueueSize = queueSize;
	}
	queueSizes->push_back(queueSize);
}


int ServiceInfoDTO::getType(){
	return type;
}

void ServiceInfoDTO::calculateData(){
	vector<int> queueSizesAux = vector<int>();
	queueSizesAux = *queueSizes;

	int sizeOfQueues = (int)queueSizes->size();
	double totalSizeOfQueue = 0;
	while(queueSizesAux.size() > 0){
		int temp = queueSizesAux.back();
		queueSizesAux.pop_back();
		totalSizeOfQueue += temp;
	}

	queueSizesAux.clear();

	vector<int> queueBuzyAux = vector<int>();
	queueBuzyAux = *queueBusy;

	int sizeOfQueueBuzy = (int)queueBusy->size();
	double totalTrueOfQueueBuzy = 0;
	while(queueBuzyAux.size() > 0){
		int temp = queueBuzyAux.back();
		queueBuzyAux.pop_back();

		if (temp == 1)
			totalTrueOfQueueBuzy++;
	}

	queueBuzyAux.clear();


	/*vector<double> serviceTimesAux = vector<double>();
	serviceTimesAux = *serviceTimes;

	int sizeOfServiceTimes = (int)serviceTimes->size();
	double totalServiceTimes = 0;
	while(serviceTimesAux.size() > 0){
		int temp = serviceTimesAux.back();
		serviceTimesAux.pop_back();
		totalServiceTimes += temp;
	}

	serviceTimesAux.clear();*/

	avgQueueSize = totalSizeOfQueue/sizeOfQueues;
	serviceUseRate = totalTrueOfQueueBuzy/sizeOfQueueBuzy;
	//avgServiceTime = totalServiceTimes/sizeOfServiceTimes;
}

AbstractSimulationResultDTO* ServiceInfoDTO::clone(){
	return new ServiceInfoDTO(*this);
}
