feat: explain activity data quality
This commit is contained in:
@@ -68,7 +68,7 @@ def activity_rows(
|
||||
average_weight_g=round(sum(r.weight_g for r in items) / len(items)),
|
||||
max_weight_g=max(r.weight_g for r in items), last_confirmed_at=latest,
|
||||
activity_score=activity, confidence_score=confidence,
|
||||
explanation=f"{len(items)} свежих уловов от {len(players)} игроков. Последнее подтверждение {freshness_text}." + (" Данных мало." if len(items) < 3 else ""),
|
||||
explanation=_explanation(len(items), len(players), freshness_text, activity, confidence),
|
||||
))
|
||||
return sorted(result, key=lambda row: (row.activity_score, row.last_confirmed_at), reverse=True)
|
||||
|
||||
@@ -82,3 +82,27 @@ def _freshness_text(delta: timedelta) -> str:
|
||||
if minutes < 60:
|
||||
return f"{minutes} мин. назад"
|
||||
return f"{minutes // 60} ч. назад"
|
||||
|
||||
|
||||
def _explanation(catches: int, players: int, freshness: str, activity: int, confidence: int) -> str:
|
||||
activity_label = "Высокая" if activity >= 60 else "Средняя" if activity >= 40 else "Низкая"
|
||||
confidence_label = "высокая" if confidence >= 70 else "средняя" if confidence >= 40 else "низкая"
|
||||
summary = (
|
||||
f"{activity_label} активность: {_count(catches, 'свежий улов', 'свежих улова', 'свежих уловов')} "
|
||||
f"от {_count(players, 'игрока', 'игроков', 'игроков')}. "
|
||||
f"Последнее подтверждение {freshness}. Уверенность {confidence_label}."
|
||||
)
|
||||
return summary + (" Данных мало: нужно хотя бы 3 наблюдения." if catches < 3 else "")
|
||||
|
||||
|
||||
def _count(value: int, one: str, few: str, many: str) -> str:
|
||||
remainder = value % 100
|
||||
if 11 <= remainder <= 14:
|
||||
word = many
|
||||
elif value % 10 == 1:
|
||||
word = one
|
||||
elif 2 <= value % 10 <= 4:
|
||||
word = few
|
||||
else:
|
||||
word = many
|
||||
return f"{value} {word}"
|
||||
|
||||
Reference in New Issue
Block a user