<commit_before>from functools import wraps
from flask import request, current_app
import random, math


# a slow decorator for tests, so can exclude them when necessary
# put @slow on its own line above a slow test method
# to exclude slow tests, run like this: nosetests -A "not slow"
def slow(f):
    f.slow = True
    return f

# derived from the jsonp function in bibserver
def jsonp(f):
    """Wraps JSONified output for JSONP"""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        callback = request.args.get('callback', False)
        if callback:
            content = str(callback) + '(' + str(f(*args,**kwargs).data) + ')'
            return current_app.response_class(content, mimetype='application/javascript')
        else:
            return f(*args, **kwargs)
    return decorated_function



def pickWosItems(num_total_results, num_subset_results):
    num_in_final_sample = 100
    num_results_per_page = 50
    num_to_sample = int(math.ceil(
        float(num_subset_results * num_in_final_sample) / float(num_total_results)
    ))

    # "id" is the index of the result in the result subset
    subset_result_ids = range(1, num_subset_results)
    ids_to_sample = sorted(random.sample(subset_result_ids, num_to_sample))

    pages_and_ids = []
    for result_id in ids_to_sample:
        page = int(math.floor(result_id / num_results_per_page))
        pages_and_ids.append((page, result_id))

    return pages_and_ids
<commit_msg>fix wrong page bug in wospicker.<commit_after>from functools import wraps
from flask import request, current_app
import random, math


# a slow decorator for tests, so can exclude them when necessary
# put @slow on its own line above a slow test method
# to exclude slow tests, run like this: nosetests -A "not slow"
def slow(f):
    f.slow = True
    return f

# derived from the jsonp function in bibserver
def jsonp(f):
    """Wraps JSONified output for JSONP"""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        callback = request.args.get('callback', False)
        if callback:
            content = str(callback) + '(' + str(f(*args,**kwargs).data) + ')'
            return current_app.response_class(content, mimetype='application/javascript')
        else:
            return f(*args, **kwargs)
    return decorated_function



def pickWosItems(num_total_results, num_subset_results):
    num_in_final_sample = 100
    num_results_per_page = 50
    num_to_sample = int(math.ceil(
        float(num_subset_results * num_in_final_sample) / float(num_total_results)
    ))

    # "id" is the index of the result in the result subset
    subset_result_ids = range(1, num_subset_results)
    ids_to_sample = sorted(random.sample(subset_result_ids, num_to_sample))

    pages_and_ids = []
    for result_id in ids_to_sample:
        page = int(math.floor(result_id / num_results_per_page)) +1
        pages_and_ids.append((page, result_id))

    return pages_and_ids

{'fraction_non_alphanumeric': 0.09146341463414634, 'fraction_numerical': 0.004403794037940379, 'mean_word_length': 3.5291411042944785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5970853', 'n_tokens_mistral': 936, 'n_tokens_neox': 903, 'n_words': 260}