'Generate timings for different amounts of asset metadata and different modulestores.'

@ddt.data(*itertools.product(MODULESTORE_SETUPS, ASSET_AMOUNT_PER_TEST))
@ddt.unpack
def test_asset_sizes(self, source_ms, num_assets):

    make_asset_xml(num_assets, ASSET_XML_PATH)
    validate_xml(ASSET_XSD_PATH, ASSET_XML_PATH)
    with source_ms.build() as (source_content, source_store):
        source_course_key = source_store.make_course_key('a', 'course', 'course')
        import_course_from_xml(source_store, 'test_user', TEST_DATA_ROOT, source_dirs=TEST_COURSE, static_content_store=source_content, target_id=source_course_key, create_if_not_present=True, raise_on_failure=True)
        asset_collection = source_ms.asset_collection()
        if (asset_collection.name in asset_collection.database.collection_names()):
            mapper = Code('\n                                                                                function()    {    emit("size",    (this    ==    null)    ?    0    :    Object.bsonsize(this))    }\n                                                                                ')
            reducer = Code('\n                                                                                function(key,    values)    {\n                                                                                                var    max_size    =    0;\n                                                                                                for    (var    i=0;    i    <    values.length;    i++)    {\n                                                                                                                if    (values[i]    >    max_size)    {\n                                                                                                                                max_size    =    values[i];\n                                                                                                                }\n                                                                                                }\n                                                                                                return    max_size;\n                                                                                }\n                                                                ')
            results = asset_collection.map_reduce(mapper, reducer, 'size_results')
            result_str = '{}    -    Store:    {:<15}    -    Num    Assets:    {:>6}    -    Result:    {}\n'.format(self.test_run_time, SHORT_NAME_MAP[source_ms], num_assets, [r for r in results.find()])
            with open('bson_sizes.txt', 'a') as f:
                f.write(result_str)
