emotions / ressources /generate_emotions_ranked.py
RemiFabre
Subjective ranking of emotions
d1bec61
#!/usr/bin/env python3
"""Generate a simple quality report for the Reachy Mini moves dataset."""
from pathlib import Path
from ruamel.yaml import YAML
ROOT = Path(__file__).resolve().parent
DATASET_PATH = ROOT / "emotions.yml"
OUTPUT_PATH = ROOT / "emotions_ranked.txt"
DATASET_NAME = "Reachy Mini moves dataset"
def load_moves() -> list[dict]:
"""Return the list of moves defined in emotions.yml."""
yaml = YAML(typ="safe")
with DATASET_PATH.open(encoding="utf-8") as stream:
data = yaml.load(stream) or {}
return data.get("moves", [])
def main() -> None:
categories: dict[str, list[tuple[str, str]]] = {
"excellent": [],
"ok": [],
"bad": [],
}
for move in load_moves():
quality = (move.get("quality") or "").strip().lower()
if quality not in categories:
continue
name = move.get("id") or move.get("clean_name") or "unnamed_move"
precision = (move.get("precision") or "ambiguous").strip().lower()
precision_label = "clear" if precision == "clear" else "ambiguous"
categories[quality].append((name, precision_label))
sections: list[str] = [
f"{DATASET_NAME} quality ranking",
"",
]
quality_labels = [
("excellent", "Excellent"),
("ok", "OK"),
("bad", "Bad"),
]
for key, label in quality_labels:
sections.append(label)
sections.append("-" * len(label))
entries = sorted(categories[key], key=lambda item: item[0].lower())
if not entries:
sections.append("- None")
else:
for name, precision in entries:
sections.append(f"- {name} ({precision})")
sections.append("")
OUTPUT_PATH.write_text("\n".join(sections).strip() + "\n", encoding="utf-8")
if __name__ == "__main__":
main()