0.2.0: display top tags + rankings

This commit is contained in:
Mark Joshwel 2024-05-25 02:20:55 +08:00
parent 0505b93539
commit 8f0e846e95
2 changed files with 23 additions and 7 deletions

View file

@ -261,6 +261,8 @@ class ListeningReport(NamedTuple):
tag_counter: Counter[str] tag_counter: Counter[str]
tags: list[str] tags: list[str]
tv: str
tc: int | float
match behaviour.format: match behaviour.format:
case FormatTypeEnum.ASCII: case FormatTypeEnum.ASCII:
@ -339,8 +341,9 @@ class ListeningReport(NamedTuple):
) )
tags = [] tags = []
for tn, tc in tag_counter.most_common(5): for tn, _tc in tag_counter.most_common(5):
tv: str = "" tv = ""
tc = round(_tc)
if tn in global_tag_counter: if tn in global_tag_counter:
counter = global_tag_counter[tn] counter = global_tag_counter[tn]
@ -356,6 +359,12 @@ class ListeningReport(NamedTuple):
) )
tv = f": #{_tv}" if (_tv > 0) else "" tv = f": #{_tv}" if (_tv > 0) else ""
_flt_ranks = [val for _, val in counter.most_common()]
_int_ranks = [round(val) for val in _flt_ranks]
if (tc in _int_ranks) and (_int_ranks.count(tc) > 1): # type: ignore
tc = round(_tc, 2)
tags.append(f"{tn} ({tc}%{tv})") tags.append(f"{tn} ({tc}%{tv})")
basket.append( basket.append(
@ -425,8 +434,9 @@ class ListeningReport(NamedTuple):
) )
tags = [] tags = []
for tn, tc in tag_counter.most_common(5): for tn, _tc in tag_counter.most_common(5):
tv = "" tv = ""
tc = round(_tc)
if tn in global_tag_counter: if tn in global_tag_counter:
counter = global_tag_counter[tn] counter = global_tag_counter[tn]
@ -442,6 +452,12 @@ class ListeningReport(NamedTuple):
) )
tv = f": #{_tv}" if (_tv > 0) else "" tv = f": #{_tv}" if (_tv > 0) else ""
_flt_ranks = [val for _, val in counter.most_common()]
_int_ranks = [round(val) for val in _flt_ranks]
if (tc in _int_ranks) and (_int_ranks.count(tc) > 1): # type: ignore
tc = round(_tc, 2)
tags.append(f"{tn} ({tc}%{tv})") tags.append(f"{tn} ({tc}%{tv})")
basket.append(f"\n{prefix}Top tags" + ": " + ", ".join(tags)) basket.append(f"\n{prefix}Top tags" + ": " + ", ".join(tags))
@ -719,7 +735,7 @@ def _rank(
def calculate_tag_score( def calculate_tag_score(
tag_values: tuple[int, ...], tags: dict[str, tuple[int, ...]] tag_values: tuple[int, ...], tags: dict[str, tuple[int, ...]]
) -> int: ) -> float:
v_cum_sum = sum([sum(tv) for tv in tags.values()]) v_cum_sum = sum([sum(tv) for tv in tags.values()])
v_cum_avg = sum([(sum(tv) / len(tv)) for tv in tags.values()]) v_cum_avg = sum([(sum(tv) / len(tv)) for tv in tags.values()])
@ -728,7 +744,7 @@ def calculate_tag_score(
tag_obj_score = (0.5 * v_avg) + (0.5 * v_sum) tag_obj_score = (0.5 * v_avg) + (0.5 * v_sum)
tag_cum_score = (0.5 * v_cum_sum) + (0.5 * v_cum_avg) tag_cum_score = (0.5 * v_cum_sum) + (0.5 * v_cum_avg)
return round(100 * (tag_obj_score / tag_cum_score)) return 100 * (tag_obj_score / tag_cum_score)
def make_circle_report( def make_circle_report(
@ -757,7 +773,7 @@ def make_circle_report(
global_tag_counter[tag_name][report.user] += calculate_tag_score( global_tag_counter[tag_name][report.user] += calculate_tag_score(
tag_value, tags=report.tags tag_value, tags=report.tags
) ) # type: ignore
for leaderboard_pos, report in enumerate( for leaderboard_pos, report in enumerate(
reversed( reversed(

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "lfcircle" name = "lfcircle"
version = "0.1.4" version = "0.2.0"
description = "last.fm statistics generator for your friend circle!" description = "last.fm statistics generator for your friend circle!"
authors = ["Mark Joshwel <mark@joshwel.co>"] authors = ["Mark Joshwel <mark@joshwel.co>"]
license = "Unlicense" license = "Unlicense"