Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    I don't recommend running this from IDLE or the interactive shell because unless you are careful the name space will be polluted from previous tests and cause false positives. Put it in a script and run it as
    python myscript.py
    sort of thing.

    BTW , there is no NULL in Python except as possiblely chr(0) but we do have a None which designates an object with no personality (I mean it has no value or methods or type).

    grim
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    FL
    Posts
    19
    Rep Power
    0
    Aye, that's why I was using None. I ran that test script on a fresh startup of pyalamode's shell, so the namespace was default (minus an import of re of course).

    also, you're right. the log doesn't start out with 'You start fighting' . I don't have access to my webspace but here's a snip for the beginning of the log:
    Code:
    (1095323546)[Thu Sep 16 01:32:26 2004] Elipha begins to cast an augmentation spell.
    (1095323548)[Thu Sep 16 01:32:28 2004] An augmentation spell is cast on you.
    (1095323550)[Thu Sep 16 01:32:30 2004] A ghostly orc is struck with a holy weapon!
    (1095323563)[Thu Sep 16 01:32:43 2004] Elipha begins to cast an incapacitation spell.
    (1095323567)[Thu Sep 16 01:32:47 2004] An incapacitation spell is cast on A ghostly orc.
    (1095323574)[Thu Sep 16 01:32:54 2004] a ghostly orc tries to crush Elipha, but Elipha ripostes.
    (1095323574)[Thu Sep 16 01:32:54 2004] Elipha hits a ghostly orc for 13 points of crushing damage.
    (1095323574)[Thu Sep 16 01:32:54 2004] You start fighting.
    (1095323574)[Thu Sep 16 01:32:54 2004] Your target is too far! Move closer!
    (1095323575)[Thu Sep 16 01:32:55 2004] Elipha hits a ghostly orc for 6 points of crushing damage.
    (1095323575)[Thu Sep 16 01:32:55 2004] YOU hit a ghostly orc for 8 points of slashing damage.
    (1095323576)[Thu Sep 16 01:32:56 2004] a ghostly orc tries to crush Elipha, but misses.
    (1095323577)[Thu Sep 16 01:32:57 2004] Elipha hits a ghostly orc for 9 points of crushing damage.
    (1095323577)[Thu Sep 16 01:32:57 2004] YOUR Kick hits a ghostly orc for 12 points of crushing damage.
    (1095323577)[Thu Sep 16 01:32:57 2004] YOU hit a ghostly orc for 8 points of slashing damage.
    (1095323578)[Thu Sep 16 01:32:58 2004] Elipha begins to cast a damage spell.
    (1095323579)[Thu Sep 16 01:32:59 2004] a ghostly orc tries to crush Elipha, but Elipha parries.
    (1095323580)[Thu Sep 16 01:33:00 2004] Elipha's Lightning Burst hits a ghostly orc for 34 points of magic damage.
    (1095323580)[Thu Sep 16 01:33:00 2004] A damage spell is cast on A ghostly orc.
    (1095323580)[Thu Sep 16 01:33:00 2004] YOUR Wild Swing hits a ghostly orc for 6 points of slashing damage.
    (1095323580)[Thu Sep 16 01:33:00 2004] Elipha tries to crush a ghostly orc, but misses.
    (1095323581)[Thu Sep 16 01:33:01 2004] YOU try to slash a ghostly orc, but miss.
    (1095323581)[Thu Sep 16 01:33:01 2004] Elipha begins to cast an incapacitation spell.
    (1095323582)[Thu Sep 16 01:33:02 2004] a ghostly orc tries to crush Elipha, but misses.
    (1095323583)[Thu Sep 16 01:33:03 2004] YOU hit a ghostly orc for 7 points of slashing damage.
    (1095323583)[Thu Sep 16 01:33:03 2004] a ghostly orc's Kick hits YOU for 22 points of crushing damage.
    (1095323584)[Thu Sep 16 01:33:04 2004] a ghostly orc tries to crush YOU, but misses.
    (1095323584)[Thu Sep 16 01:33:04 2004] Elipha begins to cast a damage spell.
    (1095323586)[Thu Sep 16 01:33:06 2004] YOUR Assault hits a ghostly orc for 10 points of slashing damage.
    (1095323586)[Thu Sep 16 01:33:06 2004] YOU try to slash a ghostly orc, but miss.
    (1095323586)[Thu Sep 16 01:33:06 2004] Elipha's Blaze hits a ghostly orc for 53 points of heat damage.
    (1095323586)[Thu Sep 16 01:33:06 2004] A damage spell is cast on A ghostly orc.
    (1095323587)[Thu Sep 16 01:33:07 2004] a ghostly orc hits YOU for 11 points of crushing damage.
    (1095323588)[Thu Sep 16 01:33:08 2004] Elipha begins to cast a damage spell.
    (1095323588)[Thu Sep 16 01:33:08 2004] YOU hit a ghostly orc for 7 points of slashing damage.
    (1095323589)[Thu Sep 16 01:33:09 2004] a ghostly orc hits YOU for 14 points of crushing damage.
    (1095323590)[Thu Sep 16 01:33:10 2004] Elipha's Lightning Burst hits a ghostly orc for 35 points of magic damage.
    (1095323590)[Thu Sep 16 01:33:10 2004] Elipha has killed a ghostly orc.
    (1095323590)[Thu Sep 16 01:33:10 2004] You stop fighting.
    (1095323590)[Thu Sep 16 01:33:10 2004] You gain experience!
  4. #18
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Have a go at updating your code and posting it here if you get stuck. (and a log file helps)

    Did you get any "failed with log line" messages before getting some printed re match objects?

    grim;
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    FL
    Posts
    19
    Rep Power
    0
    this is how the StormNetParseEng class looks like now:
    Code:
    class StormNetParseEng:
        """contains methods to parse dps for Everquest2 log files"""
    
        def convertTS(self,ts1,ts2):
    	"""takes 2 time stamps and finds the difference in seconds"""
    	# convert t1,t2 to integers
    	h1,m1,s1 = (int(ts1.group(1)), int(ts1.group(2)), int(ts1.group(3)))
    	h2,m2,s2 = (int(ts2.group(1)), int(ts2.group(2)), int(ts2.group(3)))
    
    	scnt1 = h1 * (60**2) + m1*60 + s1
    	scnt2 = h2 * (60**2) + m2*60 + s2
    
    	# check if the fight went past midnight
    	if scnt1 > scnt2:
           		scnt1 = h1 * (24 * (60**2)) + m1*60 + s1
        
    	ftime = scnt2 - scnt1
    	return float(ftime)
    
    
        def parseng(self,arg):
    	"""Does most of the dirty work.
    	Takes log as a list.
    
    	returns a fight data"""
    	
    	import re
    	
    	log = arg
    	initv = (0, 0, 0, 0, 0, 0, 0.0)
    	missCnt, fdmg, primary, secondary, scndDmg, primDmg, dps = initv
    	fightCnt, endCnt = 0,0
    
    	flist = []
    	for i in log:
    		stTime = None
    		endTime = None
    	        if 'You start fighting' in i:
    			stTime = re.match('^.*(\d{2}):(\d{2}):(\d{2})',i)
            		fightCnt += 1
    
    	        dmgPrm = re.match('^.*(YOU).*(hit).*(\d+)',i)   # primary dmg (auto attack hits)
            	dmgScnd = re.match('^.*(YOUR).*(hits).*(\d+)',i)# secondary dmg (special moves)
    	        miss = re.match('^.*(YOU?).*(miss.*)',i)
    
            	if dmgPrm:
    	            fdmg += int(dmgPrm.group(3))
            	    primary += 1
    	            primDmg += int(dmgPrm.group(3))
    
            	if dmgScnd:
    	            fdmg += int(dmgScnd.group(3))
            	    secondary += 1
    	            scndDmg += int(dmgScnd.group(3))
    
            	if miss:
    	            missCnt += 1
    
            	if 'You stop fighting' in i:
    	            endTime = re.match('^.*(\d{2}):(\d{2}):(\d{2})',i)
            	    endCnt += 1
    
    	        # test for incomplete fights. incomplete fights are not added to list
            	"""
    		if endCnt < fightCnt:
    	            fightCnt -= 1
            	elif endCnt > fightCnt:
    	            fightCnt -= 1
    	        elif endCnt == fightCnt:
            	"""   
    			# calculate dps
    	        dps = fdmg / self.convertTS(stTime,endTime)
    
            	    # store values
    	        fData = {'damage':fdmg,'prm':primary,'scn':secondary,'misscnt':missCnt,\
    		'dps':dps,'pdmg':primDmg,'sdmg':scndDmg}
            	flist.append(fdata)
    
    	            # prepare values for next cycle
            	missCnt, fdmg, primary, secondary, scndDmg, primDmg, dps, = initv
    
    
    	return flist
  8. #20
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    You should initialise stime and endtime before the loop starts:
    Code:
        flist = []
        stTime = None
        endTime = None
        for i in log: 
                if 'You start fighting' in i: 
                stTime = re.match('^.*(\d{2}):(\d{2}):(\d{2})', i)
                    fightCnt += 1
    And you say you only want to do calcs when both times have been detected so why not test if they are set before doing anything:
    Code:
            if stime and endTime: 
                # calculate dps
                dps = fdmg/self.convertTS(stTime, endTime)
    
                # store values
                fData = {'damage': fdmg, 'prm': primary, 'scn': secondary, 'misscnt': missCnt,  \
    
    
                'dps': dps, 'pdmg': primDmg, 'sdmg': scndDmg}
                flist.append(fdata)
    
                # prepare values for next cycle
                missCnt, fdmg, primary, secondary, scndDmg, primDmg, dps,  = initv
                #reset times back to None
                stime = endTime = None
    The last line is important: resetting times back to None again after doing the calcs and before the for loop continues.

    I'm sure you have your own techniques but this is the sort of problem where I find pencil and paper (Either that or a good interactive debugger) are useful. As boring as it is can be; manually working through the code, writting down the state of each variable as you go into and around the for loop will help identify any remaining bugs. And the liberal use of print statements to show whats going on helps too!

    I haven't tested this but you should be able to work it out from these suggestions. Have fun

    grim
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    FL
    Posts
    19
    Rep Power
    0
    Thanks again for all the help. I'll hack at it and should get it running.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo