Changeset 1355


Ignore:
Timestamp:
02/09/07 15:43:14 (13 years ago)
Author:
jukka
Message:

Continued with separation of TagClouds? and TitleClouds? in code. Simplified TagClouds? to only handle tag-like attributes. Old method redirects to either TagClouds? or TitleClouds?, depending on case.

To do: browsing users should return NiceNames?, not titles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LargeSectionFolder.py

    r1354 r1355  
    558558            i=(a,b,c,d,e) 
    559559            return i         
     560             
    560561        def calc_piece(x): 
    561562            res=rc({'targetUID':x.UID}) 
    562563            score=len(res) 
    563564            return score 
     565             
    564566        def calc_activity(x): 
    565567            res=rc({'targetUID':x.UID}) 
     
    611613        """ Should return unique values of search results in given index, results are list of index-metadata-like tuples in alphabetical order """ 
    612614 
    613         if browse_type.endswith('_titles'):  
     615        if search_results==[] or search_results==None: 
     616            return [] 
     617        elif browse_type.endswith('_titles'):  
    614618            return self.getTitleCloud(search_results, browse_type) 
    615  
     619        elif browse_type=='hits': 
     620            return self.getTagCloud(search_results, index_type, browse_type) 
     621 
     622 
     623    def getTagCloud(self, search_results, index_type, browse_type): 
    616624        lemill_tool = getToolByName(self, 'lemill_tool') 
    617625        pc = getToolByName(self, 'portal_catalog') 
    618         uniquetuplelist=[] 
     626        from math import log 
     627        resultlist=[] 
    619628        maxcount=0 
    620         uniques=[] 
    621         from math import log 
     629        uniquevalues=[] 
    622630 
    623631        def adjust(i): 
    624632            # helper method to adjust hit count of this tag to relative size (1,...,8)  
    625633            (a,b,c,d,e)=i 
    626             if type(b)==int: 
    627                 if b>1: 
    628                     b=int((8*log(b,2))/log(maxcount,2)) 
    629                     if b==0: 
    630                         b=1 
    631                 i=(a,b,c,d,e) 
    632             else: 
    633                 print 'Broken MemberFolder: (%s,%s,%s,%s,%s)' % (a,b,c,d,e) 
     634            b=int((8*log(b,2))/log(maxcount,2)) 
     635            if b==0: 
     636                b=1 
     637            i=(a,b,c,d,e) 
    634638            return i 
    635639 
    636         # -- Step 1 -- : Make list of unique values for this index. For members and groups this is time to collect their urls and title. 
    637         if browse_type=='hits': 
    638             uniques = pc.uniqueValuesFor(index_type)             
    639         elif browse_type=='active_groups': 
    640             groups = search_results 
    641             uniques = [x.id for x in groups] 
    642  
     640        # -- Step 1 -- : Make list of unique values for this index 
     641        uniques = pc.uniqueValuesFor(index_type)             
    643642        if uniques == []: 
    644643            return [] 
    645644        hits={} 
    646  
    647         # -- Step 2 -- : Use list to make a dictionary. Values of list are keys. 
     645        # -- Step 2 -- : Use that list to make a dictionary. Values of list are keys. 
    648646        for a in uniques: 
    649             hits[a]=(0,'','','') # value : (hits, objectURL, sort_title, title) 
    650  
    651         # -- Step 3 -- : Go through the search_results and every time a certain key is found from selected index, add a hit to counter under that key. With people and group names the counter gets hits from different sources. 
    652         if browse_type=='active_groups': 
    653             # Just get activity score from group metadata 
    654             for group in groups: 
    655                 hits[group.id]=(max(1, group.getActivity_score), group.getURL(), group.sortable_title, group.Title) 
    656                  
    657         elif browse_type=="unique_hits": 
    658             for counter in search_results: 
    659                 if counter.review_state!='deleted': 
    660                     value=getattr(counter, index_type) 
    661                     hits[value]=(0, counter.getURL(), value, counter.Title) 
    662         else: 
    663             # Vanilla hits counter 
    664             spent_urls=[] 
    665             for counter in search_results: 
    666                 c_url=counter.getURL() 
    667                 if counter.review_state!='deleted' and not c_url in spent_urls: 
    668                     values=getattr(counter, index_type) 
    669                     if values!=None: 
    670                         if type(values)==str or type(values)==int: 
    671                             hits[values]=(hits[values][0]+1, c_url, values, values) 
    672                         elif type(values)==list or type(values)==tuple: 
    673                             for a in list(values): 
    674                                 hits[a]=(hits[a][0]+1, c_url, a, a) 
    675                     spent_urls.append(c_url) 
    676         # OK, the story so far: hits = dictionary, where keys are the distinct values of current index, or memberid:s 
    677         # values of this dictionary are tuples, where: 
    678         # value[0]= n of objects that have this value, 
    679         # value[1]= url-of-object that has this value (sensible only if there is one object with this value, like names for users), 
    680         # value[2]= title, nicer representation of key's name (title for group names and nicename for member names) 
    681         # value[3]= another_title, because sortable_nicename already takes the title place for members. ugly... 
    682  
    683         # -- Step 4 -- : Build a list from previous dictionary. Objects in list are tuples. Order list alphabetically. 
    684         # This dictionary should be ordered alphabetically by title. 
     647            hits[a]=0  
     648        # -- Step 3 -- : Go through the search_results and every time a certain key is found from selected index, add a hit to counter under that key. 
     649        spent_urls=[] 
     650        for c_obj in search_results: 
     651            if c_obj.review_state!='deleted': 
     652                values=getattr(c_obj, index_type) 
     653                if values!=None: 
     654                    if type(values)==str or type(values)==int: 
     655                        hits[values]=hits[values][0]+1 
     656                    elif type(values)==list or type(values)==tuple: 
     657                        for a in list(values): 
     658                            hits[a]=hits[a]+1                
     659 
     660        # -- Step 4 -- : Build a list from previous dictionary. 
    685661        if hits.has_key(''): 
    686662            del hits[''] 
    687         uniquetuplelist=[(x[1][2],x[1][0],x[1][1],x[0],x[1][3]) for x in hits.items() if x[1][0]>0]         
    688         # uniquetuplelist now contains dictionary reordered: (sort_title, count, url, indexvalue, title) 
    689         if uniquetuplelist==[]: 
    690             return uniquetuplelist 
    691         if browse_type in ('hits','active_groups') and len(uniquetuplelist)>100: 
    692             # order by activity/usage 
    693             tmplist = [(x[1], x) for x in uniquetuplelist] 
    694             tmplist.sort() 
    695             tmplist.reverse() 
    696             uniquetuplelist = [x for (key, x) in tmplist] 
    697             # select value at cut point 
    698             maxcount=uniquetuplelist[0][1] 
    699             smallest=uniquetuplelist[100][1] 
     663        resultlist=[(x[1], x[0]) for x in hits.items() if x[1]>0]  
     664        resultlist.sort() 
     665        resultlist.reverse() 
     666        maxcount=resultlist[0][0] 
     667        # if the first cut score for tag is x, we want to cut off all of the tags with score x.  
     668        if len(resultlist)>100: 
     669            resultlist= resultlist[:100] 
     670            smallest=resultlist[100][0] 
    700671            cutpoint=99 
    701             small_value=uniquetuplelist[cutpoint][1] 
    702             # keep going down the list as long as the values are equal 
     672            small_value=resultlist[cutpoint][0] 
     673            # keep going down the list as long as the scores are equal 
    703674            while small_value==smallest: 
    704675                cutpoint=cutpoint-1 
    705                 small_value=uniquetuplelist[cutpoint][1] 
    706             uniquetuplelist=uniquetuplelist[:cutpoint+1] 
    707  
    708         else: 
    709             maxcount=max(map(lambda x: x[1], uniquetuplelist)) 
    710         uniquetuplelist.sort() 
    711         uniquetuplelist=map(adjust, uniquetuplelist) 
    712           
     676                small_value=resultlist[cutpoint][0] 
     677            resultlist=resultlist[:cutpoint+1] 
     678        resultlist=[(x[1], x[0], '','',x[1]) for x in resultlist] 
     679 
     680        # adjust to 1-8. We don't have to worry about score 0, they're already removed. 
     681        resultlist=map(adjust, resultlist)          
    713682        # prettify language names 
    714683        if index_type=='Language' or index_type=='getLanguage_skills': 
    715             uniquetuplelist=[(x[0],x[1],x[2],x[3],lemill_tool.getPrettyLanguage(x[4])) for x in uniquetuplelist] 
    716  
    717         return uniquetuplelist 
     684            resultlist=[(x[0],x[1],x[2],x[3],lemill_tool.getPrettyLanguage(x[4])) for x in resultlist] 
     685             
     686        resultlist.sort() 
     687        return resultlist 
    718688 
    719689    def getTagURL(self,context,category,value,filter=None, insideMemberFolder=False): 
Note: See TracChangeset for help on using the changeset viewer.