Spaces:
Running
Running
Download build_ui_payload.py from THULab/CompressionBenchmark: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/THULab/CompressionBenchmark/resolve/main/build_ui_payload.py
- Command line
-
hf download hf://spaces/THULab/CompressionBenchmark/build_ui_payload.py
-
curl -L -o build_ui_payload.py https://huggingface.co/spaces/THULab/CompressionBenchmark/resolve/main/build_ui_payload.py
1.85 kB
| """Build a compact UI payload from the independently hashed full result snapshot.""" | |
| from __future__ import annotations | |
| import datetime | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent | |
| def build() -> None: | |
| source = ROOT / 'data.json' | |
| data = json.loads(source.read_text()) | |
| rows = data['dataset_results'] | |
| fields = {'datasets': 'dataset', 'scopes': 'scope', 'runtimes': 'runtime', | |
| 'families': 'family', 'configurations': 'algorithm_variant'} | |
| tables = {key: sorted({r[field] for r in rows}) for key, field in fields.items()} | |
| indices = {key: {v:i for i,v in enumerate(values)} for key,values in tables.items()} | |
| compact = [] | |
| for r in rows: | |
| compact.append([*(indices[key][r[field]] for key,field in fields.items()), | |
| r['compression_rate'], r['compression_time_ns_per_point'], | |
| r['decompression_time_ns_per_point'], r['original_size_bytes'], | |
| r['compressed_size_bytes']]) | |
| payload = {key: data[key] for key in ('schema_version','benchmark','coverage','datasets','methods','scopes','source','paper_table3')} | |
| payload['exported_at'] = datetime.datetime.now(datetime.timezone.utc).isoformat() | |
| payload['source_data_sha256'] = hashlib.sha256(source.read_bytes()).hexdigest() | |
| payload['record_tables'] = tables | |
| payload['compact_records'] = compact | |
| output = ROOT / 'ui-data.json' | |
| output.write_text(json.dumps(payload, ensure_ascii=False, separators=(',', ':'), allow_nan=False)+'\n') | |
| print(json.dumps({'file':output.name,'records':len(rows),'bytes':output.stat().st_size, | |
| 'source_data_sha256':payload['source_data_sha256'], | |
| 'ui_sha256':hashlib.sha256(output.read_bytes()).hexdigest()})) | |
| if __name__ == '__main__': | |
| build() | |