<commit_before>__author__ = 'ievans3024'
"""
Helper module for collection_json classes
"""

from collection_json import Collection, Link
from math import ceil

MIMETYPE = 'application/vnd.collection+json'


def paginate(collection, endpoint='', uri_template='{endpoint_uri}?page={page}&per_page={per_page}',
             page=None, per_page=5, leading=2, trailing=2):
    """
    Paginate this collection into a list of collections representing "pages" of this collection.
    :type collection: collection_json.Collection
    :type endpoint: str
    :type uri_template: str
    :type page: int
    :type per_page: int
    :type leading: int
    :type trailing: int
    :param endpoint: The URI for this resource.
    :param uri_template: A string providing a template for paginated URI structure. May include the following keys:
        "{endpoint_uri}" - This will evaluate to the value of the 'endpoint' param.
        "{page}" - The page number will be inserted here.
        "{per_page}" - The number of items to display per page will be inserted here.
    :param page: The page number to get.
    :param per_page: The number of items per page for this representation.
    :param leading: The number of leading pages before a page to add to its "links".
    :param trailing: The number of trailing pages after a page to add to its "links".
    :return tuple: A tuple of Collections representing ordered subsets of this collection. If the
        page parameter is supplied, the tuple will contain a single Collection representing one<commit_msg>+ added template data parser to collection helper module<commit_after>__author__ = 'ievans3024'
"""
Helper module for collection_json classes
"""

from collection_json import Collection, Link, Template
from math import ceil

MIMETYPE = 'application/vnd.collection+json'


def parse_template(template):
    """
    Parse a collection_json.Template object into key/value pairs.
    :param template: The template to parse.
    :type template: collection_json.Template
    :return: The Template data represented as a dict, with prompt and other non-key/value data stripped.
    """
    if not isinstance(template, Template):
        raise TypeError('Param "template" must be an instance of ' + Template.__name__)

    as_dict = {}
    properties = template.to_dict()['data']
    for prop in properties:
        as_dict[prop.get('name')] = prop.get('value')
    return as_dict


def paginate(collection, endpoint='', uri_template='{endpoint_uri}?page={page}&per_page={per_page}',
             page=None, per_page=5, leading=2, trailing=2):
    """
    Paginate this collection into a list of collections representing "pages" of this collection.
    :type collection: collection_json.Collection
    :type endpoint: str
    :type uri_template: str
    :type page: int
    :type per_page: int
    :type leading: int
    :type trailing: int
    :param endpoint: The URI for this resource.
    :param uri_template: A string providing a template for paginated URI structure. May include the following keys:
        "{endpoint_uri}" - This will evaluate to the value of the 'endpoint' param.
        "{page}" - The page number will be inserted here.
        "{per_page}" - The number of items to display per page will be inserted here.
    :param page: The page number to get.
    :param per_page: The number of items per page for this representation.
    :param leading: The number of leading pages before a page to add to its "links".
    :param trailing: The number of trailing pages after a page to add to its "links".
    :return tuple: A tuple of Collections representing ordered subsets of this collection. If the
        page parameter is supplied, the tuple will contain a single Collection representing one
{'fraction_non_alphanumeric': 0.07860378363975486, 'fraction_numerical': 0.0037303490540900614, 'mean_word_length': 3.6691542288557213, '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': '1036853', 'n_tokens_mistral': 973, 'n_tokens_neox': 966, 'n_words': 445}