Exemplo n.º 1
0
    def deliver(self, package_hash, distance_dict, distances_list, truck_to_hub=False):
        if self.loaded_package_list:
            # Capacity is a constant number of 16 so the while loop counts as O(1)
            while self.loaded_package_list:
                address1 = self.location
                if self.location == 'HUB':
                    address1 = ' ' + self.location

                package_id = self.loaded_package_list.pop(0)
                address2 = ' ' + package_hash.get(package_id)[3] + '\n(' + package_hash.get(package_id)[6] + ')'
                hours = float(distance_between(address1, address2, distance_dict, distances_list)) / self.speed
                current_time = self.time.advance_time(self.time.current_time, hours, 0, 0)
                value = package_hash.get(package_id)
                value[0] = 'Finished'
                value[2] = 'Delivered at ' + current_time.strftime("%H:%M:%S")
                package_hash.add(package_id, value)
                self.location = address2
                self.time.end_time = current_time

        if truck_to_hub is True:
            address1 = self.location
            address2 = ' HUB'
            hours = float(distance_between(address1, address2, distance_dict, distances_list)) / self.speed
            current_time = self.time.advance_time(self.time.current_time, hours, 0, 0)
            self.location = address2
            self.time.end_time = current_time

        return hours
Exemplo n.º 2
0
    def on_status(self,tweet):
        self.text = ""
        self.hashtags = ""
        self.favs = 0
        self.retweets = 0
        self.username = ""
        self.followers = 0

        if (self.tweetCount < tweetThresh):

            if tweet.coordinates:

                d = math.ceil(distance.distance_between(tweet.coordinates["coordinates"][1], tweet.coordinates["coordinates"][0], center["lat"], center["long"]))

                if d < self.tweetRadius:
                    
                    # General Information
                    self.tweetCount += 1
                    self.text = tweet.text
                    self.favs = tweet.favorite_count
                    self.retweets = tweet.retweet_count
                    
                    # User Data
                    user = api.get_user(tweet.user.screen_name)
                    if user:
                        self.username = user.screen_name
                        self.followers = user.followers_count
                    
                    if verbose:
                        print "Tweet: " + str(self.tweetCount)
                        print "Text: " + self.text + " (Distance: " + str(d) + " mi)"
                        print "Fav: " + str(self.favs)
                        print "Retweets: " + str(self.retweets)
                        print "Hashtags: " + self.hashtags
                        print "User: "******"Followers: " + str(self.followers)
                        print "\n"
                
                
                    # CSV output
                    label = 1  # used for trainning classfilier
                    csvFile = 'testData.csv'
                    
                    if collectTrainingData:
                        csvFile = 'trainData.csv'
                    if (self.tweetCount == 0):
                        with open(csvFile,'wb') as outfile:
                            writer = csv.writer(outfile,delimiter='|')
                            writer.writerow((label,self.text.encode('utf-8'),self.followers))
                    else:
                        fd = open(csvFile,'a')
                        writer = csv.writer(fd,delimiter='|')
                        writer.writerow((label,self.text.encode('utf-8'),self.followers))
                        fd.close()

        else:
            print("Done Collecting Tweets!\n")
            sys.exit()
Exemplo n.º 3
0
 def on_status(self, tweet):
   # print str(StreamListener.count) + " " + tweet.user.screen_name + "-  " + tweet.text + "\n"
   if tweet.coordinates:
     # tweet coordinates come in longitude, latitude order for some reason
     d = math.ceil(distance.distance_between(tweet.coordinates["coordinates"][1], tweet.coordinates["coordinates"][0], center["lat"], center["long"]))
     # this makes sure tweets are within 25 miles of center
     if d < 10000:
       print tweet
       print tweet.coordinates
       print tweet.text + "(" + str(d) + " mi)"
       print ""
Exemplo n.º 4
0
 def on_status(self, tweet):
     if tweet.coordinates:
         d = math.ceil(distance_between(
             tweet.coordinates["coordinates"][1],
             tweet.coordinates["coordinates"][0],
             self.center["lat"],
             self.center["long"]))
         if d < self.distance:
             user = self.api.get_user(tweet.user.screen_name)
             self.action(tweet, user)
             self.count += 1
             if self.quantity > 0 and self.count >= self.quantity:
                 return False
    def on_status(self,tweet):
        text = ""
        hashtags = ""
        urls = ""
        user_mentions = ""
        favs = 0
        retweets = 0
        username = ""
        followers = 0

        if (self.tweetCount < self.tweetThresh):

            if tweet.coordinates:

                d = math.ceil(distance.distance_between(tweet.coordinates["coordinates"][1], tweet.coordinates["coordinates"][0], center["lat"], center["long"]))

                if d < 10000:

                    self.tweetCount += 1
                    text = tweet.text
                    favs = tweet.favorite_count
                    print "Text: " + text + "\n" + "Distance: " + str(d) + " mi" + "\n" + "Fav: " + str(favs) + "\n" + "Retweets: " + str(retweets)
                    print "\n"

                    label = 1  # used for trainning classfilier
                    csvFile = 'testData.csv'
                    if collectTrainningData:
                        csvFile = 'trainData.csv'
                    if (self.tweetCount == 0):
                        with open(csvFile,'wb') as outfile:
                            writer = csv.writer(outfile,delimiter='|')
                            writer.writerow((label,text.encode('utf-8'),followers))
                    else:
                        fd = open(csvFile,'a')
                        writer = csv.writer(fd,delimiter='|')
                        writer.writerow((label,text.encode('utf-8'),followers))
                        fd.close()

        else:
            print("Done Collecting Tweets!\n")
            sys.exit()