Beispiel #1
0
def get_number_downloads_unique_and_total():
    number_downloads_unique = 0
    number_downloads_total = 0

    projects = get_projects()

    for project in projects:

        for filenode in OsfStorageFile.find(Q('node', 'eq', project)):
            for idx, version in enumerate(filenode.versions):
                page = ':'.join(
                    ['download', project._id, filenode._id,
                     str(idx)])
                unique, total = get_basic_counters(page)
                number_downloads_unique += unique or 0
                number_downloads_total += total or 0

        for filenode in TrashedFileNode.find(
                Q('provider', 'eq', 'osfstorage') & Q('node', 'eq', project)
                & Q('is_file', 'eq', True)):
            for idx, version in enumerate(filenode.versions):
                page = ':'.join(
                    ['download', project._id, filenode._id,
                     str(idx)])
                unique, total = get_basic_counters(page)
                number_downloads_total += total or 0
                number_downloads_unique += unique or 0

    return number_downloads_unique, number_downloads_total
Beispiel #2
0
def get_number_downloads_unique_and_total():
    number_downloads_unique = 0
    number_downloads_total = 0

    projects = get_projects()

    for project in projects:

        for filenode in OsfStorageFile.find(Q('node', 'eq', project)):
            for idx, version in enumerate(filenode.versions):
                page = ':'.join(['download', project._id, filenode._id, str(idx)])
                unique, total = get_basic_counters(page)
                number_downloads_unique += unique or 0
                number_downloads_total += total or 0

        for filenode in TrashedFileNode.find(Q('provider', 'eq', 'osfstorage') & Q('node', 'eq', project) & Q('is_file', 'eq', True)):
            for idx, version in enumerate(filenode.versions):
                page = ':'.join(['download', project._id, filenode._id, str(idx)])
                unique, total = get_basic_counters(page)
                number_downloads_total += total or 0
                number_downloads_unique += unique or 0

        clear_modm_cache()

    return number_downloads_unique, number_downloads_total
Beispiel #3
0
def count_file_downloads():
    downloads_unique, downloads_total = 0, 0
    for record in OsfStorageFile.find():
        page = ':'.join(['download', record.node._id, record._id])
        unique, total = get_basic_counters(page)
        downloads_unique += unique or 0
        downloads_total += total or 0
    return downloads_unique, downloads_total
Beispiel #4
0
def count_file_downloads():
    downloads_unique, downloads_total = 0, 0
    for record in OsfStorageFile.find():
        page = ':'.join(['download', record.node._id, record._id])
        unique, total = get_basic_counters(page)
        downloads_unique += unique or 0
        downloads_total += total or 0
    return downloads_unique, downloads_total
Beispiel #5
0
def get_usage(node):
    vids = sum([
        file_node.to_storage().get('versions', [])
        for file_node in
        OsfStorageFile.find(Q('node', 'eq', node))
    ], [])

    t_vids = sum([
        file_node.to_storage().get('versions', [])
        for file_node in
        TrashedFileNode.find(
            Q('node', 'eq', node) &
            Q('is_file', 'eq', True) &
            Q('provider', 'eq', 'osfstorage')
        )
    ], [])

    usage = sum([v.size or 0 for v in FileVersion.find(Q('_id', 'in', vids))])
    trashed_usage = sum([v.size or 0 for v in FileVersion.find(Q('_id', 'in', t_vids))])

    return map(sum, zip(*([(usage, trashed_usage)] + [get_usage(child) for child in node.nodes_primary])))  # Adds tuples together, map(sum, zip((a, b), (c, d))) -> (a+c, b+d)
Beispiel #6
0
def get_usage(node):
    usage = (
        sum([v.size or 0 for file_node in OsfStorageFile.find(Q('node', 'eq', node)) for v in file_node.versions]),  # Sum all versions of all files of this node
        sum([v.size or 0 for file_node in TrashedFileNode.find(Q('node', 'eq', node) & Q('is_file', 'eq', True) & Q('provider', 'eq', 'osfstorage')) for v in file_node.versions]),  # Sum all versions of all deleted files of this node
    )
    return map(sum, zip(*([usage] + [get_usage(child) for child in node.nodes_primary])))  # Adds tuples together, map(sum, zip((a, b), (c, d))) -> (a+c, b+d)