Please find both attached and on the branch table-picker-bug-13789 @
FIXME a fix for https://gna.org/bugs/?13789 .  This patch applies
directly to trunk as of r5976.

I plan to merge it into trunk tonight, pending dachary's review.

Here is the commit log I expect to use:

TablePicker() returns fullest table w/ seat that matches given criteria,
which closed bug#13789.

This was implemented by simply adding an ORDER BY on listTables() query
to force the tables with the most players to be seen first by the
selection function, getTableBestByCriteria() which already returns when
it finds the first table that isn't full and the player has enough money
to buy in for.

This patch is copyrighted by me and licensed AGPLv3-or-later. 


Added ORDER BY on listTables() so that the tables with the most players
are highest in the list.  The existing code does the rest.

diff --git a/poker-network/ChangeLog b/poker-network/ChangeLog
index 4418770..d0b1ada 100644
--- a/poker-network/ChangeLog
+++ b/poker-network/ChangeLog
@@ -1,3 +1,14 @@
+2009-06-28  Bradley M. Kuhn  <[email protected]>
+
+	* pokernetwork/pokerservice.py (PokerService.listTables): Added
+	ORDER BY players desc, serial
+
+	* tests/test-pokeravatar.py.in
+	(PokerAvatarTablePickerTestCase.test04_tablePicker_twoPossibleGivesMostEmpty):
+	Renamed test and enabled.
+	(PokerAvatarTablePickerTestCase.test12_tablePicker_twoPossibleGivesMostFullWithSeatsButNotFullOne):
+	Wrote test.
+
 2009-06-27  Bradley M. Kuhn  <[email protected]>
 
 	* pokernetwork/pokeravatar.py
diff --git a/poker-network/pokernetwork/pokerservice.py b/poker-network/pokernetwork/pokerservice.py
index d95b783..a1116cd 100644
--- a/poker-network/pokernetwork/pokerservice.py
+++ b/poker-network/pokernetwork/pokerservice.py
@@ -1495,6 +1495,11 @@ class PokerService(service.Service):
                   sent in equal to 0, no error will be generated, but it
                   will be as if you didn't send them at all).
 
+                  Finally, the query is sorted such that tables with the
+                  most players are at the top of the list.  Note that
+                  other methods rely on this, so don't change it.  The
+                  secondary sorting key is the ascending table serial.
+
            One final note: sneakily, this method sets an internal variable
            which is left around for use by self.getTableBestByCriteria().
            self.getTableBestByCriteria() clears it before and after its
@@ -1512,14 +1517,15 @@ class PokerService(service.Service):
         # whether it was better not to expand this method, but I felt it
         # was close enough that it was.  Our discussion happened on IRC
         # circa 2009-06-20 and following. -- bkuhn, 2009-06-20
+        orderBy = " ORDER BY players desc, serial"
         criteria = split(string, "\t")
         cursor = self.db.cursor(DictCursor)
         if string == '' or string == 'all':
-            cursor.execute("SELECT * FROM pokertables")
+            cursor.execute("SELECT * FROM pokertables" + orderBy)
         elif string == 'my':
-            cursor.execute("SELECT pokertables.* FROM pokertables,user2table WHERE pokertables.serial = user2table.table_serial AND user2table.user_serial = %s", serial)
+            cursor.execute("SELECT pokertables.* FROM pokertables,user2table WHERE pokertables.serial = user2table.table_serial AND user2table.user_serial = %s%s", serial, orderBy)
         elif re.match("^[0-9]+$", string):
-            cursor.execute("SELECT * FROM pokertables WHERE currency_serial = %s", string)
+            cursor.execute("SELECT * FROM pokertables WHERE currency_serial = %s%s", string, orderBy)
         elif len(criteria) > 1:
             # Next, unpack the various possibilities in the tab-separated
             # criteria, starting with everything set to None.  This helps
@@ -1581,7 +1587,7 @@ class PokerService(service.Service):
                 else:
                     sql += kk + " = " + "%s"
                 sqlQuestionMarkParameterList.append(vv)
-            sql += " order by serial"
+            sql += orderBy
             cursor.execute(sql, sqlQuestionMarkParameterList)
         else:
             cursor.execute("SELECT * FROM pokertables WHERE name = %s", string)
@@ -2397,7 +2403,6 @@ class PokerService(service.Service):
         self._listTables_min_players_cached = 0
         for rr in self.listTables(list_table_query_str, serial):
             table = self.getTable(rr['serial'])
-
             # Skip considering table entirely if it is full.
             if table.game.full():
                 continue
diff --git a/poker-network/tests/test-pokeravatar.py.in b/poker-network/tests/test-pokeravatar.py.in
index f2f12ab..b8808ef 100644
--- a/poker-network/tests/test-pokeravatar.py.in
+++ b/poker-network/tests/test-pokeravatar.py.in
@@ -4300,17 +4300,15 @@ class PokerAvatarTablePickerTestCase(PokerAvatarTestCaseBaseClass):
         playersDeferreds.append(pickerDeferred)
         return defer.DeferredList(playersDeferreds)
     # ------------------------------------------------------------------------
-    # NOTE: Test below not operational.  Proposed for a later improvement.
-    def test04_tablePicker_twoPossibleGivesMostEmpty(self):
-        return True
+    def test04_tablePicker_twoPossibleGivesMostFullWithSeats(self):
         self.createClients(8)
 
         playersDeferreds = []
-        for ii in [ 0, 1, 2, 3 ]:
+        for ii in [ 0, 1, 2 ]:
             playersDeferreds.append(
                 self.startPlayerSeatedAndPlaying(ii, 1, "NL HE 10-max 100/200",
                                                  "100-200-no-limit", "holdem", 10, 1))
-        for ii in [ 4, 5, 6 ]:
+        for ii in [ 3, 4, 5, 6 ]:
             playersDeferreds.append(
                 self.startPlayerSeatedAndPlaying(ii, 2, "NL HE 6-max 100/200",
                                                  "100-200-no-limit", "holdem", 6, 1))
@@ -4318,7 +4316,7 @@ class PokerAvatarTablePickerTestCase(PokerAvatarTestCaseBaseClass):
         pickerDeferred = self.preparePlayerForTablePickerSend(7)
         pickerDeferred.addCallback(self.setMoneyForPlayer, 7, 1, "over_best", 1)
         pickerDeferred.addCallback(self.tablePickerSucceeds, 7, 3, 0,
-                                    "holdem", "100-200-no-limit", 1, "NL HE 6-max 100/200")
+                                    "holdem", "100-200-no-limit", 2, "NL HE 6-max 100/200")
         playersDeferreds.append(pickerDeferred)
         return defer.DeferredList(playersDeferreds)
     # ------------------------------------------------------------------------
@@ -4446,6 +4444,31 @@ class PokerAvatarTablePickerTestCase(PokerAvatarTestCaseBaseClass):
         pickerDeferred.addCallback(self.restoreTableCanAddPlayer, 5)
         playersDeferreds.append(pickerDeferred)
         return defer.DeferredList(playersDeferreds)
+    # ------------------------------------------------------------------------
+    def test12_tablePicker_twoPossibleGivesMostFullWithSeatsButNotFullOne(self):
+        self.createClients(18)
+
+        playersDeferreds = []
+        for ii in [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]:
+            playersDeferreds.append(
+                self.startPlayerSeatedAndPlaying(ii, 1, "NL HE 10-max 100/200",
+                                                 "100-200-no-limit", "holdem", 10, 1))
+        for ii in [ 10, 11, 12 ]:
+            playersDeferreds.append(
+                self.startPlayerSeatedAndPlaying(ii, 2, "NL HE 6-max 100/200",
+                                                 "100-200-no-limit", "holdem", 6, 1))
+        for ii in [ 13, 14, 15, 16 ]:
+            playersDeferreds.append(
+                self.startPlayerSeatedAndPlaying(ii, 5, "Stud 8-max 2/4",
+                                             "2-4-limit", "7stud", 8, 2))
+
+        pickerDeferred = self.preparePlayerForTablePickerSend(17)
+        pickerDeferred.addCallback(self.setMoneyForPlayer, 17, 1, "over_best", 1)
+        pickerDeferred.addCallback(self.setMoneyForPlayer, 17, 2, "over_best", 5)
+        pickerDeferred.addCallback(self.tablePickerSucceeds, 17, 0, 0,
+                                    "", "", 5, "Stud 8-max 2/4")
+        playersDeferreds.append(pickerDeferred)
+        return defer.DeferredList(playersDeferreds)
 # -----------------------------------------------------------------------------
 class ConvertTablePickerArgsToListTablesQueryStringUnitTestCase(unittest.TestCase):
     """This coverage class exists to cover on specific method in avatar,
 
-- 

   -- bkuhn
_______________________________________________
Pokersource-users mailing list
[email protected]
https://mail.gna.org/listinfo/pokersource-users

Reply via email to