Files
Investidor-V2/outputs/investmoz-referencias-economicas-QA-20261016/prepare-matrix.py
T
nala 2d23157e40
tests / ci (push) Canceled after 0s
versao nrgocios
2026-10-16 13:06:58 +02:00

15 lines
1.4 KiB
Python

from pathlib import Path
import csv,io,json,hashlib
csv.field_size_limit(10000000)
out=Path(__file__).resolve().parent;root=out.parents[1];path=root/'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv';raw=path.read_bytes();text=raw.decode('utf-8-sig');lines=text.splitlines(keepends=True);reader=csv.reader(io.StringIO(text,newline=''));headers=next(reader);previous=reader.line_num;selected=[];ids={'RF-CLU-001','RF-CLU-003','RF-PII-017','MASTER-9dee08d0-0070','OP-9f173ed3-0141','OP-FIELD-opportunity-subsector_id','OP-FIELD-opportunity-economic_activity_id'};count=0
for row in reader:
end=reader.line_num;count+=1
if row[0]in ids:selected.append({'id':row[0],'row':row,'start':previous,'end':end,'raw':''.join(lines[previous:end])})
previous=end
assert len(selected)==7 and count==3402
sha=hashlib.sha256(raw).hexdigest();assert sha=='70488d4d79d30b2d399b849ddd979334289c60c2d920a0a0288e77f5866bfc59','Matriz changed: reconcile before write'
(out/'matrix-tool').mkdir(exist_ok=True)
(out/'matrix-tool/before.csv').write_bytes(raw)
(out/'matrix-tool/input.json').write_text(json.dumps({'matrix':str(path),'sha256_before':sha,'rows_total':count,'headers':headers,'selected':selected,'csv_subset':''.join(lines[:1])+''.join(x['raw']for x in selected)},ensure_ascii=False),'utf-8')
print(json.dumps({'selected':len(selected),'preserve_raw_rows':count-7,'headers':len(headers)}))