<commit_before>#!/usr/bin/python3

"""pat
pinky
image-hB image-lB
prostate-hB prostate-lB
lesion-hB lesion-lB
roi-hB roi-lB
"""

from collections import defaultdict

from dwi.types import Path
from tabulate import tabulate

BASE = Path('/mri')
LIST = 'misc/list/all.txt'


def nums(case):
    def num(pat):
        # print(pat, len(list(BASE.glob(pat.format(**d)))))
        return len(list(BASE.glob(pat.format(**d))))

    # r = {}
    r = defaultdict(int)
    r['case'] = case
    d = dict(c=case)
    r['hist'] = num('hist/New_ALL_RALP/{c}_*.*')
    # for scan in ['1a', '1b', '2a', '2b']:
    #     d['s'] = scan
    #     r['img-hB-'+scan] = num('images/DWI/{c}-{s}*.*')
    #     r['img-lB-'+scan] = num('images/DWI_lB/{c}-{s}*.*')
    #     r['pro-hB-'+scan] = num('masks/prostate/DWI/{c}-{s}.*')
    #     r['pro-lB-'+scan] = num('masks/prostate/DWI_lB/{c}-{s}.*')
    #     r['les-hB-'+scan] = num('masks/lesion/DWI/lesion1/{c}-{s}.*')
    #     r['les-lB-'+scan] = num('masks/lesion/DWI_lB/lesion1/{c}-{s}.*')
    #     r['roi-hB-'+scan] = num('masks/roi/DWI/{c}-{s}.*')
    #     r['roi-lB-'+scan] = num('masks/roi/DWI_lB/{c}-{s}.*')
    for rep in [1, 2]:
        d['r'] = rep
        r['hB-img'] += (num('images/DWI/{c}-{r}[ab]*.*') > 1)
        # r['img-Mono'] += (num('images/DWI-Mono/{c}-{r}[ab]') > 1)
        # r['img-Kurt'] += (num('images/DWI-Kurt/{c}-{r}[ab]') > 1)
        r['hB-pro'] += (num('masks/prostate/DWI/{c}-{r}[ab].*') > 1)
        r['hB-les'] += (num('masks/lesion/DWI/lesion1/{c}-{r}[ab].*') > 1)
        r['hB-roi'] += (num('masks/roi/DWI/{c}-{r}[ab]_*') > 1)

    r['T2-img'] = num('images/T2/{c}-*.*')
    r['T2w-img'] = num('images/T2w/{c}-*.*')

    r['T2-pro'] = num('masks/prostate/T2/{c}-*.*')
    r['T2w-pro'] = num('masks/prostate/T2w/{c}-*.*')

    r['T2-les'] = num('masks/lesion/T2/lesion1/{c}-*.*')
    r['T2w-les'] = num('masks/lesion/T2/lesion1/{c}-*.*')

    return r


def main():
    # cases = range(350)
    cases = sorted(int(x) for x in (BASE / LIST).read_text().split())
    # print('{}: {}'.format(len(cases), ' '.join(str(x) for x in cases)))

    s = (
        '{case:3}'
        ', {hist}'

        # ', {img-hB-1a}, {img-hB-1b}, {img-hB-2a}, {img-hB-2b}'
        # ', {pro-hB-1a}, {pro-hB-1b}, {pro-hB-2a}, {pro-hB-2b}'
        # ', {les-hB-1a}, {les-hB-1b}, {les-hB-2a}, {les-hB-2b}'<commit_msg>refactoring<commit_after>#!/usr/bin/python3

"""pat
pinky
image-hB image-lB
prostate-hB prostate-lB
lesion-hB lesion-lB
roi-hB roi-lB
"""

from collections import defaultdict

from dwi.types import Path
from tabulate import tabulate

BASE = Path('/mri')
LIST = 'misc/list/all.txt'


def read_cases():
    return sorted(int(x) for x in (BASE / LIST).read_text().split())


def nums(case):
    def num(pat):
        # print(pat, len(list(BASE.glob(pat.format(**d)))))
        return len(list(BASE.glob(pat.format(**d))))

    # r = {}
    r = defaultdict(int)
    r['case'] = case
    d = dict(c=case)
    r['hist'] = num('hist/New_ALL_RALP/{c}_*.*')
    # for scan in ['1a', '1b', '2a', '2b']:
    #     d['s'] = scan
    #     r['img-hB-'+scan] = num('images/DWI/{c}-{s}*.*')
    #     r['img-lB-'+scan] = num('images/DWI_lB/{c}-{s}*.*')
    #     r['pro-hB-'+scan] = num('masks/prostate/DWI/{c}-{s}.*')
    #     r['pro-lB-'+scan] = num('masks/prostate/DWI_lB/{c}-{s}.*')
    #     r['les-hB-'+scan] = num('masks/lesion/DWI/lesion1/{c}-{s}.*')
    #     r['les-lB-'+scan] = num('masks/lesion/DWI_lB/lesion1/{c}-{s}.*')
    #     r['roi-hB-'+scan] = num('masks/roi/DWI/{c}-{s}.*')
    #     r['roi-lB-'+scan] = num('masks/roi/DWI_lB/{c}-{s}.*')
    for rep in [1, 2]:
        d['r'] = rep
        r['hB-img'] += (num('images/DWI/{c}-{r}[ab]*.*') > 1)
        # r['img-Mono'] += (num('images/DWI-Mono/{c}-{r}[ab]') > 1)
        # r['img-Kurt'] += (num('images/DWI-Kurt/{c}-{r}[ab]') > 1)
        r['hB-pro'] += (num('masks/prostate/DWI/{c}-{r}[ab].*') > 1)
        r['hB-les'] += (num('masks/lesion/DWI/lesion1/{c}-{r}[ab].*') > 1)
        r['hB-roi'] += (num('masks/roi/DWI/{c}-{r}[ab]_*') > 1)

    r['T2-img'] = num('images/T2/{c}-*.*')
    r['T2w-img'] = num('images/T2w/{c}-*.*')

    r['T2-pro'] = num('masks/prostate/T2/{c}-*.*')
    r['T2w-pro'] = num('masks/prostate/T2w/{c}-*.*')

    r['T2-les'] = num('masks/lesion/T2/lesion1/{c}-*.*')
    r['T2w-les'] = num('masks/lesion/T2/lesion1/{c}-*.*')

    return r


def main():
    cases = read_cases()
    # print('{}: {}'.format(len(cases), ' '.join(str(x) for x in cases)))

    s = (
        '{case:3}'
        ', {hist}'

        # ', {img-hB-1a}, {img-hB-1b}, {img-hB-2a}, {img-hB-2b}'
        # ', {pro-hB-1a}, {pro-hB-1b}, {pro-hB-2a}, {pro-hB-2b}'
        # ', {les-hB-1a}, {les-hB-1b}, {les-hB-2a}, {les-hB-2b}'
{'fraction_non_alphanumeric': 0.30010559662090813, 'fraction_numerical': 0.01879619852164731, 'mean_word_length': 2.590598938589841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1145669', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2239, 'n_words': 283}