def __init__(self, userID, category=None, parent=None, ctree=None, eaa=None, score=None, dictionary=None, db=user_behavior.DJANGO_DB): """ A Tree for a user is represented recursively as a collection of trees, Each gtree is for a specific user. The name of a tree node is the category name otherwise defaults to ROOT the value is calculated from the persisted representation of the tree much the user likes this, and optionally children """ self.parent = parent self.children = [] if not ctree: ctree = CachedCategoryTree() if eaa == None: # get from DB (whether Django or dictionary) eaa = db.gvix_dict(userID) if category: self.children = [ CategoryTree(userID, x, self, ctree, eaa) for x in ctree.children(category) ] self.category = category self.title = category.title else: self.children = [ CategoryTree(userID, x, self, ctree, eaa) for x in ctree.children(ctree.concrete_node) ] self.category = ctree.concrete_node self.title = ctree.concrete_node.title if dictionary: self.dictionary = dictionary else: self.dictionary = {} try: self.score = eaa[self.category.id] except: #if self.category: # self.score = settings.default_eaa[self.category.id] #else: self.score = ( (0, 0, 0, 0) ) # * settings.scoringFunction((0,0,0,0)) #This is the root node
def __init__(self, userID, category=None, parent=None, ctree=None, eaa=None, score=None, dictionary=None, db=user_behavior.DJANGO_DB): """ A Tree for a user is represented recursively as a collection of trees, Each gtree is for a specific user. The name of a tree node is the category name otherwise defaults to ROOT the value is calculated from the persisted representation of the tree much the user likes this, and optionally children """ self.parent = parent self.children = [] if not ctree: ctree = CachedCategoryTree() if eaa==None: # get from DB (whether Django or dictionary) eaa = db.gvix_dict(userID) if category: self.children = [CategoryTree(userID, x, self, ctree, eaa) for x in ctree.children(category)] self.category = category self.title = category.title else: self.children = [CategoryTree(userID, x, self, ctree, eaa) for x in ctree.children(ctree.concrete_node)] self.category = ctree.concrete_node self.title = ctree.concrete_node.title if dictionary: self.dictionary = dictionary else: self.dictionary = {} try: self.score = eaa[self.category.id] except: #if self.category: # self.score = settings.default_eaa[self.category.id] #else: self.score = ((0, 0, 0, 0)) # * settings.scoringFunction((0,0,0,0)) #This is the root node
def test_load_db(self): ctree = CachedCategoryTree() for cc in ctree.children(ctree.concrete_node): self.assertEqual(self.n, cc.events_concrete.all().count())