python - Counting how many times a value occurs in a json file -
how read count how many times each "type" , "key" occurs in json file data below
{"method":"get","udid":"26:90:a4:46392970","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/04track12netics2015/reversegeocode/-28.45818,24.39608.xml?returnspeedlimit=true","key":"04track12netics2015","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":5,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t23:59:52.975z"} {"method":"get","udid":"26:90:a4:46392915","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/04track12netics2015/reversegeocode/-25.96607,28.14167.xml?returnspeedlimit=true","key":"04track12netics2015","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":96,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t23:59:53.011z"} {"method":"get","udid":"26:90:a4:46393163","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/04track12netics2015/reversegeocode/-28.45818,24.39608.xml?returnspeedlimit=true","key":"04track12netics2015","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":7,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t23:59:53.170z"} {"method":"get","udid":"26:90:a4:81986956","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/tile/1185/1176/11.png?settings=russian-river&res=mdpi","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":438,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t06:06:27.394z"} {"method":"get","udid":"26:90:a4:81987014","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/tile/1185/1177/11.png?settings=russian-river&res=mdpi","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":390,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t06:06:27.404z"} {"method":"get","udid":"26:90:a4:81986884","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/tile/1183/1175/11.png?settings=russian-river&res=mdpi","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":533,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t06:06:27.417z"} {"method":"get","udid":"26:90:a4:41422853","dataset":"tomtom","production":true,"type":"search","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/search/0a%20schoonder%20stree,.json?countryset=za","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":824,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t22:37:03.677z"} {"method":"get","udid":"26:90:a4:88284444","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/reversegeocode/-33.92456,18.54727.json","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":170,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t07:51:24.615z"} {"method":"get","udid":"26:90:a4:10992447","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/cxiqlybhwykcixtywrrbltcdij4xuxfn/tile/18063/19670/15.png?transparent=true&settings=russian-river&res=hdpi","key":"cxiqlybhwykcixtywrrbltcdij4xuxfn","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":407,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-21t20:23:12.854z"} {"method":"get","udid":"26:90:a4:10992826","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/cxiqlybhwykcixtywrrbltcdij4xuxfn/tile/18060/19670/15.png?transparent=true&settings=russian-river&res=hdpi","key":"cxiqlybhwykcixtywrrbltcdij4xuxfn","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":219,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-21t20:23:13.046z"} {"method":"get","udid":"26:90:a4:46392970","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/04track12netics2015/reversegeocode/-28.45818,24.39608.xml?returnspeedlimit=true","key":"04track12netics2015","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":5,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t23:59:52.975z"} {"method":"get","udid":"26:90:a4:46392915","dataset":"decarta","production":true,"type":"reversegeocode","path":"/v1/04track12netics2015/reversegeocode/-25.96607,28.14167.xml?returnspeedlimit=true","key":"04track12netics2015","cost":1,"vendorcost":{"dataprovider":1,"trafficprovider":0},"roundtriptime":96,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t23:59:53.011z"} {"method":"get","udid":"26:90:a4:81986949","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/fpogtly1zf22m3va4flku52tslmpanyo/tile/1182/1175/11.png?settings=russian-river&res=mdpi","key":"fpogtly1zf22m3va4flku52tslmpanyo","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":472,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-12t06:06:27.421z"} {"method":"get","udid":"26:90:a4:10992826","dataset":"tomtom-world","production":true,"type":"tile","path":"/v1/cxiqlybhwykcixtywrrbltcdij4xuxfn/tile/18060/19670/15.png?transparent=true&settings=russian-river&res=hdpi","key":"cxiqlybhwykcixtywrrbltcdij4xuxfn","cost":1,"vendorcost":{"dataprovider":0.03125,"trafficprovider":0},"roundtriptime":219,"noncompquery":0,"level":"request","message":"processing request","timestamp":"2016-08-21t20:23:13.046z"}
from collections import counter import json pprint import pprint open('logs.txt') infile: data = (json.loads(line) line in infile) counter = counter((row['type'], row['key']) row in data) pprint(dict(counter))
output:
{(u'reversegeocode', u'04track12netics2015'): 5, (u'reversegeocode', u'fpogtly1zf22m3va4flku52tslmpanyo'): 1, (u'search', u'fpogtly1zf22m3va4flku52tslmpanyo'): 1, (u'tile', u'cxiqlybhwykcixtywrrbltcdij4xuxfn'): 3, (u'tile', u'fpogtly1zf22m3va4flku52tslmpanyo'): 4}
Comments
Post a Comment