Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
Utility to return the ratio of key size, punctuation size, and leaf value size.

        def analyse_json(filename):
    """Utility to return the ratio of key size, punctuation size, and leaf value size."""

    unique_keys = { }

    def __get_size(j):
        """Recurse to generate size."""
        (keys, punctuation, key_count) = (0, 0, 0)
        if isinstance(j, list):
            punctuation += 1 # [
            punctuation += (len(j) - 1) # ,
            for v in j:
                sub_k, sub_p, sub_count = __get_size(v)
                keys += sub_k
                punctuation += sub_p
                key_count += sub_count
            punctuation += 1 # ]
        elif isinstance(j, dict):
            punctuation += 1 # {
            if len(j.keys()) > 1:
                punctuation += (len(j.keys()) - 1) # ,
            for k, v in j.iteritems():
                if k not in unique_keys:
                    unique_keys[k] = True
                key_count += 1
                punctuation += 1 # "
                keys += len(k)
                punctuation += 1 # "
                punctuation += 1 # :
                sub_k, sub_p, sub_count = __get_size(v)
                keys += sub_k
                punctuation += sub_p
                key_count += sub_count
            punctuation += 1 # }
        elif isinstance(j, (str, unicode)):
            punctuation += 1 # "
            punctuation += 1 # "
        return (keys, punctuation, key_count)

    total_size = path_getsize(filename)
    with open(filename, 'r') as f:
        data = f.read()
        j = json_loads(data)

        (keys, punctuation, key_count) = __get_size(j)
        values = total_size - (keys + punctuation)
        unique_count = len(unique_keys.keys())
        compressed_size = len(zlib_compress(data, 6))

        return (keys, punctuation, values, key_count, unique_count, total_size, compressed_size)
        


src/t/u/turbulenz_tools-1.0.5/turbulenz_tools/tools/json2stats.py   turbulenz_tools(Download)
from optparse import OptionParser, TitledHelpFormatter
 
from turbulenz_tools.utils.json_stats import analyse_json
from turbulenz_tools.tools.stdtool import simple_options
 
    for f in args:
        for g in iglob(f):
            stats = analyse_json(g)
            totals = vadd(totals, stats)
            if options.verbose:

src/t/u/turbulenz_tools-HEAD/turbulenz_tools/tools/json2stats.py   turbulenz_tools(Download)
from optparse import OptionParser, TitledHelpFormatter
 
from turbulenz_tools.utils.json_stats import analyse_json
from turbulenz_tools.tools.stdtool import simple_options
 
    for f in args:
        for g in iglob(f):
            stats = analyse_json(g)
            totals = vadd(totals, stats)
            if options.verbose: