From a0b98913bf3d04a9058356cfef854b90572d26bf Mon Sep 17 00:00:00 2001 From: DrBot7 <46543473+DrBot7@users.noreply.github.com> Date: Thu, 14 Jan 2021 04:40:05 -0600 Subject: [PATCH] Timings - Calculate color from tps --- cogs/timings.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 0a81187..a8e8b54 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -18,14 +18,13 @@ class Timings(commands.Cog): def __init__(self, bot): self.bot = bot self.TIMINGS_TITLE = "Timings Analysis" - self.TIMINGS_TITLE_COLOR = 0x55ffff # Use @commands.Cog.listener() instead of event and use @commands.command() for commands async def analyze_timings(self, message): words = message.content.replace("\n", " ").split(" ") timings_url = "" - embed_var = discord.Embed(title=self.TIMINGS_TITLE, color=self.TIMINGS_TITLE_COLOR) + embed_var = discord.Embed(title=self.TIMINGS_TITLE) embed_var.set_footer(text="Requested by " + message.author.name, icon_url=message.author.avatar_url) for word in words: @@ -227,6 +226,31 @@ class Timings(commands.Cog): print("Missing: " + str(key)) unchecked = unchecked + 1 + try: + normal_ticks = request["timingsMaster"]["data"][0]["totalTicks"] + worst_tps = 20 + index = 0 + while index < len(request["timingsMaster"]["data"]): + total_ticks = request["timingsMaster"]["data"][index]["totalTicks"] + if total_ticks == normal_ticks: + end_time = request["timingsMaster"]["data"][index]["end"] + start_time = request["timingsMaster"]["data"][index]["start"] + tps = total_ticks / (end_time - start_time) + if tps < worst_tps: + worst_tps = tps + index = index + 1 + if worst_tps < 10: + red = 255 + green = int(255 * (0.1 * worst_tps)) + else: + red = int(255 * (-0.1 * worst_tps + 2)) + green = 255 + color = int(red*256*256 + green*256) + embed_var.color = color + except KeyError as key: + print("Missing: " + str(key)) + unchecked = unchecked + 1 + except ValueError as value_error: print(value_error) embed_var.add_field(name="❗ Value Error",