formatting fix

This commit is contained in:
klemek
2021-01-11 15:50:26 +01:00
parent 034562f167
commit 5563945dcc
4 changed files with 28 additions and 18 deletions
+4 -4
View File
@@ -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)})",
]
+17 -10
View File
@@ -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
+6 -3
View File
@@ -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
+1 -1
View File
@@ -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