def metrics(asset):
    def __approximate_size(num):
        """Convert a file size to human-readable form."""
        for x in [' bytes', 'KB', 'MB', 'GB', 'TB']:
            if num < 1024.0:
                return "%3.1f%s" % (num, x)
            num /= 1024.0

    def __count_nodes(nodes):
        """Recursively count the nodes."""
        num_nodes = len(nodes)
        for n in nodes.itervalues():
            if 'nodes' in n:
                num_nodes += __count_nodes(n['nodes'])
        return num_nodes

    m = { }
    for k in asset.keys():
        if isinstance(asset[k], dict):
            m['num_' + k] = len(asset[k])
        elif isinstance(asset[k], list):
            m['num_' + k] = len(asset[k])
    if 'nodes' in asset:
        m['num_nodes_recurse'] = __count_nodes(asset['nodes'])
    if 'num_geometries' in m and m['num_geometries']:
        m['total_primitives'] = 0
        m['total_positions'] = 0
        m['approximate_size'] = 0
        for _, shape in asset['geometries'].items():
            if 'surfaces' in shape:
                for _, surface in shape['surfaces'].items():
                    m['total_primitives'] += int(surface['numPrimitives'])
            else:
                if 'numPrimitives' in shape:
                    m['total_primitives'] += int(shape['numPrimitives'])
            if 'POSITION' in shape['inputs']:
                position_source = shape['inputs']['POSITION']['source']
                if position_source in shape['sources']:
                    positions = shape['sources'][position_source]
                    m['total_positions'] += len(positions['data']) / positions['stride']
            for _, source in shape['sources'].items():
                m['approximate_size'] += len(source['data']) * 4      # Assume float per vertex element attribute
            if 'triangles' in shape:
                m['approximate_size'] += len(shape['triangles']) * 2  # Assume short per index
            elif 'quads' in shape:
                m['approximate_size'] += len(shape['quads']) * 2      # Assume short per index
        m['average_primitives'] = m['total_primitives'] / m['num_geometries']
        m['average_positions'] = m['total_positions'] / m['num_geometries']
        m['approximate_readable_size'] = __approximate_size(m['approximate_size'])
    return m
Returns a serialized form of the schema of the resource.
dataset/ETHPy150Open turbulenz/turbulenz_tools/turbulenz_tools/utils/json_utils.py/metrics--crossover with--dataset/ETHPy150Open mozilla/inventory/vendor-local/src/django-tastypie/tastypie/resources.py/Resource.get_schema