Exemple #1
0
 def OnTimer(self, id):
     ageSDL = PtGetAgeSDL()
     if (id == 1):
         if (ageSDL[sdlCanQuake.value][0] == 0):
             print 'dsntQuake.OnTimer: A quake would happen, but Esher is speaking.'
             self.NextQuakeDelay()
         else:
             self.QuakeStart()
     elif (id == 2):
         peakStrength = whrandom.uniform(peakStrengthMin, peakStrengthMax)
         print 'OnTimer: The quake peak of ',
         print peakStrength,
         print ' starts.'
         rampUpTarget = peakStrength
         self.RampUp()
         respPeakStart.run(self.key)
     elif (id == 3):
         baseStrength = whrandom.uniform(baseStrengthMin, baseStrengthMax)
         print 'OnTimer: The quake peak ends. Ramping down to a base of ',
         print baseStrength
         rampDownTarget = baseStrength
         self.RampDown()
         respPeakStop.run(self.key)
     elif (id == 4):
         self.QuakeStop()
     elif (id == 5):
         self.RampUp()
     elif (id == 6):
         self.RampDown()
Exemple #2
0
def random (m, n=None):
  """
    returns an uniformly generated integer in [m,n)
    or in [0,m) if n is not supplied.
  """
  if not n:
    return int(uniform (0, m))
  else:
    return int(uniform (m, n))
Exemple #3
0
 def QuakeStart(self):
     global quaking
     global rampUpTarget
     quaking = true
     baseStrength = whrandom.uniform(baseStrengthMin, baseStrengthMax)
     print '##'
     print 'dsntQuake: The quake starts with a base strength of ',
     print baseStrength
     rampUpTarget = baseStrength
     #self.RampUp()
     prob = whrandom.uniform(0, 1)
     if (prob < peakProb):
         peakDelay = whrandom.uniform(peakDelayMin, peakDelayMax)
         print '\tA Peak will occur ',
         print peakDelay,
         print ' seconds later.'
         PtAtTimeCallback(self.key, peakDelay, 2)
         peakDuration = whrandom.uniform(peakDurationMin, peakDurationMax)
         print '\tThe peak will last for ',
         print peakDuration,
         print ' seconds.'
         PtAtTimeCallback(self.key, (peakDelay + peakDuration), 3)
         Duration = ((whrandom.uniform(minDuration, maxDuration) + peakDelay) + peakDuration)
     else:
         print '\tA Peak will NOT occur.'
         Duration = whrandom.uniform(minDuration, maxDuration)
     print '\tThe quake will last for ',
     print Duration,
     print ' seconds.'
     PtAtTimeCallback(self.key, Duration, 4)
     respBaseStart.run(self.key)
Exemple #4
0
def loadinc(name, mb, f, printstat=0, max=99999999, wait=1):
    from ZODB.POSException import ConflictError
    from time import sleep
    from whrandom import uniform
    import Zope, sys
    rconflicts=wconflicts=0

    i=0
    message=mb.next()
    body=message.fp.read()
    headers=list(message.headers)
    while i < max:
        # sys.stderr.write("%s " % i)
        # sys.stdout.flush()
        if wait: sleep(uniform(0,wait))
        jar=Zope.DB.open()
        app=jar.root()['Application']
        mdest=getattr(app, name)
        if i%100 == 0 and printstat:
            sys.stdout.write("\t%s\t%s\t\r" % (i, f.tell()))
            sys.stdout.flush()

        did=str(i)
        try:
            loadmessage(mdest, message, did, body, headers)
            doc=mdest[did]
            app.cat.catalog_object(doc)
        except ConflictError, v:
            # print v.args
            rconflicts=rconflicts+1
            get_transaction().abort()
        else:
            try:
                get_transaction().commit()
                i=i+1
                message=mb.next()
                body=message.fp.read()
                headers=list(message.headers)
            except ConflictError:
                wconflicts=wconflicts+1
                get_transaction().abort()

        doc=app=mdest=0
        jar.close()
Exemple #5
0
def incedit(edits, wait, ndel=20, nins=20):
    import Zope, whrandom, string, time
    from ZODB.POSException import ConflictError

    rconflicts=wconflicts=0
    did=str(edits.pop())
    while edits:
        if wait: time.sleep(whrandom.uniform(0,wait))
        jar=Zope.DB.open()
        app=jar.root()['Application']
        doc=getattr(app.mail, did)

        text=string.split(doc.raw)

        n=whrandom.randint(0,ndel*2)
        for j in range(n):
            if len(text) < 2: break
            j=whrandom.randint(0,len(text)-1)
            #del text[j]

        n=whrandom.randint(0,nins*2)
        for j in range(n):
            word=whrandom.choice(words)
            text.append(word)

        doc.raw=string.join(text)

        try: app.cat.catalog_object(doc)
        except ConflictError, v:
            #print v.args
            rconflicts=rconflicts+1
            get_transaction().abort()
        else:
            try:
                get_transaction().commit()
                did=str(edits.pop())
            except ConflictError:
                wconflicts=wconflicts+1
                get_transaction().abort()

        doc=app=0
        jar.close()
Exemple #6
0
import whrandom

# same as random
print(whrandom.random())
print(whrandom.choice([1, 2, 3, 5, 9]))
print(whrandom.uniform(10, 20))
print(whrandom.randint(100, 1000))

## 0.113412062346
## 1
## 16.8778954689
## 799
Exemple #7
0
import whrandom

# same as random
print whrandom.random()
print whrandom.choice([1, 2, 3, 5, 9])
print whrandom.uniform(10, 20)
print whrandom.randint(100, 1000)

## 0.113412062346
## 1
## 16.8778954689
## 799