def __init__(self, data, twitterSession, fromCache=False): Timestamped.__init__(self) Hashable.__init__(self) if twitterSession is not None: assert isinstance(twitterSession, TwitterSession) self.data = Tree.make(data) if not fromCache: self.data.applyFunctionInTree(reverse_list, ['coordinates', 'coordinates']) # for use with leaflet. self.isDataNew = not fromCache twitterPlaceData = self.data.getFromTree(['place']) if twitterPlaceData is not None: self.twitter_place = Place(twitterPlaceData) else: self.twitter_place = None userJson = self.data.getFromTree(['user']) if userJson is None: self._user = None else: self._user = User(userJson, twitterSession=twitterSession, isAssociatedWithTweet=True, twitterPlace=self.twitter_place, currentLocationCoordinate=self.coordinate) if twitterSession is not None: self.instance_key = twitterSession.instance_key else: self.instance_key = None self.twitter_session = twitterSession
def __init__(self, x, y, age=None, hash=1): Timestamped.__init__(self) self.x = x self.y = y self.hash = hash if age is not None: self.timestamp = getEpochMs() - age
def __init__(self, userJson, twitterSession, fromCache=False, isFollowee=False, isAssociatedWithTweet=False, twitterPlace=None, currentLocationCoordinate=None, geocodeBias=None, knownFollowees=None): Hashable.__init__(self) Timestamped.__init__(self) if twitterSession is not None: assert isinstance(twitterSession, TwitterSession) if twitterPlace is not None: assert isinstance(twitterPlace, Place) if knownFollowees is None: knownFollowees = set() self.allow_geocode_external = True if userJson is None: self.data = Tree.make() else: self.data = Tree.make(userJson) # If false indicates that self.data is already in the cache, # so no point readding. self.isDataNew = not fromCache self.is_followee = isFollowee # This does not contain all followees, only followees known to our application # through follower enrichment. self.known_followees = knownFollowees self.is_associated_with_tweet = isAssociatedWithTweet self.twitter_session = twitterSession if twitterSession is not None: self.instance_key = twitterSession.instance_key else: self.instance_key = None self.queued_for_follower_enrichment = False self.current_location_coordinate = currentLocationCoordinate self.twitter_place = twitterPlace self.last_follower_enrichment_error = None self.follower_enrichment_progress = UserFollowerEnrichmentProgress(self) if self.num_followers is not None: self.twitter_calls_to_retrieve_follower_ids = math.ceil(float(self.num_followers) / float(TwitterSession.GET_FOLLOWER_IDS_QUANTITY_PER_TWITTER_CALL)) else: self.twitter_calls_to_retrieve_follower_ids = 1 self.geocoded_from = None self.geocode_bias = None self.analysers = None
def testTreeFunctioned(self): funcList = [lambda a: a.x, lambda a: a.y] ob1 = testTree.TestObj(0, 50, 0) ob2 = testTree.TestObj(100, 150, 1000) ob3 = testTree.TestObj(100, 250, 2000) ob4 = testTree.TestObj(100, 250, 3000) comparisonObj = testTree.TestObj(100, 150, 1000) treeController = DictTreeFunctioned(hashFuncList=funcList) dic = SpecialDict() treeController.addByFunction(dic, ob1) treeController.addByFunction(dic, ob2) treeController.addByFunction(dic, ob3) treeController.addByFunction(dic, ob4) result = treeController.getOriginalByFunction(dic,comparisonObj) assert result is ob2 # We override the first hash function, it will look # only at the second hash function. ob5 = testTree.TestObj(100, 300, 4000) treeController.addByFunction(dic[0], ob5, depth=1) assert dic[0][50] is ob1 assert len(dic[0]) == 2 assert len(dic[100]) == 2 assert len(dic) == 2 assert dic[100][150] is ob2 assert dic[100][250] is ob4 assert dic[100][250] is ob4 assert dic[0][300] is ob5 Timestamped.prune(dic, 2100) assert len(dic) == 2 assert len(dic[0]) == 1 assert len(dic[100]) == 1 assert dic[0][50] is not None assert dic[100][150] is not None
def testTreeFunctioned(self): funcList = [lambda a: a.x, lambda a: a.y] ob1 = testTree.TestObj(0, 50, 0) ob2 = testTree.TestObj(100, 150, 1000) ob3 = testTree.TestObj(100, 250, 2000) ob4 = testTree.TestObj(100, 250, 3000) comparisonObj = testTree.TestObj(100, 150, 1000) treeController = DictTreeFunctioned(hashFuncList=funcList) dic = SpecialDict() treeController.addByFunction(dic, ob1) treeController.addByFunction(dic, ob2) treeController.addByFunction(dic, ob3) treeController.addByFunction(dic, ob4) result = treeController.getOriginalByFunction(dic, comparisonObj) assert result is ob2 # We override the first hash function, it will look # only at the second hash function. ob5 = testTree.TestObj(100, 300, 4000) treeController.addByFunction(dic[0], ob5, depth=1) assert dic[0][50] is ob1 assert len(dic[0]) == 2 assert len(dic[100]) == 2 assert len(dic) == 2 assert dic[100][150] is ob2 assert dic[100][250] is ob4 assert dic[100][250] is ob4 assert dic[0][300] is ob5 Timestamped.prune(dic, 2100) assert len(dic) == 2 assert len(dic[0]) == 1 assert len(dic[100]) == 1 assert dic[0][50] is not None assert dic[100][150] is not None