This is way out of my comfort range and I'm not even sure I can describe it well enough. I have a file that is a list of dicts that contain another list of dicts. An excerpt of the data structure is below:
j_traffic =
[
{
"timePeriod": "2017-08-04T15:20:00.000+0000",
"applicationTrafficPerApplication": [
{
"applicationId": 39,
"applicationName": "HTTP",
"trafficInboundBps": 148760,
"trafficOutboundBps": 5673493,
"trafficWithinBps": 0
},
{
"applicationId": 41,
"applicationName": "HTTPS",
"trafficInboundBps": 16805,
"trafficOutboundBps": 546937,
"trafficWithinBps": 0
}
]
},
{
"timePeriod": "2017-08-04T15:15:00.000+0000",
"applicationTrafficPerApplication": [
{
"applicationId": 39,
"applicationName": "HTTP",
"trafficInboundBps": 157569,
"trafficOutboundBps": 5769206,
"trafficWithinBps": 0
},
{
"applicationId": 41,
"applicationName": "HTTPS",
"trafficInboundBps": 17454,
"trafficOutboundBps": 590421,
"trafficWithinBps": 0
},
{
"applicationId": 44,
"applicationName": "DNS",
"trafficInboundBps": 18218,
"trafficOutboundBps": 13683,
"trafficWithinBps": 0
},
{
"applicationId": 45,
"applicationName": "SNMP",
"trafficInboundBps": 14,
"trafficOutboundBps": 0,
"trafficWithinBps": 0
}
]
},
{
"timePeriod": "2017-08-04T15:05:00.000+0000",
"applicationTrafficPerApplication": [
{
"applicationId": 39,
"applicationName": "HTTP",
"trafficInboundBps": 139897,
"trafficOutboundBps": 5073320,
"trafficWithinBps": 0
},
{
"applicationId": 41,
"applicationName": "HTTPS",
"trafficInboundBps": 22592,
"trafficOutboundBps": 457962,
"trafficWithinBps": 0
},
{
"applicationId": 44,
"applicationName": "DNS",
"trafficInboundBps": 19903,
"trafficOutboundBps": 14033,
"trafficWithinBps": 0
}
]
}
]
I am trying to understand how I can create a new dict using "applicationName" value as the keys and the values are the sum of all values of key "trafficInboundBps" that would look like this:
inboundTraffic = {"HTTP": 446316, "HTTPS": 56581, "DNS": 38121, "SNMP": 14}
I've tried suggestions I found on here but can't wrap my head around how to parse the nested levels with the following: inboundTraffic = dict.fromkeys(set().union(*j_traffic))
Any takers?
thanks!