Esempio n. 1
0
def getRaces(folder, season, week, verbose):

    fileName = "%s/Season %d Week %d.txt" % (folder, season, week)
    if os.path.exists(fileName):
        print "%s already exists, exiting" % fileName
        exit(1)
        
    logging.config.fileConfig(iRacingUtils.getConfigFileName())
    
    username, password = iRacingUtils.getAccountDetails()
    primaryDAL = iRacingDAL.iRacingDAL(username, password)
    
    cache = MemoryCache.MemoryCache()
    dal = cachingDAL.cachingDAL(primaryDAL, cache)
    
    if not verbose: logging.getLogger().setLevel(logging.ERROR)
    races = dal.getSeasonRaces(season, week)
    logging.getLogger().info("Processing %d races for season %d week %d" % (len(races), season, week))
    i = 0
    for race in races:
        i += 1
        logging.getLogger().info("(%d,%d) race %d of %d" % (season, week, i, len(races)) )
        if race.isofficial:
            race.setResults(dal.getRaceResults(race.subsessionid))
            for result in race.getResults().itervalues():
                if result.laps == None:
                    result.setLaps(dal.getLaps(race.subsessionid, result.custid))
   
    if len(cache.races) == 0:
        logging.getLogger().info("No races were downloaded. No file written.")
        exit(0)
        
    iRacingUtils.writeCacheToPickle(cache, fileName)
Esempio n. 2
0
def readRaces(folder, season, week, verbose):
    fileName = "%s/Season %d Week %d.txt" % (folder, season, week)
    if not os.path.exists(fileName):
        print "%s not found" % fileName
        exit(1)

    cache = MemoryCache.MemoryCache()

    logging.config.fileConfig(iRacingUtils.getConfigFileName())
    if not verbose: logging.getLogger().setLevel(logging.ERROR)

    with open(fileName, "r") as file:
        logging.getLogger().info("Loading cached data from %s" % fileName)
        try:
            cache.races = pickle.load(file)
            logging.getLogger().info("Cached data loaded successfully")
        except BaseException as e:
            logging.getLogger().error("Error loading data from cache: %s" % e)

    logging.getLogger().info("Read %d races from file" % len(cache.races))
Esempio n. 3
0
def readRaces(folder, season, week, verbose):
    fileName = "%s/Season %d Week %d.txt" % (folder, season, week)
    if not os.path.exists(fileName):
        print "%s not found" % fileName
        exit(1)
    
    cache = MemoryCache.MemoryCache()        
        
    logging.config.fileConfig(iRacingUtils.getConfigFileName())
    if not verbose: logging.getLogger().setLevel(logging.ERROR)
    
    with open(fileName,"r") as file:
        logging.getLogger().info("Loading cached data from %s" % fileName)
        try:
            cache.races = pickle.load(file)
            logging.getLogger().info("Cached data loaded successfully")
        except BaseException as e:
            logging.getLogger().error("Error loading data from cache: %s" % e)

    logging.getLogger().info("Read %d races from file" % len(cache.races))
Esempio n. 4
0
def getRaces(folder, season, week, verbose):

    fileName = "%s/Season %d Week %d.txt" % (folder, season, week)
    if os.path.exists(fileName):
        print "%s already exists, exiting" % fileName
        exit(1)

    logging.config.fileConfig(iRacingUtils.getConfigFileName())

    username, password = iRacingUtils.getAccountDetails()
    primaryDAL = iRacingDAL.iRacingDAL(username, password)

    cache = MemoryCache.MemoryCache()
    dal = cachingDAL.cachingDAL(primaryDAL, cache)

    if not verbose: logging.getLogger().setLevel(logging.ERROR)
    races = dal.getSeasonRaces(season, week)
    logging.getLogger().info("Processing %d races for season %d week %d" %
                             (len(races), season, week))
    i = 0
    for race in races:
        i += 1
        logging.getLogger().info("(%d,%d) race %d of %d" %
                                 (season, week, i, len(races)))
        if race.isofficial:
            race.setResults(dal.getRaceResults(race.subsessionid))
            for result in race.getResults().itervalues():
                if result.laps == None:
                    result.setLaps(
                        dal.getLaps(race.subsessionid, result.custid))

    if len(cache.races) == 0:
        logging.getLogger().info("No races were downloaded. No file written.")
        exit(0)

    iRacingUtils.writeCacheToPickle(cache, fileName)
Esempio n. 5
0
class iRacingDAL_Tests(unittest.TestCase):

    logging.config.fileConfig(iRacingUtils.getConfigFileName())

    username, password = iRacingUtils.getAccountDetails()
    dal = iRacingDAL.iRacingDAL( username, password )

    seasons = [ (368, "MX-5 Season 4B", 4092, 781), (369, "MX-5 Season 4C", 4253, 908 ), (374, "Skip Barber 2010 S4", 2518, 181) ]


    def testGetSeasonRaces(self):
        for season, name, driverCount, raceCount in self.seasons:
            races = self.dal.getSeasonRaces(season, 0)
            self.assertIsNotNone(races)
            self.assertEquals(len(races), raceCount)
            self.assertIsInstance(races[0], Race)

    def testGetBadSeasonRaces(self):
        races = self.dal.getSeasonRaces(368, -1)
        self.assertIsNotNone(races)
        self.assertEquals(len(races), 0)

    def testGetRaceResult(self):
        rr = self.dal.getSessionResults(2790352) # Mazda mx-5 season 4B 2010-12-05 1.00pm
        # http://members.iracing.com/membersite/member/EventResult.do?&subsessionid=2790352&custid=57702
        self.assertIsNotNone(rr)
        self.assertEquals(len(rr), 12)
        self.assertIsInstance(rr[0],SessionResult)

    def testGetBadRaceResult(self):
        # Mazda mx-5 season 4B 2010-12-05 1.00pm
        rr = self.dal.getSessionResults(-1) 
        self.assertIsNotNone(rr)
        self.assertEquals(len(rr), 0)

    def testGetLapData(self):
        # http://members.iracing.com/membersite/member/EventResult.do?&subsessionid=2884449&custid=57702
        # 2010 Season 4B
        # 2010-12-27 1:00 pm

        rr = self.dal.getSessionResults(2884449) 
        self.assertIsNotNone(rr)
        self.assertEquals(len(rr), 12)

        """
        Finished in 11th place

        http://members.iracing.com/membersite/member/eventresult_laps.jsp?&subsessionid=2884449&custid=55267&simsessnum=0
        Jason Workman
        iRacing Mazda Cup - 2010 Season 4B
        2010-12-27 1:00 pm
        Race Session: 14085234/2884449 undefined
        Mazda Raceway Laguna Seca - Full Course
        #	Time	Comments
        0	- -:- -.- - -	
        1	01:48.161	off track
        2	01:57.394	fastest lap
        3	01:44.886	off track
        4	01:57.633	car contact, lost control
        """

        raceResult = rr[10]
        self.assertIsInstance(raceResult, SessionResult)
        self.assertEquals(raceResult.custid, 55267)
        laps = self.dal.getLaps(2884449, 55267)
        self.assertIsNotNone(laps)
        self.assertEquals(len(laps), 5, "5 laps should have been returned")
        self.assertIsInstance(laps[0], Lap)

        self.assertFalse(laps[0].isGoodLap(), "Lap 0 should not be a good lap")
        self.assertFalse(laps[0].isCleanLap(), "Lap 0 should not be a clean lap")

        self.assertTrue(laps[1].isGoodLap(), "Lap 1 should be a good lap")
        self.assertTrue(laps[1].flags & Lap.FLAG_OFF_TRACK)        
        self.assertEquals(laps[1].time, datetime.timedelta(minutes=1, seconds=48, milliseconds=161)) 

        self.assertTrue(laps[2].isGoodLap(), "Lap 2 should be a good lap")
        self.assertTrue(laps[2].isCleanLap(), "Lap 2 should be a clean lap")        
        self.assertEquals(laps[2].time, datetime.timedelta(minutes=1, seconds=57, milliseconds=394))         

        self.assertTrue(laps[3].isGoodLap())
        self.assertTrue(laps[3].flags & Lap.FLAG_OFF_TRACK)
        self.assertEquals(laps[3].time, datetime.timedelta(minutes=1, seconds=44, milliseconds=886))

        self.assertFalse(laps[4].isGoodLap())
        self.assertTrue(laps[4].flags & Lap.FLAG_CAR_CONTACT)
        self.assertTrue(laps[4].flags & Lap.FLAG_LOST_CONTROL)
        self.assertEquals(laps[4].time, datetime.timedelta(minutes=1, seconds=57, milliseconds=633))

    def testGoodSeasonStandings(self):
        for season, name, driverCount,raceCount in self.seasons:
            seasonStandings = self.dal.getSeasonStandings(season)
            self.assertIsNotNone(seasonStandings)

            self.assertIsNotNone(seasonStandings.standings)
            self.assertEquals(seasonStandings.season, season)
            self.assertEqual(len(seasonStandings.standings), driverCount)  

    def testMissingSeasonStandings(self):
        seasonstandings = self.dal.getSeasonStandings(99999)
        self.assertEqual(len(seasonstandings.standings), 0)

    def testSearchForDrivers(self):
        drivers = self.dal.searchForDrivers("Ian Bevan")
        self.assertIsNotNone(drivers)
        self.assertEqual(len(drivers), 1)
        self.assertEqual("Ian Bevan", drivers[0].name)
        self.assertEqual(57702, drivers[0].custid)
        self.assertEqual({}, drivers[0].personalbests)
Esempio n. 6
0
import logging
import logging.config
import MemoryCache
import iRacingUtils

logging.config.fileConfig(iRacingUtils.getConfigFileName())

cache = iRacingUtils.loadCacheFromPickle()

if cache is None:
    logging.getLogger().info("Cached data not available, exiting")
    exit(1)

totalraces = 0
totalcounted = 0

for week in range(0,10):
    unofficial = 0
    noresults = 0
    nolaps = 0

    races = cache.getSeasonRaces(420, week)  
    totalraces += len(races)    
    for race in races:
        if not race.isofficial:
            unofficial += 1
            continue
        
        results = race.getResults()    
        
        if results  == None:
Esempio n. 7
0
class MemoryCacheDAL_Test(unittest.TestCase):

    logging.config.fileConfig(iRacingUtils.getConfigFileName())
    custid = 1000
    subsessionid = 99

    def testGetNoLaps(self):
        dal = MemoryCache.MemoryCache()
        laps = dal.getLaps(self.subsessionid, self.custid)
        self.assertIsNotNone(laps)
        self.assertEquals(len(laps), 0)

    def testSingleSetLaps(self):
        dal = MemoryCache.MemoryCache()

        laps = []
        laps.append(dm.Lap(0, datetime.timedelta(seconds=1), 0))
        laps.append(dm.Lap(1, datetime.timedelta(seconds=2), 0))
        laps.append(dm.Lap(2, datetime.timedelta(seconds=3), 0))
        dal.setLaps(self.subsessionid, self.custid, laps)

        comp = dal.getLaps(self.subsessionid, self.custid)
        self.assertEqual(laps, comp)

    def testMultipleSetLaps(self):

        dal = MemoryCache.MemoryCache()

        laps = []
        laps.append(dm.Lap(0, datetime.timedelta(seconds=1), 0))
        laps.append(dm.Lap(1, datetime.timedelta(seconds=2), 0))
        laps.append(dm.Lap(2, datetime.timedelta(seconds=3), 0))

        for i in range(5):
            dal.setLaps(self.subsessionid + i, self.custid + i, laps)
            comp = dal.getLaps(self.subsessionid + i, self.custid + i)
            self.assertEqual(comp, laps)

    def testSetSeasonRaces(self):
        races = []
        races.append(dm.Race(0, 1, 20000, True))
        races.append(dm.Race(0, 2, 20001, True))
        races.append(dm.Race(0, 3, 20002, True))

        dal = MemoryCache.MemoryCache()
        dal.setSeasonRaces(season=430, week=1, races=races)

        comp = dal.getSeasonRaces(season=430, week=1)
        self.assertIsNotNone(comp)
        self.assertEquals(len(comp), len(races))
        self.assertEqual(comp, races)
        for i in range(0, len(races)):
            self.assertEqual(comp[i], races[i])

    def testSetMultipleSeasonRaces(self):
        dal = MemoryCache.MemoryCache()
        races = []
        races.append(dm.Race(0, 1, 20001, True))
        races.append(dm.Race(0, 2, 20002, True))
        races.append(dm.Race(0, 3, 20003, True))
        dal.setSeasonRaces(season=430, week=1, races=races)

        races1 = []
        races1.append(dm.Race(0, 4, 20004, True))
        races1.append(dm.Race(0, 5, 20005, True))
        races1.append(dm.Race(0, 6, 20006, True))
        dal.setSeasonRaces(season=431, week=2, races=races1)

        comp = dal.getSeasonRaces(season=431, week=2)
        self.assertIsNotNone(comp)
        self.assertEquals(len(comp), len(races1))
        self.assertEqual(comp, races1)
        for i in range(0, len(races1)):
            self.assertEqual(comp[i], races1[i])

    def testSetMoreSeasonRaces(self):
        """ Make sure that adding races for a week does not replace any existing races for that week """

        dal = MemoryCache.MemoryCache()
        races = []
        races.append(dm.Race(0, 1, 20001, True))
        races.append(dm.Race(0, 2, 20002, True))
        races.append(dm.Race(0, 3, 20003, True))
        dal.setSeasonRaces(season=430, week=1, races=races)

        races = []
        races.append(dm.Race(0, 4, 20004, True))
        races.append(dm.Race(0, 5, 20005, True))
        races.append(dm.Race(0, 6, 20006, True))
        dal.setSeasonRaces(season=430, week=1, races=races)

        comp = dal.getSeasonRaces(430, 1)
        self.assertEquals(len(comp), 6)
Esempio n. 8
0
import logging
import logging.config
import MemoryCache
import iRacingUtils

logging.config.fileConfig(iRacingUtils.getConfigFileName())

cache = iRacingUtils.loadCacheFromPickle()

if cache is None:
    logging.getLogger().info("Cached data not available, exiting")
    exit(1)

totalraces = 0
totalcounted = 0

for week in range(0, 10):
    unofficial = 0
    noresults = 0
    nolaps = 0

    races = cache.getSeasonRaces(420, week)
    totalraces += len(races)
    for race in races:
        if not race.isofficial:
            unofficial += 1
            continue

        results = race.getResults()

        if results == None: