public static JsonObject buildStatSummary(RTCStatList statArray, boolean fullyDetailed) {
  
    JsonObjectBuilder builder = Json.createObjectBuilder();
    double totalRTT = 0;
    double agvRTT = 0;
    List<List<RTCRtpStreamStats>> inboundStreamStatsList = new ArrayList<>();
    List<List<RTCRtpStreamStats>> outboundStreamStatsList = new ArrayList<>();
    builder.add("Starting Timestamp", timestamp(statArray.get(0).getTimestamp()));
    builder.add("Ending Timestamp", timestamp(statArray.get(statArray.size() - 1).getTimestamp()));
    builder.add("Connected", !statArray.hasNoData());
    builder.add("Room", statArray.getRoomUrl());
    builder.add("Batch", statArray.getBatchId());

    for (String key : statArray.getAdditionalData().keySet()) {
      builder.add(key, statArray.getAdditionalData().get(key));
    }

    RTCStats lastRtcStats = statArray.get(statArray.size() -1);
    if (lastRtcStats.get("remote-candidate") != null) {
      builder.add(StatEnum.REMOTE_IP.toString(), lastRtcStats.getRemoteIP());
    }
    if (lastRtcStats.get("inbound-rtp") != null) {
//      builder
//        .add(StatEnum.TOTAL_INBOUND_BYTES_RECEIVED.toString(), lastRtcStats.getTotalBytesByMedia("inbound"))
//        .add(StatEnum.TOTAL_INBOUND_AUDIO_BYTES_RECEIVED.toString(), lastRtcStats.getTotalBytesByMedia("inbound", "audio"))
//        .add(StatEnum.TOTAL_INBOUND_VIDEO_BYTES_RECEIVED.toString(), lastRtcStats.getTotalBytesByMedia("inbound", "video"));
    }
    if (lastRtcStats.get("outbound-rtp") != null) {
//      builder
//        .add(StatEnum.TOTAL_OUTBOUND_BYTES_SENT.toString(), lastRtcStats.getTotalBytesByMedia("outbound"))
//        .add(StatEnum.TOTAL_OUTBOUND_AUDIO_BYTES_SENT.toString(), lastRtcStats.getTotalBytesByMedia("outbound", "audio"))
//        .add(StatEnum.TOTAL_OUTBOUND_VIDEO_BYTES_SENT.toString(), lastRtcStats.getTotalBytesByMedia("outbound", "video"));
    }
    
    for (int index = 0; index < statArray.size(); index++) {
      RTCStats rtcStats = statArray.get(index);
      if (!rtcStats.getSuccessfulCandidate().isEmpty()) {
        RTCIceCandidatePairStats candidatePairStats = (RTCIceCandidatePairStats) rtcStats.getSuccessfulCandidate();
        totalRTT += candidatePairStats.getTotalRoundTripTime();
        agvRTT = (agvRTT + candidatePairStats.getCurrentRoundTripTime()) / (index + 1);
      }
      
      inboundStreamStatsList.add(rtcStats.getStreamsStats("inbound"));
      outboundStreamStatsList.add(rtcStats.getStreamsStats("outbound"));
    }
    
    builder
//      .add(StatEnum.TOTAL_RTT.toString(), totalRTT)
      .add(StatEnum.AVG_CURRENT_RTT.toString(), agvRTT);
    if (lastRtcStats.get("inbound-rtp") != null) {
      builder.add("inbound", processStreamStats(inboundStreamStatsList, fullyDetailed));
    }
    if (lastRtcStats.get("outbound-rtp") != null) {
      builder
        .add("outbound", processStreamStats(outboundStreamStatsList, fullyDetailed));
    }
    
    return builder.build();
  }
@param statArray     array of stats provided from getStats()
@param fullyDetailed true if the detailed arrays of specific stat values are to be added to the summary

@return  the stat summary : (Sample stats on Chrome 74)
    "Starting Timestamp": "2019-06-28 162729",
    "Ending Timestamp": "2019-06-28 162740",
    "Total Inbound Bytes Received (Bytes)": 642114,
    "Total Inbound Audio Bytes Received (Bytes)": 114190,
    "Total Inbound Video Bytes Received (Bytes)": 527924,
    "Total Outbound Bytes Sent (Bytes)": 644136,
    "Total Outbound Audio Bytes Sent (Bytes)": 114371,
    "Total Outbound Video Bytes Sent (Bytes)": 529765,
    "Total Round Trip Time (ms)": 0.0,
    "Average Current Round Trip Time (ms)": 0.0,
    "inbound": {
            "audio": [
            {
                "streamId": "RTCInboundRTPAudioStream_3333556480",
                "Total Bytes Received (Bytes)": "34997",
                "Average Received Bitrate (kbps)": "3071",
                "Total Packets Received": "585",
                "Average Audio Level (dB)": "0",
                "Total Packets Lost": 0,
                "Packets Lost (%)": "0",
                "Packets Discarded (%)": "0",
                "Average Audio Jitter (ms)": "0"
            }
        ],
        "video": [
            {
                "streamId": "RTCInboundRTPVideoStream_3131213379",
                "Total Bytes Received (Bytes)": "1031833",
                "Average Received Bitrate (kbps)": "95078",
                "Total Packets Received": "1006",
                "Frames Received": "234",
                "Average Frame Rate (fps)": "0",
                "Total Packets Lost": 0,
                "Packets Lost (%)": "0",
                "Packets Discarded (%)": "0"
            }
        ]
    },
    "outbound": {
        "audio": [ same as inbound stats ],
        "video": [ same as inbound stats ]
    }
KITE-Framework/src/main/java/org/webrtc/kite/stats/StatsUtils.java