@Override public Map<String, Object> getStatistics(List<String> statistics) { Collection<ConfiguredObjectStatistic<?, ?>> stats = getTypeRegistry().getStatistics(getClass()); Map<String,Object> map = new HashMap<>(); boolean allStats = statistics == null || statistics.isEmpty(); for(ConfiguredObjectStatistic stat : stats) { if(allStats || statistics.contains(stat.getName())) { Object value = stat.getValue(this); if(value != null) { map.put(stat.getName(), value); } } } return map; }
private void writeStatistics(final PrintWriter writer, final Class<? extends ConfiguredObject> configuredClass, final Model model, final List<Class<? extends ConfiguredObject>> types) { writer.println("<a name=\"types\"><h2>Statistics</h2></a>"); writer.println("<h2>Common Statistics</h2>"); writeStatisticsTable(writer, model.getTypeRegistry().getStatistics(configuredClass)); for(Class<? extends ConfiguredObject> type : types) { String typeName = getTypeName(type, model); Collection<ConfiguredObjectStatistic<?, ?>> typeSpecificStatistics = model.getTypeRegistry().getTypeSpecificStatistics(type); if(!typeSpecificStatistics.isEmpty()) { writer.println("<h2><span class=\"type\">"+typeName+"</span> Specific Statistics</h2>"); writeStatisticsTable(writer, typeSpecificStatistics); } } }
private Map<String, Map> processStatistics(final Class<? extends ConfiguredObject> type, final Model model) { Collection<ConfiguredObjectStatistic<?, ?>> statistics = model.getTypeRegistry().getStatistics(type); Map<String, Map> allStatisticsDetails = new LinkedHashMap<>(); for (ConfiguredObjectStatistic<?, ?> statistic : statistics) { Map<String, Object> stat = new LinkedHashMap<>(); stat.put("name", statistic.getName()); stat.put("type", statistic.getType().getSimpleName()); if (!"".equals(statistic.getDescription())) { stat.put("description", statistic.getDescription()); } if (!"".equals(statistic.getLabel())) { stat.put("label", statistic.getLabel()); } stat.put("units", statistic.getUnits()); stat.put("statisticType", statistic.getStatisticType().toString()); allStatisticsDetails.put(statistic.getName(), stat); } return allStatisticsDetails; } }