package metrics4Asterisk.display;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import metrics4Asterisk.metrics.CallMetric;
import org.apache.log4j.Logger;
/**
*
* This class is for populating and accessing SummaryDistribution objects.
* @author Lance Stine
*/
public class QueueSummary {
/**
* A field for a summary of answered calls.
*/
private SummaryDistribution answeredCalls;
/**
* A field for a summary of un-answered calls.
*/
private SummaryDistribution unansweredCalls;
/**
* The logger for debugging this application.
*/
private Logger logger;
public QueueSummary() {
answeredCalls = new SummaryDistribution();
unansweredCalls = new SummaryDistribution();
logger = Logger.getLogger(this.getClass());
}
/**
* This method will iterate through the map argument and add the data to either the answeredCalls field or the unansweredCalls field.
* If the CallMetric object members have a talkTime field with a value greater than 0 it is an answered call, otherwise it is un-answered.
* Answered calls will have their talkTime and waitTime fields added to the distribution.
* Un-answered calls will only have their watTime field added.
* @param queueNames The queues that will be included in this summary
* @param map a map of parsed call data
*/
public void makeSummary(final Set<String> queueNames, final Map<String, CallMetric> map) {
Set<String> keys = map.keySet();
Iterator<String> iter = keys.iterator();
while(iter.hasNext()) {
String key = iter.next();
CallMetric callMetric = map.get(key);
if (queueNames.contains(callMetric.getQueueName())) {
//logger.debug("getConnectAgentTime " + callMetric.getConnectAgentTime());
if (callMetric.getTalkTime() > 0) {
logger.debug("add answered");
answeredCalls.addCall();
answeredCalls.addToDistribution(callMetric.getWaitTime());
answeredCalls.addWaitTime(callMetric.getWaitTime());
answeredCalls.addTalkTime(callMetric.getTalkTime());
} else {
logger.debug("add unanswered");
unansweredCalls.addCall();
unansweredCalls.addToDistribution(callMetric.getWaitTime());
unansweredCalls.addWaitTime(callMetric.getWaitTime());
}
}
}
}
public SummaryDistribution getAnsweredCalls() {
return answeredCalls;
}
public void setAnsweredCalls(SummaryDistribution answeredCalls) {
this.answeredCalls = answeredCalls;
}
public SummaryDistribution getUnansweredCalls() {
return unansweredCalls;
}
public void setUnansweredCalls(SummaryDistribution unansweredCalls) {
this.unansweredCalls = unansweredCalls;
}
}