| from dataclasses import dataclass |
| from typing import Dict, Any, List |
|
|
| @dataclass |
| class ScoreResult: |
| score: float |
| details: Dict[str, Any] |
|
|
| def score(sample: Dict[str, Any], prediction: str) -> ScoreResult: |
| p = (prediction or "").lower() |
| words_ok = len(p.split()) <= 700 |
|
|
| has_corr = "correlation" in p or "convergence" in p |
| has_div = "diversity" in p or "response" in p |
| has_trend = "decline" in p or "trend" in p |
| has_time = "onset" in p or "year" in p |
| has_tip = "tipping" in p or "proximity" in p |
|
|
| raw = ( |
| 0.15 * int(words_ok) + |
| 0.25 * int(has_corr) + |
| 0.20 * int(has_div) + |
| 0.20 * int(has_trend) + |
| 0.10 * int(has_time) + |
| 0.10 * int(has_tip) |
| ) |
| return ScoreResult(score=min(1.0, raw), details={"id": sample.get("id")}) |
|
|
| def aggregate(results: List[ScoreResult]) -> Dict[str, Any]: |
| if not results: |
| return {"mean": 0.0, "n": 0} |
| return {"mean": sum(r.score for r in results)/len(results), "n": len(results)} |
|
|