-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Following dachary guidance,

I added currency_serial_from_date_format field to tourney_schedule
table, with the attached pokerservice modifications.

By setting it to '%Y%m' (NULL and ignored by default), one can achieve
monthly rotation of currency_serial of a scheduled recurring tournament.

For example:
200810
200811
200810

Feel free to review the attached patch before I commit it to trunk.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkmnXkACgkQZmEdV9SHoe71HgCghnrQhBZYjCDKsf3iW5SbTT7k
ibYAn3xIVnZqZt6zuasqjGeXF+pHoIRy
=U8y5
-----END PGP SIGNATURE-----
Index: pokernetwork/pokerservice.py
===================================================================
--- pokernetwork/pokerservice.py        (revision 4962)
+++ pokernetwork/pokerservice.py        (working copy)
@@ -98,6 +98,7 @@
 from pokernetwork.userstats import UserStatsFactory
 from pokernetwork.tourneyattrs import TourneyAttrsFactory
 from pokerauth import get_auth_instance
+from datetime import date
 
 UPDATE_TOURNEYS_SCHEDULE_DELAY = 10 * 60
 CHECK_TOURNEYS_SCHEDULE_DELAY = 60
@@ -575,7 +576,14 @@
         self.cancelTimer('checkTourney')
         self.timer['checkTourney'] = 
reactor.callLater(CHECK_TOURNEYS_SCHEDULE_DELAY, self.checkTourneysSchedule)
 
+    def today(self):
+        return date.today()
+
     def spawnTourney(self, schedule):
+        currency_serial = schedule['currency_serial']
+        currency_serial_from_date_format = 
schedule['currency_serial_from_date_format']
+        if currency_serial_from_date_format:
+            currency_serial = 
long(self.today().strftime(currency_serial_from_date_format))
         cursor = self.db.cursor()
         cursor.execute("INSERT INTO tourneys "
                        " (resthost_serial, schedule_serial, name, 
description_short, description_long, players_quota, players_min, variant, 
betting_structure, seats_per_game, player_timeout, currency_serial, prize_min, 
bailor_serial, buy_in, rake, sit_n_go, breaks_first, breaks_interval, 
breaks_duration, rebuy_delay, add_on, add_on_delay, start_time)"
@@ -592,7 +600,7 @@
                          schedule['betting_structure'],
                          schedule['seats_per_game'],
                          schedule['player_timeout'],
-                         schedule['currency_serial'],
+                         currency_serial,
                          schedule['prize_min'],
                          schedule['bailor_serial'],
                          schedule['buy_in'],
@@ -618,16 +626,16 @@
             cursor.execute("UPDATE tourneys_schedule SET active = 'n' WHERE 
serial = %s" % schedule['serial'])
         cursor.execute("REPLACE INTO route VALUES (0,%s,%s,%s)", ( 
tourney_serial, int(seconds()), self.resthost_serial))
         cursor.close()
-        self.spawnTourneyInCore(schedule, tourney_serial, schedule['serial'])
+        self.spawnTourneyInCore(schedule, tourney_serial, schedule['serial'], 
currency_serial)
 
-    def spawnTourneyInCore(self, tourney_map, tourney_serial, schedule_serial):
+    def spawnTourneyInCore(self, tourney_map, tourney_serial, schedule_serial, 
currency_serial):
         tourney_map['start_time'] = int(tourney_map['start_time'])
         tourney_map['register_time'] = int(tourney_map.get('register_time', 0))
         tourney = PokerTournament(dirs = self.dirs, **tourney_map)
         tourney.serial = tourney_serial
         tourney.verbose = self.verbose
         tourney.schedule_serial = schedule_serial
-        tourney.currency_serial = tourney_map['currency_serial']
+        tourney.currency_serial = currency_serial
         tourney.bailor_serial = tourney_map['bailor_serial']
         tourney.player_timeout = int(tourney_map['player_timeout'])
         tourney.callback_new_state = self.tourneyNewState
@@ -1417,7 +1425,7 @@
         for x in xrange(cursor.rowcount):
             row = cursor.fetchone()
             if self.verbose >= 0: message = "cleanupTourneys: restoring %s(%s) 
with players" % ( row['name'], row['serial'],  )
-            tourney = self.spawnTourneyInCore(row, row['serial'], 
row['schedule_serial'])
+            tourney = self.spawnTourneyInCore(row, row['serial'], 
row['schedule_serial'], row['currency_serial'])
             cursor1 = self.db.cursor()
             sql = "SELECT user_serial FROM user2tourney WHERE tourney_serial = 
" + str(row['serial'])
             if self.verbose > 2:
Index: tests/test-pokerservice.py.in
===================================================================
--- tests/test-pokerservice.py.in       (revision 4962)
+++ tests/test-pokerservice.py.in       (working copy)
@@ -39,6 +39,7 @@
 import sets
 from _mysql_exceptions import IntegrityError
 from pprint import pprint
+from datetime import date
 
 from tests import testclock
 
@@ -1174,6 +1175,30 @@
             self.assertEquals(self.service.joinedCountReachedMax(),
                               val >= expectedMax)
         self.service.stopService()
+    # ----------------------------------------------------------------
+    def test20_spawnTourneyCurrencySerialFromDateFormat(self):
+        cursor = self.db.cursor()
+        currency_serial_from_date_format = '%Y%m'
+        cursor.execute("UPDATE tourneys_schedule SET 
currency_serial_from_date_format = '%s' WHERE name = 'sitngo2'" % 
currency_serial_from_date_format)
+        self.assertEqual(1, cursor.rowcount)
+        cursor.close()
+        self.service.today = lambda: date(1970, 01, 01)
+        currency_serial_from_date = 197001L
+        self.service.startService()
+        tourney_serial, schedule = self.service.tourneys_schedule.items()[0]
+        self.assertEqual(currency_serial_from_date_format, 
schedule["currency_serial_from_date_format"])
+        cursor = self.db.cursor()
+        cursor.execute("SELECT currency_serial from tourneys WHERE name = 
'%s'" % 'sitngo2')
+        self.assertEqual(1, cursor.rowcount)
+        currency_serial = cursor.fetchone()[0]
+        cursor.close()
+        self.assertEqual(currency_serial_from_date, currency_serial)
+        tourney = self.service.tourneys[tourney_serial]
+        self.assertEqual(False, hasattr(tourney, 
currency_serial_from_date_format))
+        self.assertEqual(currency_serial_from_date, tourney.currency_serial)
+    # ----------------------------------------------------------------
+    def test21_today(self):
+        self.assertEqual(self.service.today(), date.today())
 
 class RefillTestCase(unittest.TestCase):
 
Index: database/1.6.0-1.7.0.sql
===================================================================
--- database/1.6.0-1.7.0.sql    (revision 4962)
+++ database/1.6.0-1.7.0.sql    (working copy)
@@ -24,6 +24,7 @@
 --
 ALTER TABLE `tourneys` ADD COLUMN resthost_serial INT UNSIGNED DEFAULT 0 NOT 
NULL;
 ALTER TABLE `tourneys_schedule` ADD COLUMN resthost_serial INT UNSIGNED 
DEFAULT 0 NOT NULL;
+ALTER TABLE `tourneys_schedule` ADD COLUMN currency_serial_from_date_format 
VARCHAR(16) DEFAULT NULL;
 --
 -- Tournament rank is used for tourneySelect
 --
Index: database/schema.sql.in
===================================================================
--- database/schema.sql.in      (revision 4962)
+++ database/schema.sql.in      (working copy)
@@ -286,6 +286,8 @@
   respawn CHAR DEFAULT 'n',
   -- Unused.
   respawn_interval INT DEFAULT 0,
+  -- Format string to override currency serial from date.
+  currency_serial_from_date_format VARCHAR(16) DEFAULT NULL,
 
   PRIMARY KEY (serial),
   KEY tourneys_schedule_active_index (active),
_______________________________________________
Pokersource-users mailing list
[email protected]
https://mail.gna.org/listinfo/pokersource-users

Reply via email to