<commit_before>import re
import os

import pandas as pd

from scipy.io import loadmat

from ..identifiers import Pid
from ..utils import BaseDictlike
from .files import find_product_file, list_product_files

class ClassScoresDirectory(BaseDictlike):
    """a dictlike keyed by bin lid. the values are ClassScoresFiles"""
    def __init__(self, path, version=None):
        self.path = path
        if version is None:
            version = 1
        self.version = str(version)
    def __getitem__(self, bin_lid):
        filename = '{}_class_v{}.mat'.format(bin_lid, self.version)
        path = find_product_file(self.path, filename, exhaustive=True)
        if path is not None:
            return ClassScoresFile(path, bin_lid, version=self.version)
        raise KeyError(bin_lid)
    def has_key(self, bin_lid):
        try:
            self[bin_lid]
            return True
        except KeyError:
            return False
    def keys(self):
        fn_regex = r'.*_class_v{}\.mat'.format(self.version)
        for p in list_product_files(self.path, fn_regex):
            # parse the filename as a pid
            bin_lid = Pid(os.path.basename(p)).bin_lid
            yield bin_lid
    def __repr__(self):
        return '<ClassScoresDirectory {}>'.format(self.path)<commit_msg>speeding up typical class scores file locating<commit_after>import re
import os

import pandas as pd

from scipy.io import loadmat

from ..identifiers import Pid
from ..utils import BaseDictlike
from .files import find_product_file, list_product_files

class ClassScoresDirectory(BaseDictlike):
    """a dictlike keyed by bin lid. the values are ClassScoresFiles"""
    def __init__(self, path, version=None):
        self.path = path
        if version is None:
            version = 1
        self.version = str(version)
        print('wagh')
    def __getitem__(self, bin_lid):
        filename = '{}_class_v{}.mat'.format(bin_lid, self.version)
        year = Pid(bin_lid).timestamp.year
        likely_path = os.path.join(self.path, 'class{}_v{}'.format(year, self.version), filename)
        if os.path.exists(likely_path):
            print('found it')
            return ClassScoresFile(likely_path, bin_lid, version=self.version)
        path = find_product_file(self.path, filename, exhaustive=True)
        if path is not None:
            return ClassScoresFile(path, bin_lid, version=self.version)
        raise KeyError(bin_lid)
    def has_key(self, bin_lid):
        try:
            self[bin_lid]
            return True
        except KeyError:
            return False
    def keys(self):
        fn_regex = r'.*_class_v{}\.mat'.format(self.version)
        for p in list_product_files(self.path, fn_regex):
            # parse the filename as a pid
            bin_lid = Pid(os.path.basename(p)).bin_lid
            yield bin_lid
    def __repr__(self):
        return '<ClassScoresDirectory {}>'.format(self.path)
{'fraction_non_alphanumeric': 0.09544988026000684, 'fraction_numerical': 0.0006842285323297981, 'mean_word_length': 2.6143386897404204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '650361', 'n_tokens_mistral': 906, 'n_tokens_neox': 886, 'n_words': 235}