<commit_before>#!/usr/bin/env python
import argparse
import os
import logging
import pprint
import sys
import yaml

# HACK
_file = os.path.abspath(__file__)
_dir = os.path.dirname(os.path.dirname(_file))
sys.path.insert(0, _dir)
from BoogieRunner.ResultType import ResultType

def main(args):
    resultTypes = [ r.name for r in list(ResultType)] # Get list of ResultTypes as strings
    logging.basicConfig(level=logging.DEBUG)
    parser = argparse.ArgumentParser()
    parser.add_argument('result_yml', type=argparse.FileType('r'), default='-')
    parser.add_argument('result_type', choices=resultTypes)
    pargs = parser.parse_args(args)

    results = yaml.load(pargs.result_yml)

    assert isinstance(results, list)

    # Get out of requested type
    resultCode = ResultType[pargs.result_type].value

    count = 0
    collected = [ ]
    for r in results:
        if r['result'] == resultCode:
            count += 1
            collected.append(r)

    logging.info('Count of type {} : {}'.format(pargs.result_type, count))

    print(yaml.dump(collected, default_flow_style=False))

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))<commit_msg>Added ability to filter out all results of a certain type. This is useful for removing results of type UNKNOWN which aren't useful for analysis.<commit_after>#!/usr/bin/env python
"""
Filer a results file (as YAML) and
output a filtered YAML file.

By default only results of type 'result_type'
are outputted. If -n is used then this is inverted.
"""
import argparse
import os
import logging
import pprint
import sys
import yaml

# HACK
_file = os.path.abspath(__file__)
_dir = os.path.dirname(os.path.dirname(_file))
sys.path.insert(0, _dir)
from BoogieRunner.ResultType import ResultType

def main(args):
    resultTypes = [ r.name for r in list(ResultType)] # Get list of ResultTypes as strings
    logging.basicConfig(level=logging.DEBUG)
    parser = argparse.ArgumentParser()
    parser.add_argument('result_yml', type=argparse.FileType('r'), help='File to open, if \'-\' then use stdin')
    parser.add_argument('result_type', choices=resultTypes, help='ResultType to match or filter out (depending on -n)')
    parser.add_argument('-n', '--not-matching', action='store_true', dest='not_matching', help='Change behaviour to output results that are not of type \'result_type\'')
    pargs = parser.parse_args(args)

    results = yaml.load(pargs.result_yml)

    assert isinstance(results, list)

    # Get out of requested type
    resultCode = ResultType[pargs.result_type].value
    collected = [ ]
    for r in results:
        if pargs.not_matching:
            if r['result'] != resultCode:
                collected.append(r)
        else:
            if r['result'] == resultCode:
                collected.append(r)

    if pargs.not_matching:
        logging.info('Kept {} results'.format(len(collected)))
    else:
        logging.info('Count of type {} : {}'.format(pargs.result_type, len(collected)))

    logging.info('Filtered out {} results out of {}'.format(len(results) - len(collected), len(results)))

    print(yaml.dump(collected, default_flow_style=False))

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))
{'fraction_non_alphanumeric': 0.12134411947728686, 'fraction_numerical': 0.001866832607342875, 'mean_word_length': 3.7559171597633134, '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': '3496903', 'n_tokens_mistral': 1017, 'n_tokens_neox': 982, 'n_words': 268}