File size: 2,469 Bytes
6a7ed30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""datensatz_ccf.py -- Stufe 2 fuer CCF: jede Logzeile und jeder Protokollpunkt als Episode (Schritt angenommen/abgelehnt,
Sekante, Nullstelle, Start), gescheiterte Suchen und Quellterm-Boegen eingeschlossen. Laeuft auf dem Mac (leicht).
Aufruf (in bib/ccf/): python3 datensatz_ccf.py <aus_dir>"""
import glob
import json
import os
import re
import sys
import zstandard as zstd

AUS = sys.argv[1]
os.makedirs(AUS, exist_ok=True)
KV = re.compile(r"([A-Za-z_][A-Za-z0-9_\-()'|/^*]*?)\s*=\s*([-+]?[0-9.]+(?:e[-+]?\d+)?)")
ZAHL = {}


def schreiber(name):
    f = open(f'{AUS}/{name}', 'wb')
    return f, zstd.ZstdCompressor(level=10).stream_writer(f)


def art(z):
    s = z.strip()
    if 'nicht konvergiert' in s or s.startswith('Abbruch'):
        return 'schritt_abgelehnt'
    if s.startswith('NULLSTELLE') or 'NULLDURCHGANG' in s:
        return 'kreuzung'
    if s.startswith('Sekante'):
        return 'sekante'
    if s.startswith(('Start', 'Neustart', 'Test', 'Aufbau', 'instabil1')):
        return 'start'
    if s.startswith('lambda=') or s.startswith('it '):
        return 'schritt' if s.startswith('lambda=') else 'newton_iteration'
    return 'sonstig'


f, w = schreiber('ccf_logzeilen.jsonl.zst'); n = 0
for pf in sorted(glob.glob('*.log')):
    lauf = pf[:-4]
    for i, z in enumerate(open(pf, errors='replace')):
        if not z.strip():
            continue
        d = dict(datei=pf, lauf=lauf, zeile=i, art=art(z), text=z.rstrip('\n'),
                 felder={k: float(v) for k, v in KV.findall(z)})
        w.write((json.dumps(d, ensure_ascii=False) + '\n').encode()); n += 1
w.close(); ZAHL['ccf_logzeilen.jsonl.zst'] = n

f, w = schreiber('ccf_protokollpunkte.jsonl.zst'); n = 0
for pf in sorted(glob.glob('*.json')):
    try:
        P = json.load(open(pf))
    except ValueError:
        continue
    L = P if isinstance(P, list) else [P]
    for i, p in enumerate(L):
        w.write((json.dumps(dict(datei=pf, index=i, punkt=p), ensure_ascii=False, default=str) + '\n').encode()); n += 1
w.close(); ZAHL['ccf_protokollpunkte.jsonl.zst'] = n

f, w = schreiber('ccf_dokumente.jsonl.zst'); n = 0
for pf in sorted(glob.glob('*.md')) + sorted(glob.glob('*.py')) + sorted(glob.glob('*.sh')):
    w.write((json.dumps(dict(datei=pf, text=open(pf, errors='replace').read()), ensure_ascii=False) + '\n').encode()); n += 1
w.close(); ZAHL['ccf_dokumente.jsonl.zst'] = n

json.dump(ZAHL, open(f'{AUS}/manifest_ccf.json', 'w'), indent=1)
print(ZAHL)