File size: 1,178 Bytes
341e402
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Read the released v1 shards (data/tasks/*.tar.zst) as a stream and record, per v1 task, the submission indices
that submissions.json marks 'seen'. Out: out_v49/work/v1_seen.json (task_id -> [indices])."""
import glob, json, os, sys, tarfile
from multiprocessing import Pool
import zstandard

V = '<ROOT>/'
OUT = V + 'build_v2/out_v49/work/v1_seen.json'


def one(path):
    out = {}
    with open(path, 'rb') as f:
        r = zstandard.ZstdDecompressor().stream_reader(f)
        with tarfile.open(fileobj=r, mode='r|') as t:
            for m in t:
                if m.isfile() and m.name.endswith('/environment/context/submissions.json'):
                    subs = json.loads(t.extractfile(m).read())
                    out[m.name.split('/')[0]] = [s['index'] for s in subs if s.get('result') == 'seen']
    return out


if __name__ == '__main__':
    os.makedirs(os.path.dirname(OUT), exist_ok=True)
    allr = {}
    with Pool(int(sys.argv[1]) if len(sys.argv) > 1 else 4) as p:
        for d in p.imap_unordered(one, sorted(glob.glob(V + 'data/tasks/*.tar.zst'))):
            allr.update(d)
    json.dump(allr, open(OUT, 'w'))
    print('v1 tasks read', len(allr))