示例#1
0
    def getRandomDriverTrips(self, numtrips, numNotDrivers, feat):

        #get list of drivers and shuffle
        notDrivers = os.listdir("../drivers/")
        copy = notDrivers[1:]
        random.shuffle(copy)
        notDrivers[1:] = copy

        #process number of 'other' drivers
        if numNotDrivers == 0 or numNotDrivers >= len(notDrivers):
            numNotDrivers = len(notDrivers) - 1

        #if we are comparing to only one driver and that driver is the same as
        #the original driver
        if numNotDrivers == 1:
            while notDrivers[1] == self.name:
                copy = notDrivers[1:]
                random.shuffle(copy)
                notDrivers[1:] = copy

        #sample trips and output desired features
        tripList = []
        for i in range(numtrips):
            dnum = notDrivers[random.randint(
                1, numNotDrivers)]  #sample a random driver
            #print self.name  + " " + dnum
            while dnum == self.name:  #don't sample from self
                dnum = notDrivers[random.randint(1, numNotDrivers)]
            tnum = random.randint(1, 200)  #sample a random trip
            t = Trip("../drivers/" + str(dnum) + "/" + str(tnum) + ".csv",
                     feat)
            tripList.append(t.printFeatures())

        return tripList
示例#2
0
	def writeCSV(self, numTrips=training_self):
		g = open ("driver_stats/"+str(self.name)+"_trips.csv", "w")
		#a header and then the features for each trip
		g.write("advSpeed,tripDist\n")
		for i in range (1, numTrips+1):
			t = Trip("../drivers/"+str(self.name)+"/"+str(i)+".csv")
			g.write(t.printFeatures())
		g.close()
示例#3
0
 def writeCSV_test(self):
     g = open("driver_stats/" + str(self.name) + "_test.csv", "w")
     #first trips from this driver
     for i in range(num_selfTrips + 1, num_selfTrips + num_testTrips + 1):
         t = Trip("../drivers/" + str(self.name) + "/" + str(i) + ".csv")
         g.write(t.printFeatures())
     #trips from other drivers
     tripList = self.getRandomDriverTrips(num_testTrips)
     for other in tripList:
         g.write(other)
     g.close()
示例#4
0
 def writeCSV_training(self):
     g = open("driver_stats/" + str(self.name) + "_training.csv", "w")
     #a header and then the features for each trip
     #g.write("advSpeed,tripDist\n")
     #first trips from this driver
     for i in range(1, num_selfTrips + 1):
         t = Trip("../drivers/" + str(self.name) + "/" + str(i) + ".csv")
         g.write(t.printFeatures())
     #trips from other drivers
     tripList = self.getRandomDriverTrips(num_NOTselfTrips)
     for other in tripList:
         g.write(other)
     g.close()
示例#5
0
	def writeCSV_notDriver(self, numTrips = training_others):
		#list other drivers in directory, since their numbers skip around
		notDrivers = os.listdir("../drivers/")

		g = open ("driver_stats/"+str(self.name)+"_NOTtrips.csv", "w")
		for i in range(numTrips):
			dnum = notDrivers[random.randint(1, len(notDrivers))] #sample a random driver
			while dnum == self.name: #don't sample from self
				dnum = notDrivers[random.randint(1, len(notDrivers))]
			tnum = random.randint(1,201)#sample a random trip
			t = Trip("../drivers/"+str(dnum)+"/"+str(tnum)+".csv")
			g.write(t.printFeatures())
		g.close()
示例#6
0
 def getRandomDriverTrips(self, numtrips):
     notDrivers = os.listdir("../drivers/")
     numNotDrivers = len(
         notDrivers)  #change this parameter to consider a different number
     tripList = []
     for i in range(numtrips):
         dnum = notDrivers[random.randint(1,
                                          len(notDrivers) -
                                          1)]  #sample a random driver
         while dnum == self.name:  #don't sample from self
             dnum = notDrivers[random.randint(1, numNotDrivers - 1)]
         tnum = random.randint(1, 200)  #sample a random trip
         t = Trip("../drivers/" + str(dnum) + "/" + str(tnum) + ".csv")
         tripList.append(t.printFeatures())
     return tripList
示例#7
0
    def writeCSV(self, order, numNotDrivers, feat):
        g = open("driver_stats/" + str(self.name) + "_training.csv", "w")

        #first trips from this driver
        for i in range(0, num_selfTrips + num_testTrips):
            #print i
            t = Trip(
                "../drivers/" + str(self.name) + "/" + str(order[i]) + ".csv",
                feat)
            g.write(t.printFeatures())

        #trips from other drivers
        tripList = self.getRandomDriverTrips(num_NOTselfTrips + num_testTrips,
                                             numNotDrivers, feat)
        for other in tripList:
            g.write(other)
        g.close()
示例#8
0
 def writeCSV_selfDriver(self):
     g = open("driver_stats/" + str(self.name) + "_selfTrips.csv", "w")
     for i in range(1, 201):  #get features for all driver trips
         t = Trip("../drivers/" + str(self.name) + "/" + str(i) + ".csv")
         g.write(t.printFeatures())
     g.close()