String[] nameValuePair = optionPair.split("=");
if(nameValuePair.length == 2)
{
String name = nameValuePair[0];
String value = nameValuePair[1];
FormStatisticsOptionBean formStatisticsOptionBean = new FormStatisticsOptionBean(name, value, 0, 0F);
defaultOptionBeans.put(name, formStatisticsOptionBean);
}
}
}
formStatisticsBean.getFormEntryValueVOList().addAll(formEntryValueVOList);
Integer totalEntries = formEntryValueVOList.size();
Float totalValue = 0F;
Map<String,Object> statisticsMap = new HashMap<String,Object>();
statisticsMap.put("totalEntries", totalEntries);
Iterator formEntryValueVOListIterator = formEntryValueVOList.iterator();
while(formEntryValueVOListIterator.hasNext())
{
FormEntryValueVO formEntryValueVO = (FormEntryValueVO)formEntryValueVOListIterator.next();
if(type.equals("percentage") || type.equals("numeric"))
{
Integer count = (Integer)statisticsMap.get("" + formEntryValueVO.getValue());
if(count == null)
statisticsMap.put("" + formEntryValueVO.getValue(), 1);
else
statisticsMap.put("" + formEntryValueVO.getValue(), count + 1);
}
else if(type.equals("average"))
{
try
{
totalValue = totalValue + Integer.getInteger(formEntryValueVO.getValue());
}
catch (Exception e)
{
logger.warn("Not a valid number:" + e.getMessage());
}
}
}
Map<String,Object> statisticsResultMap = new HashMap<String,Object>();
statisticsResultMap.putAll(statisticsMap);
if(type.equals("percentage") || type.equals("numeric"))
{
Iterator statisticsMapIterator = statisticsMap.keySet().iterator();
while(statisticsMapIterator.hasNext())
{
String key = (String)statisticsMapIterator.next();
Integer totalCount = (Integer)statisticsMap.get(key);
statisticsResultMap.put(key + "_totalCount", totalCount);
statisticsResultMap.put(key + "_percentage", (totalCount / totalEntries) * 100);
String[] optionPairs = path.split("igbr");
for(int i=0; i<optionPairs.length; i++)
{
String optionPair = optionPairs[i];
String[] nameValuePair = optionPair.split("=");
if(nameValuePair.length == 2)
{
String name = nameValuePair[0];
String value = nameValuePair[1];
if(name.equalsIgnoreCase(key))
{
FormStatisticsOptionBean formStatisticsOptionBean = new FormStatisticsOptionBean(name, value, totalCount, ((float)totalCount / totalEntries) * 100);
formStatisticsBean.getFormStatisticsOptionBeanList().add(formStatisticsOptionBean);
defaultOptionBeans.remove(name);
}
}
}