| | |
| | | */ |
| | | protected JSONObject buildErrorLevel(TreeNode<FuzzyValue> node) { |
| | | JSONObject result = new JSONObject(); |
| | | if(node == null) |
| | | if(node == null || node.getData() == null) |
| | | return result; |
| | | |
| | | int totalErrors = Arrays.stream(node.getData().getTotalErrorCounts()).sum(); |
| | | return buildErrorLevel(node.getData().getTotalErrorCounts()); |
| | | } |
| | | |
| | | /** |
| | | * 根据隐患等级计数构建汇总信息。 |
| | | * |
| | | * @param errorCounts 按一级至四级隐患排列的数量 |
| | | * @return 隐患等级汇总 |
| | | */ |
| | | protected JSONObject buildErrorLevel(int[] errorCounts) { |
| | | JSONObject result = new JSONObject(); |
| | | if (errorCounts == null || errorCounts.length < ErrorLevel.values().length) |
| | | return result; |
| | | |
| | | int totalErrors = Arrays.stream(errorCounts).sum(); |
| | | result.put("隐患数量", totalErrors); |
| | | List<Object> errorInfos = new ArrayList<>(); |
| | | for (int i = 0; i<4 ; i++) { |
| | | var level = ErrorLevel.values()[i]; |
| | | var count = node.getData().getTotalErrorCounts()[i]; |
| | | var count = errorCounts[i]; |
| | | var info = new JSONObject(); |
| | | info.put("隐患等级", level.getDesc()); |
| | | info.put("隐患程度", level.getDesc2()); |
| | | info.put("数量", count); |
| | | info.put("比例", formatPercent(count * 1.0 / totalErrors)); |
| | | info.put("比例", formatPercent(totalErrors == 0 ? 0 : count * 1.0 / totalErrors)); |
| | | errorInfos.add(info); |
| | | } |
| | | result.put("一级隐患数量", node.getData().getTotalErrorCounts()[0]); |
| | | result.put("二级隐患数量", node.getData().getTotalErrorCounts()[1]); |
| | | result.put("三级隐患数量", node.getData().getTotalErrorCounts()[2]); |
| | | result.put("四级隐患数量", node.getData().getTotalErrorCounts()[3]); |
| | | result.put("一级隐患数量", errorCounts[0]); |
| | | result.put("二级隐患数量", errorCounts[1]); |
| | | result.put("三级隐患数量", errorCounts[2]); |
| | | result.put("四级隐患数量", errorCounts[3]); |
| | | result.put("分项", errorInfos); |
| | | return result; |
| | | } |