small fixes
This commit is contained in:
@@ -2,7 +2,7 @@ from typing import List
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
from utils import str_date, str_datetime, from_now, plural, percent
|
from utils import str_date, str_datetime, from_now, plural, percent, precise, top_key
|
||||||
|
|
||||||
|
|
||||||
class Frequency:
|
class Frequency:
|
||||||
@@ -20,8 +20,8 @@ class Frequency:
|
|||||||
def to_string(self) -> List[str]:
|
def to_string(self) -> List[str]:
|
||||||
delta = self.dates[-1] - self.dates[0]
|
delta = self.dates[-1] - self.dates[0]
|
||||||
total_msg = len(self.dates)
|
total_msg = len(self.dates)
|
||||||
busiest_weekday = sorted(self.week)[-1]
|
busiest_weekday = top_key(self.week)
|
||||||
busiest_hour = sorted(self.day)[-1]
|
busiest_hour = top_key(self.day)
|
||||||
n_weekdays = delta.days // 7
|
n_weekdays = delta.days // 7
|
||||||
if (
|
if (
|
||||||
self.dates[0].weekday() <= busiest_weekday
|
self.dates[0].weekday() <= busiest_weekday
|
||||||
@@ -34,11 +34,11 @@ class Frequency:
|
|||||||
return [
|
return [
|
||||||
f"- **earliest message**: {str_datetime(self.dates[0])} ({from_now(self.dates[0])})",
|
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"- **latest message**: {str_datetime(self.dates[-1])} ({from_now(self.dates[-1])})",
|
||||||
f"- **messages/day**: {total_msg/delta.days:,.2f}",
|
f"- **messages/day**: {precise(total_msg/delta.days, precision=3)}",
|
||||||
f"- **busiest day of week**: {calendar.day_name[busiest_weekday]} (~{self.week[busiest_weekday]/n_weekdays:,.2f} msg, {percent(self.week[busiest_weekday]/total_msg)})",
|
f"- **busiest day of week**: {calendar.day_name[busiest_weekday]} (~{precise(self.week[busiest_weekday]/n_weekdays, precision=3)} msg, {percent(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"- **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"- **messages/hour**: {precise(total_msg*3600/delta.total_seconds(), precision=3)}",
|
||||||
f"- **busiest hour of day**: {busiest_hour:0>2}:00 (~{self.day[busiest_hour]/n_hours:,.2f} msg, {percent(self.day[busiest_hour]/total_msg)})",
|
f"- **busiest hour of day**: {busiest_hour:0>2}:00 (~{precise(self.day[busiest_hour]/n_hours, precision=3)} msg, {percent(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"- **busiest hour ever**: {str_datetime(self.busiest_hour)} ({from_now(self.busiest_hour)}) ({self.busiest_hour_count} msg)",
|
||||||
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)})",
|
f"- **longest break**: {plural(round(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)})",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -37,8 +37,11 @@ class Presence:
|
|||||||
)[-1]
|
)[-1]
|
||||||
ret += [
|
ret += [
|
||||||
f"- **most visited channel**: {channel_mention(top_channel)} ({self.channel_usage[top_channel]:,} msg, {percent(self.channel_usage[top_channel]/channel_sum)})",
|
f"- **most visited channel**: {channel_mention(top_channel)} ({self.channel_usage[top_channel]:,} msg, {percent(self.channel_usage[top_channel]/channel_sum)})",
|
||||||
f"- **mostly found in**: {channel_mention(found_in)} ({self.channel_usage[found_in]:,} msg, {percent(self.channel_usage[found_in]/self.channel_total[found_in])} of channel's)",
|
|
||||||
]
|
]
|
||||||
|
if member_specific:
|
||||||
|
ret += [
|
||||||
|
f"- **mostly found in**: {channel_mention(found_in)} ({self.channel_usage[found_in]:,} msg, {percent(self.channel_usage[found_in]/self.channel_total[found_in])} of channel's)"
|
||||||
|
]
|
||||||
if member_specific:
|
if member_specific:
|
||||||
if len(self.mentions) > 0:
|
if len(self.mentions) > 0:
|
||||||
top_mention = top_key(self.mentions)
|
top_mention = top_key(self.mentions)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import discord
|
|||||||
from logs import ChannelLogs, MessageLog
|
from logs import ChannelLogs, MessageLog
|
||||||
from data_types import Emote, get_emote_dict
|
from data_types import Emote, get_emote_dict
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
from utils import emojis, COMMON_HELP_ARGS
|
from utils import emojis, COMMON_HELP_ARGS, plural, precise
|
||||||
|
|
||||||
|
|
||||||
class EmotesScanner(Scanner):
|
class EmotesScanner(Scanner):
|
||||||
@@ -50,8 +50,7 @@ class EmotesScanner(Scanner):
|
|||||||
len(self.members) == 0 or len(self.members) > 1
|
len(self.members) == 0 or len(self.members) > 1
|
||||||
)
|
)
|
||||||
# Create emotes dict from custom emojis of the guild
|
# Create emotes dict from custom emojis of the guild
|
||||||
# Create emotes dict from custom emojis of the guild
|
self.emotes = get_emote_dict(guild)
|
||||||
self.emotes = get_emote_dict(message.channel.guild)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
def compute_message(self, channel: ChannelLogs, message: MessageLog):
|
||||||
@@ -79,10 +78,10 @@ class EmotesScanner(Scanner):
|
|||||||
usage_count += self.emotes[name].usages
|
usage_count += self.emotes[name].usages
|
||||||
reaction_count += self.emotes[name].reactions
|
reaction_count += self.emotes[name].reactions
|
||||||
res += [
|
res += [
|
||||||
f"Total: {usage_count:,} times ({usage_count / self.msg_count:.4f} / message)"
|
f"Total: {plural(usage_count,'time')} ({precise(usage_count/self.msg_count)}/msg)"
|
||||||
]
|
]
|
||||||
if reaction_count > 0:
|
if reaction_count > 0:
|
||||||
res[-1] += f" and {reaction_count:,} reactions"
|
res[-1] += f" and {plural(reaction_count, 'reaction')}"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -95,7 +94,7 @@ class EmotesScanner(Scanner):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
impacted = False
|
impacted = False
|
||||||
# If author is included in the selection (empty list is all)
|
# If author is included in the selection (empty list is all)
|
||||||
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
if not message.bot and len(raw_members) == 0 or message.author in raw_members:
|
||||||
impacted = True
|
impacted = True
|
||||||
# Find all emotes un the current message in the form "<:emoji:123456789>"
|
# Find all emotes un the current message in the form "<:emoji:123456789>"
|
||||||
# Filter for known emotes
|
# Filter for known emotes
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from collections import defaultdict
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
|
||||||
# Custom libs
|
# Custom libs
|
||||||
|
|
||||||
from .scanner import Scanner
|
from .scanner import Scanner
|
||||||
from . import FrequencyScanner, CompositionScanner, PresenceScanner, EmotesScanner
|
from . import FrequencyScanner, CompositionScanner, PresenceScanner
|
||||||
from data_types import Frequency, Composition, Presence, get_emote_dict
|
from data_types import Frequency, Composition, Presence
|
||||||
from logs import ChannelLogs, MessageLog
|
from logs import ChannelLogs, MessageLog
|
||||||
from utils import COMMON_HELP_ARGS
|
from utils import COMMON_HELP_ARGS
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ class FullScanner(Scanner):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def init(self, message: discord.Message, *args: str) -> bool:
|
async def init(self, message: discord.Message, *args: str) -> bool:
|
||||||
guild = message.channel.guild
|
|
||||||
self.freq = Frequency()
|
self.freq = Frequency()
|
||||||
self.compo = Composition()
|
self.compo = Composition()
|
||||||
self.pres = Presence()
|
self.pres = Presence()
|
||||||
@@ -42,8 +40,10 @@ class FullScanner(Scanner):
|
|||||||
FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
|
FrequencyScanner.analyse_message(message, self.freq, self.raw_members)
|
||||||
CompositionScanner.analyse_message(message, self.compo, self.raw_members)
|
CompositionScanner.analyse_message(message, self.compo, self.raw_members)
|
||||||
PresenceScanner.analyse_message(channel, message, self.pres, self.raw_members)
|
PresenceScanner.analyse_message(channel, message, self.pres, self.raw_members)
|
||||||
return not message.bot and (
|
return (
|
||||||
len(self.raw_members) == 0 or message.author in self.raw_members
|
not message.bot
|
||||||
|
and len(self.raw_members) == 0
|
||||||
|
or message.author in self.raw_members
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_results(self, intro: str) -> List[str]:
|
def get_results(self, intro: str) -> List[str]:
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class PresenceScanner(Scanner):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
impacted = False
|
impacted = False
|
||||||
# If author is included in the selection (empty list is all)
|
# If author is included in the selection (empty list is all)
|
||||||
if not message.bot and (len(raw_members) == 0 or message.author in raw_members):
|
if not message.bot and len(raw_members) == 0 or message.author in raw_members:
|
||||||
impacted = True
|
impacted = True
|
||||||
pres.channel_usage[channel.id] += 1
|
pres.channel_usage[channel.id] += 1
|
||||||
for mention in message.mentions:
|
for mention in message.mentions:
|
||||||
|
|||||||
+4
-2
@@ -108,8 +108,10 @@ def percent(p: float) -> str:
|
|||||||
return f"{precise(100*p)}%"
|
return f"{precise(100*p)}%"
|
||||||
|
|
||||||
|
|
||||||
def precise(p: float) -> str:
|
def precise(p: float, *, precision: int = 2) -> str:
|
||||||
precision = abs(min(0, math.ceil(math.log10(p)) - 2))
|
if p == 0:
|
||||||
|
return "0"
|
||||||
|
precision = abs(min(0, math.ceil(math.log10(p)) - precision))
|
||||||
s = "{:." + str(precision) + "f}"
|
s = "{:." + str(precision) + "f}"
|
||||||
return s.format(p)
|
return s.format(p)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user