File size: 1,130 Bytes
0eb8972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from pathlib import PurePosixPath

KINDS = ('palabras', 'silabas', 'oraciones', 'cuentos')

def testing(data, collection):
    return any(c['id'] == collection and (c.get('is_test') or c['name'].casefold().startswith('prueba')) for c in data['collections'])

def folder(data, collection, kind):
    if data.get('storage_layout') == 'types':
        return f'pruebas/{kind}/{collection}' if testing(data, collection) else kind
    return f'v1/colecciones/{collection}/{kind}'

def manifests(data):
    if data.get('storage_layout') != 'types':
        return {}
    groups = {kind: [] for kind in KINDS}
    groups.update({f'pruebas/{kind}': [] for kind in KINDS})
    for record in data['recordings']:
        item = data['items'][record['item_id']]
        target = f"pruebas/{item['kind']}" if testing(data, record['collection']) else item['kind']
        groups[target].append(dict(record, file_name=PurePosixPath(record['path']).name,
            word_id=item['id'], dataset='pruebas' if testing(data, record['collection']) else item['kind']))
    return {f'{path}/manifest.json': records for path, records in groups.items()}