1from typing import List, Dict, Any
2from ._memobin import construct_dataset_url, construct_reconstructed_url
3from ..types import Algorithm
5GITHUB_ALGORITHMS_PREFIX = "https://github.com/magland/ephys_compression_tests/blob/main/python/ephys_compression_tests/algorithms/"
6GITHUB_DATASETS_PREFIX = "https://github.com/magland/ephys_compression_tests/blob/main/python/ephys_compression_tests/datasets/"
9def collect_algorithm_info(algorithms: List[Dict[str, Algorithm]]) -> List[Dict[str, Any]]:
10 """Collect information about compression algorithms.
12 Args:
13 algorithms: List of algorithm dictionaries
15 Returns:
16 List of algorithm information dictionaries
17 """
18 algorithm_info = []
19 for algorithm in algorithms:
20 info = {
21 "name": algorithm.name,
22 "description": algorithm.description if algorithm.description else "",
23 "long_description": algorithm.long_description if algorithm.long_description else "",
24 "version": algorithm.version,
25 "tags": algorithm.tags if algorithm.tags else [],
26 }
27 if algorithm.source_file:
28 info["source_file"] = GITHUB_ALGORITHMS_PREFIX + algorithm.source_file
29 algorithm_info.append(info)
30 return algorithm_info
33def collect_dataset_info(datasets: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
34 """Collect information about benchmark datasets.
36 Args:
37 datasets: List of dataset dictionaries
39 Returns:
40 List of dataset information dictionaries
41 """
42 dataset_info = []
43 for dataset in datasets:
44 info = {
45 "name": dataset.name,
46 "description": dataset.description if dataset.description else "",
47 "long_description": dataset.long_description if dataset.long_description else "",
48 "version": dataset.version,
49 "tags": dataset.tags if dataset.tags else [],
50 "data_url_raw": construct_dataset_url(
51 dataset.name, dataset.version, "dat"
52 ),
53 "data_url_npy": construct_dataset_url(
54 dataset.name, dataset.version, "npy"
55 ),
56 "data_url_json": construct_dataset_url(
57 dataset.name, dataset.version, "json"
58 ),
59 }
60 if dataset.source_file:
61 info["source_file"] = GITHUB_DATASETS_PREFIX + dataset.source_file
62 dataset_info.append(info)
63 return dataset_info
66def add_reconstructed_urls_to_results(results: List[Dict[str, Any]], algorithms: List[Algorithm]) -> None:
67 """Add reconstructed data URL to results for lossy algorithms.
69 Args:
70 results: List of benchmark result dictionaries (modified in-place)
71 algorithms: List of algorithm objects
72 """
73 # Create a lookup dict for algorithm tags
74 alg_tags_map = {alg.name: alg.tags for alg in algorithms}
76 for result in results:
77 alg_name = result.get("algorithm")
78 if not alg_name:
79 continue
81 alg_tags = alg_tags_map.get(alg_name, [])
83 # Only add reconstructed URL for lossy algorithms (just .dat format)
84 if "lossy" in alg_tags:
85 result["reconstructed_url_raw"] = construct_reconstructed_url(
86 alg_name,
87 result["dataset"],
88 result["algorithm_version"],
89 result["dataset_version"],
90 result["system_version"],
91 "dat",
92 )