<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2017 <NAME>
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import gzip
import json
import sys
import zlib

def failures(item):
    return item.get("status") == "failure"

def load(filename_or_fp, only=failures, limit=None, verbose=False):
    count = 0
    opened = False
    if isinstance(filename_or_fp, str):
        fp = gzip.open(filename_or_fp, 'rb')
        opened = True
    else:
        fp = filename_or_fp
    try:
        while True:
            try:
                line = fp.readline().decode('utf-8')
            except (OSError, zlib.error) as ex:
                sys.stderr.write("tests-data: {0}\n".format(str(ex)))
                return
            if not line:
                return

            # Parse the line
            item = json.loads(line)

            # Now actually check for only values
            if only is not None and not only(item):
                continue

            yield item
            count += 1
            if verbose and count % 1000 == 0:
                sys.stderr.write("{0}: Items loaded\r".format(count))
            if limit is not None and count == limit:
                return
    finally:
        if opened:
            fp.close()
<commit_msg>bots: Print total number of items loaded<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2017 <NAME>
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import gzip
import json
import sys
import zlib

def failures(item):
    return item.get("status") == "failure"

def load(filename_or_fp, only=failures, limit=None, verbose=False):
    count = 0
    opened = False
    if isinstance(filename_or_fp, str):
        fp = gzip.open(filename_or_fp, 'rb')
        opened = True
    else:
        fp = filename_or_fp
    try:
        while True:
            try:
                line = fp.readline().decode('utf-8')
            except (OSError, zlib.error) as ex:
                sys.stderr.write("tests-data: {0}\n".format(str(ex)))
                return
            if not line:
                return

            # Parse the line
            item = json.loads(line)

            # Now actually check for only values
            if only is not None and not only(item):
                continue

            yield item
            count += 1
            if verbose and count % 1000 == 0:
                sys.stderr.write("{0}: Items loaded\r".format(count))
            if limit is not None and count == limit:
                return
    finally:
        if verbose and count > 0:
            sys.stderr.write("{0}: Items loaded\n".format(count))
        if opened:
            fp.close()

{'fraction_non_alphanumeric': 0.09005818365798128, 'fraction_numerical': 0.009612952188211486, 'mean_word_length': 2.1281645569620253, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5729106', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1063, 'n_words': 434}