fixed avail and unavail
authorGeorgios Atheridis <atheridis@tutamail.com>
Thu, 12 May 2022 07:48:17 +0000 (07:48 +0000)
committerGeorgios Atheridis <atheridis@tutamail.com>
Thu, 12 May 2022 07:48:17 +0000 (07:48 +0000)
skgyorugo/commands/available.py
skgyorugo/commands/forceavailable.py
skgyorugo/commands/forceunavailable.py
skgyorugo/commands/unavailable.py
skgyorugo/database_manager.py

index 2e4a33aa22fc0195669defcd5a9a9e88fdf09ff2..8eaa8c87963846c7b94e7175f9208c16d5cae71d 100644 (file)
@@ -44,16 +44,64 @@ def main(bot: Bot, message: Message):
         UPDATE
             lol_queue
         SET
-            position = position + 1
+            position = (
+                CASE
+                    WHEN (
+                        SELECT
+                            position
+                        FROM
+                            lol_queue
+                        WHERE
+                            twitch_id = ?
+                    ) < (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+                    THEN position + 1
+                    ELSE position
+                END
+            )
         WHERE
-            position >= (
+            position > (
                 SELECT
-                    data
-                FROM 
-                    lol_queue_data
+                    max(position)
+                FROM
+                    lol_queue
                 WHERE
-                    name = 'queuesize'
-            )
+                    priority_queue = 1
+                    OR position <= (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+            );
         """
     )
 
@@ -63,14 +111,63 @@ def main(bot: Bot, message: Message):
             lol_queue
         SET 
             available = 1,
-            position = (
+            priority_queue = (
+                CASE
+                    WHEN (
+                        SELECT
+                            position
+                        FROM
+                            lol_queue
+                        WHERE
+                            twitch_id = ?
+                    ) < (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+                    THEN 1
+                    ELSE 0
+                END
+            ),
+            position = 1 + (
                 SELECT
-                    data
+                    max(position)
                 FROM
-                    lol_queue_data
+                    lol_queue
                 WHERE
-                    name = 'queuesize'
-            ),
+                    priority_queue = 1
+                    OR position <= (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+            )
             time_remaining = time_remaining - (? - last_available)
         WHERE 
             twitch_id = ?
index 6a340c861596b49c9aa0a1c0455b0212621bb2dd..092e095dc1436dce8bb9fda597624b5ef21e32da 100644 (file)
@@ -47,16 +47,64 @@ def main(bot: Bot, message: Message):
         UPDATE
             lol_queue
         SET
-            position = position + 1
+            position = (
+                CASE
+                    WHEN (
+                        SELECT
+                            position
+                        FROM
+                            lol_queue
+                        WHERE
+                            twitch_id = ?
+                    ) < (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+                    THEN position + 1
+                    ELSE position
+                END
+            )
         WHERE
-            position >= (
+            position > (
                 SELECT
-                    data
-                FROM 
-                    lol_queue_data
+                    max(position)
+                FROM
+                    lol_queue
                 WHERE
-                    name = 'queuesize'
-            )
+                    priority_queue = 1
+                    OR position <= (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+            );
         """
     )
 
@@ -66,14 +114,63 @@ def main(bot: Bot, message: Message):
             lol_queue
         SET 
             available = 1,
-            position = (
+            priority_queue = (
+                CASE
+                    WHEN (
+                        SELECT
+                            position
+                        FROM
+                            lol_queue
+                        WHERE
+                            twitch_id = ?
+                    ) < (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+                    THEN 1
+                    ELSE 0
+                END
+            ),
+            position = 1 + (
                 SELECT
-                    data
+                    max(position)
                 FROM
-                    lol_queue_data
+                    lol_queue
                 WHERE
-                    name = 'queuesize'
-            ),
+                    priority_queue = 1
+                    OR position <= (
+                        SELECT
+                            max(position)
+                        FROM
+                            lol_queue
+                        WHERE
+                            available = 1
+                        ORDER BY 
+                            position
+                        LIMIT (
+                            SELECT
+                                data
+                            FROM
+                                lol_queue_data
+                            WHERE
+                                name = 'queuesize'
+                        )
+                    )
+            )
             time_remaining = time_remaining - (? - last_available)
         WHERE 
             twitch_id = ?
index 4df29e05eed09cdfb79b8e866eeb7b4db2296fbc..1b355d1f735fbab3897d09fa11e64fea28be7e88 100644 (file)
@@ -44,7 +44,7 @@ def main(bot: Bot, message: Message):
 
     c.execute(
         """
-        UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?;
+        UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?;
         """,
         (
             int(time.time()),
index c95b59c9120e566034069cce47a55a85113f226f..9a2fb158b0755e47b31cf77b5c6544b3108c5ee2 100644 (file)
@@ -41,7 +41,7 @@ def main(bot: Bot, message: Message):
 
     c.execute(
         """
-        UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?;
+        UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?;
         """,
         (
             int(time.time()),
index 718c2743d7221ad87e2ae6194d8ab2fa0898b755..7f079bf13da0be8fba1ac8c41e34195b3d1fb022 100644 (file)
@@ -99,6 +99,7 @@ def create_lol_database():
             last_available INTEGER,
             time_remaining INTEGER NOT NULL,
             team INTEGER,
+            priority_queue INTEGER,
             PRIMARY KEY (twitch_id)
         );
         """