From 5563945dcc98af8adb70926d9db7e2a570fc2b10 Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 11 Jan 2021 15:50:26 +0100 Subject: [PATCH] formatting fix --- src/data_types/frequency.py | 8 ++++---- src/data_types/other.py | 27 +++++++++++++++++---------- src/scanners/other_scanner.py | 9 ++++++--- src/utils/utils.py | 2 +- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/data_types/frequency.py b/src/data_types/frequency.py index 44e04c2..f84a177 100644 --- a/src/data_types/frequency.py +++ b/src/data_types/frequency.py @@ -2,7 +2,7 @@ from typing import List from datetime import timedelta import calendar -from utils import str_date, str_datetime, from_now +from utils import str_date, str_datetime, from_now, plural class Frequency: @@ -35,10 +35,10 @@ class Frequency: f"- **earliest message**: {str_datetime(self.dates[0])} ({from_now(self.dates[0])})", f"- **latest message**: {str_datetime(self.dates[-1])} ({from_now(self.dates[-1])})", f"- **messages/day**: {total_msg/delta.days:,.2f}", - f"- **busiest day of week**: {calendar.day_name[busiest_weekday]} (~{self.week[busiest_weekday]/n_weekdays:,.2f} msg) ({round(100*self.week[busiest_weekday]/total_msg)}%)", + f"- **busiest day of week**: {calendar.day_name[busiest_weekday]} (~{self.week[busiest_weekday]/n_weekdays:,.2f} msg, {round(100*self.week[busiest_weekday]/total_msg)}%)", f"- **busiest day ever**: {str_date(self.busiest_day)} ({from_now(self.busiest_day)}) ({self.busiest_day_count} msg)", f"- **messages/hour**: {total_msg*3600/delta.total_seconds():,.2f}", - f"- **busiest hour of day**: {busiest_hour:0>2}:00 (~{self.day[busiest_hour]/n_hours:,.2f} msg) ({round(100*self.day[busiest_hour]/total_msg)}%)", + f"- **busiest hour of day**: {busiest_hour:0>2}:00 (~{self.day[busiest_hour]/n_hours:,.2f} msg, {round(100*self.day[busiest_hour]/total_msg)}%)", f"- **busiest hour ever**: {str_datetime(self.busiest_hour)} ({from_now(self.busiest_hour)}) ({self.busiest_hour_count} msg)", - f"- **longest break**: {self.longest_break.total_seconds()//3600:,.0f} hours ({self.longest_break.days:,} days) from {str_datetime(self.longest_break_start)} ({from_now(self.longest_break_start)})", + f"- **longest break**: {plural(int(self.longest_break.total_seconds()/3600), 'hour')} ({plural(self.longest_break.days,'day')}) from {str_datetime(self.longest_break_start)} ({from_now(self.longest_break_start)})", ] diff --git a/src/data_types/other.py b/src/data_types/other.py index 3c04f78..c54ed55 100644 --- a/src/data_types/other.py +++ b/src/data_types/other.py @@ -2,7 +2,7 @@ from typing import List from collections import defaultdict -from utils import mention, channel_mention +from utils import mention, channel_mention, plural class Other: @@ -21,14 +21,21 @@ class Other: ret += [ f"- **most visited channel**: {channel_mention(top_channel)} ({self.channel_usage[top_channel]:,} msg, {100*self.channel_usage[top_channel]//channel_sum:.0f}%)" ] - if show_mentioned and len(self.mentions) > 0: - top_mention = sorted(self.mentions)[-1] - mention_sum = sum(self.mentions.values()) + if show_mentioned: + if len(self.mentions) > 0: + top_mention = sorted(self.mentions)[-1] + mention_sum = sum(self.mentions.values()) + ret += [ + f"- **mentioned**: {plural(mention_sum, 'time')}", + f"- **mostly mentioned by**: {mention(top_mention)} ({plural(self.mentions[top_mention], 'time')}, {100*self.mentions[top_mention]//mention_sum:.0f}%)", + ] + else: + ret += [f"- **mentioned**: 0 times"] + if self.used_reaction_total > 0: ret += [ - f"- **mentioned**: {mention_sum:,} times", - f"- **mostly mentioned by**: {mention(top_mention)} ({self.mentions[top_mention]:,} times, {100*self.mentions[top_mention]//mention_sum:.0f}%)", + f"- **reactions**: {plural(self.used_reaction_total, 'time')}", + f"- **most used reaction**: {self.most_used_reaction} ({plural(self.most_used_reaction_count, 'time')}, {100*self.most_used_reaction_count/self.used_reaction_total:.0f}%)", ] - return ret + [ - f"- **reactions**: {self.used_reaction_total:,}", - f"- **most used reaction**: {self.most_used_reaction} ({self.most_used_reaction_count:,} uses, {100*self.most_used_reaction_count/self.used_reaction_total:.0f}%)", - ] # TODO + else: + ret += [f"- **reactions**: 0 times"] + return ret diff --git a/src/scanners/other_scanner.py b/src/scanners/other_scanner.py index cb06405..2b1fa3c 100644 --- a/src/scanners/other_scanner.py +++ b/src/scanners/other_scanner.py @@ -66,8 +66,11 @@ class OtherScanner(Scanner): @staticmethod def compute_results(other: Other, emotes: Dict[str, Emote]): - # calculate most used reaction - other.most_used_reaction = sorted(emotes, key=lambda k: emotes[k].reactions)[-1] - other.most_used_reaction_count = emotes[other.most_used_reaction].reactions # calculate total reactions other.used_reaction_total = sum([emote.reactions for emote in emotes.values()]) + if other.used_reaction_total > 0: + # calculate most used reaction + other.most_used_reaction = sorted( + emotes, key=lambda k: emotes[k].reactions + )[-1] + other.most_used_reaction_count = emotes[other.most_used_reaction].reactions diff --git a/src/utils/utils.py b/src/utils/utils.py index a0e9d1a..8743387 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -86,7 +86,7 @@ def aggregate(names: List[str]) -> str: def plural(count: int, word: str) -> str: - return str(count) + " " + word + ("s" if count != 1 else "") + return f"{count:,} {word}{'s' if count != 1 else ''}" # DATE FORMATTING