'Given a CourseKey and a list of (block_type, block_id) pairs,
prepare the JSON-ready metadata needed for analytics logging.
This is [
{"usage_key": x, "original_usage_key": y, "original_usage_version": z, "descendants": [...]}
where the main list contains all top-level blocks, and descendants contains a *flat* list of all
descendants of the top level blocks, if any.'

def create_block_analytics_summary(self, course_key, block_keys):

    def summarize_block(usage_key):
        '    Basic    information    about    the    given    block    '
        (orig_key, orig_version) = self.store.get_block_original_usage(usage_key)
        return {'usage_key': unicode(usage_key), 'original_usage_key': (unicode(orig_key) if orig_key else None), 'original_usage_version': (unicode(orig_version) if orig_version else None)}
    result_json = []
    for block_key in block_keys:
        key = course_key.make_usage_key(*block_key)
        info = summarize_block(key)
        info['descendants'] = []
        try:
            block = self.store.get_item(key, depth=None)
            children = list(getattr(block, 'children', []))
            while children:
                child_key = children.pop()
                child = self.store.get_item(child_key)
                info['descendants'].append(summarize_block(child_key))
                children.extend(getattr(child, 'children', []))
        except ItemNotFoundError:
            pass
        result_json.append(info)
    return result_json
