Minor optimizations and some fixes to the dummyrunner.

This commit is contained in:
Griatch 2012-08-22 22:34:43 +02:00
parent 5117bd2a0a
commit f68523cc22
3 changed files with 57 additions and 40 deletions

View file

@ -884,9 +884,7 @@ class TypedObject(SharedMemoryModel):
# (we make sure to not incur a loop by not triggering the
# typeclass' __getattribute__, since that one would
# try to look back to this very database object.)
typeclass = _GA(self, 'typeclass')
# will raise AttributeError also if typeclass was malformed
return _GA(typeclass, propname)
return _GA(_GA(self, 'typeclass'), propname)
#@property
_dbid_cache = None

View file

@ -49,6 +49,9 @@ from django.conf import settings
from src.utils import utils
HELPTEXT = """
Usage: dummyrunner.py [-h][-v][-V] [nclients]
DO NOT RUN THIS ON A PRODUCTION SERVER! USE A CLEAN/TESTING DATABASE!
This stand-alone program launches dummy telnet clients against a
@ -144,6 +147,9 @@ class DummyClient(telnet.StatefulTelnetProtocol):
self.exits = [] # exit names created
self.objs = [] # obj names created
self._report = ""
self._cmdlist = [] # already stepping in a cmd definition
self._ncmds = 0
self._actions = self.factory.actions
self._echo_brief = self.factory.verbose == 1
self._echo_all = self.factory.verbose == 2
@ -186,23 +192,28 @@ class DummyClient(telnet.StatefulTelnetProtocol):
"""
if random.random() > CHANCE_OF_ACTION:
return
if self.istep == 0:
cfunc = self._actions[0]
else: # random selection using cumulative probabilities
rand = random.random()
cfunc = [func for cprob, func in self._actions[2] if cprob >= rand][0]
# launch the action (don't hide tracebacks)
cmd, report = cfunc(self)
# handle the result
cmd = "\n".join(makeiter(cmd))
if self.istep == 0 or self._echo_brief or self._echo_all:
print "client %i %s" % (self.cid, report)
self.sendLine(cmd)
if not self._cmdlist:
# no cmdlist in store, get a new one
if self.istep == 0:
cfunc = self._actions[0]
else: # random selection using cumulative probabilities
rand = random.random()
cfunc = [func for cprob, func in self._actions[2] if cprob >= rand][0]
# assign to internal cmdlist
cmd, self._report = cfunc(self)
self._cmdlist = list(makeiter(cmd))
self._ncmds = len(self._cmdlist)
# output
if self.istep == 0 and not (self._echo_brief or self._echo_all):
print "client %i %s" % (self.cid, self._report)
elif self.istep == 0 or self._echo_brief or self._echo_all:
print "client %i %s (%i/%i)" % (self.cid, self._report, self._ncmds-(len(self._cmdlist)-1), self._ncmds)
# launch the action by popping the first element from cmdlist (don't hide tracebacks)
self.sendLine(str(self._cmdlist.pop(0)))
self.istep += 1 # only steps up if an action is taken
class DummyFactory(protocol.ClientFactory):
protocol = DummyClient
def __init__(self, actions, timestep, verbose):
"Setup the factory base (shared by all clients)"
self.actions = actions

View file

@ -59,12 +59,20 @@ TOBJ_TYPECLASS = "examples.red_button.RedButton"
def c_login(client):
"logins to the game"
cname = "Dummy-%s-%i" % (RUNID, client.cid)
cemail = "%s@dummy.com" % (cname.lower())
#cemail = "%s@dummy.com" % (cname.lower())
cpwd = "%s-%s" % (RUNID, client.cid)
cmd = ('create "%s" %s %s' % (cname, cemail, cpwd),
'connect %s %s' % (cemail, cpwd),
# set up for digging a first room (to move to)
roomname = ROOM_TEMPLATE % client.counter()
exitname1 = EXIT_TEMPLATE % client.counter()
exitname2 = EXIT_TEMPLATE % client.counter()
client.exits.extend([exitname1, exitname2])
cmd = '@dig %s = %s, %s' % (roomname, exitname1, exitname2)
cmd = ('create %s %s' % (cname, cpwd),
'connect %s %s' % (cname, cpwd),
'@dig %s' % START_ROOM % client.cid,
'@teleport %s' % START_ROOM % client.cid)
'@teleport %s' % START_ROOM % client.cid,
'@dig %s = %s, %s' % (roomname, exitname1, exitname2)
)
return cmd, "logs in as %s ..." % cname
@ -143,16 +151,16 @@ def c_moves(client):
# otherwise the system will normalize them.
#
# heavy builder definition
#ACTIONS = ( c_login,
# c_logout,
# (0.2, c_looks),
# (0.1, c_examines),
# (0.2, c_help),
# (0.1, c_digs),
# (0.1, c_creates_obj),
# #(0.1, c_creates_button),
# (0.2, c_moves))
# "heavy" builder definition
ACTIONS = ( c_login,
c_logout,
(0.2, c_looks),
(0.1, c_examines),
(0.2, c_help),
(0.1, c_digs),
(0.1, c_creates_obj),
#(0.01, c_creates_button),
(0.2, c_moves))
# "normal builder" definition
#ACTIONS = ( c_login,
# c_logout,
@ -163,14 +171,14 @@ def c_moves(client):
# (0.01, c_creates_obj),
# #(0.1, c_creates_button),
# (0.3, c_moves))
# "normal player" definition
ACTIONS = ( c_login,
c_logout,
(0.7, c_looks),
#(0.1, c_examines),
(0.3, c_help))
#(0.1, c_digs),
#(0.1, c_creates_obj),
#(0.1, c_creates_button),
#(0.4, c_moves))
# "passive player" definition
#ACTIONS = ( c_login,
# c_logout,
# (0.7, c_looks),
# #(0.1, c_examines),
# (0.3, c_help))
# #(0.1, c_digs),
# #(0.1, c_creates_obj),
# #(0.1, c_creates_button),
# #(0.4, c_moves))