<commit_before>import re

from operator import itemgetter
from collections import Counter, OrderedDict
from flask import request
from eve.methods.get import getitem_internal, get_internal


def availableInstances():
    """Get a list of available instances and display them with links to invitation pages
    """
    availableInstances = get_internal('sites', **{"status": "available"})
    availableInstancesSidList = []
    if availableInstances and availableInstances[4]:
        for header in availableInstances[4]:
            if header and header[0] == 'X-Total-Count' and header[1] > 0:
                for item in availableInstances[0]['_items']:
                    availableInstancesSidList.append(item['sid'])
    else:
        availableInstancesSidList = None

    return availableInstancesSidList


def summaryInstances():
    """Return a list of summary statistics about instances
        Instance Count
          Total - Done
          by state - Done
          with bundles - To Do
    """

    q = get_internal('sites')
    res = q[0] if len(q) > 0 else {}
    totalItems = res.get('_meta', None).get('total', None)

    summary = {}

    if totalItems:
        summary['total'] = totalItems

        # If more items exist than initial request, reset max_results to total to get a full export
        if totalItems > res.get('_meta', None).get('max_results', None):
            # Copy the existing arguments on the request object
            setArgs = request.args.copy()
            # Set our new header
            setArgs['max_results'] = totalItems
            request.args = setArgs
            results = get_internal('sites')[0]['_items']
        else:
            results = res.get('_items', None)

        statusCount = Counter()
        typeCount = Counter()
        pantheonCount = Counter()
        # Count totals by status
        for res in results:
            statusCount[res['status']] += 1
            if 'site_type' in res:
                typeCount[res['site_type']] += 1
            if 'pantheon_size' in res:
                pantheonCount[res['pantheon_size']] += 1
        summary['status'] = OrderedDict(sorted(dict(statusCount).items()))
        summary['site_type'] = OrderedDict(sorted(dict(typeCount).items()))
        summary['pantheon_size'] = OrderedDict(sorted(dict(pantheonCount).items()))
    else:
        summary = None


    qq = get_internal('statistics')
    resStat = qq[0] if len(qq) > 0 else {}<commit_msg>chg: remove unnecessary blank lines [!minor]<commit_after>import re

from operator import itemgetter
from collections import Counter, OrderedDict
from flask import request
from eve.methods.get import getitem_internal, get_internal


def availableInstances():
    """Get a list of available instances and display them with links to invitation pages
    """
    availableInstances = get_internal('sites', **{"status": "available"})
    availableInstancesSidList = []
    if availableInstances and availableInstances[4]:
        for header in availableInstances[4]:
            if header and header[0] == 'X-Total-Count' and header[1] > 0:
                for item in availableInstances[0]['_items']:
                    availableInstancesSidList.append(item['sid'])
    else:
        availableInstancesSidList = None

    return availableInstancesSidList


def summaryInstances():
    """Return a list of summary statistics about instances
        Instance Count
          Total - Done
          by state - Done
          with bundles - To Do
    """

    q = get_internal('sites')
    res = q[0] if len(q) > 0 else {}
    totalItems = res.get('_meta', None).get('total', None)

    summary = {}

    if totalItems:
        summary['total'] = totalItems

        # If more items exist than initial request, reset max_results to total to get a full export
        if totalItems > res.get('_meta', None).get('max_results', None):
            # Copy the existing arguments on the request object
            setArgs = request.args.copy()
            # Set our new header
            setArgs['max_results'] = totalItems
            request.args = setArgs
            results = get_internal('sites')[0]['_items']
        else:
            results = res.get('_items', None)

        statusCount = Counter()
        typeCount = Counter()
        pantheonCount = Counter()
        # Count totals by status
        for res in results:
            statusCount[res['status']] += 1
            if 'site_type' in res:
                typeCount[res['site_type']] += 1
            if 'pantheon_size' in res:
                pantheonCount[res['pantheon_size']] += 1
        summary['status'] = OrderedDict(sorted(dict(statusCount).items()))
        summary['site_type'] = OrderedDict(sorted(dict(typeCount).items()))
        summary['pantheon_size'] = OrderedDict(sorted(dict(pantheonCount).items()))
    else:
        summary = None

    qq = get_internal('statistics')
    resStat = qq[0] if len(qq) > 0 else {}
{'fraction_non_alphanumeric': 0.10649455425574829, 'fraction_numerical': 0.005647438483259379, 'mean_word_length': 2.554838709677419, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '1741078', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1339, 'n_words': 395}