[cc-commits] [CC SVN] r12564 - in stats/wikibot: . template

webmaster at creativecommons.org webmaster at creativecommons.org
Thu May 7 13:53:54 EDT 2009


Author: bhy
Date: 2009-05-07 17:53:53 +0000 (Thu, 07 May 2009)
New Revision: 12564

Added:
   stats/wikibot/template/stats_juris.wiki
Modified:
   stats/wikibot/views.py
Log:
add ranking on juris stats

Copied: stats/wikibot/template/stats_juris.wiki (from rev 12468, stats/wikibot/template/stats.wiki)
===================================================================
--- stats/wikibot/template/stats_juris.wiki	                        (rev 0)
+++ stats/wikibot/template/stats_juris.wiki	2009-05-07 17:53:53 UTC (rev 12564)
@@ -0,0 +1,60 @@
+{# 
+== List of parameters ==
+ licenses: A list of license code which is available (ie. has count>0)
+ count(x): Count of license x
+ percent(x): Float number, percent of license x in [0,1]
+ total: Total number of licenses.
+ freedom_score: Freedom score.
+ date: current date.
+ thousandsep: A thousand seperator filter for numbers.
+#}
+{| class="wikitable" style="text-align:center" border="1"
+|+ CC License Adoption - Search Results
+! License
+! {{licenses | join(' !! ')}}
+! Total
+|-
+! Count
+{% for item in licenses %}
+| {{count(item) | thousandsep }}
+{% endfor %}
+| {{total | thousandsep}}
+|-
+! Percent
+{% for item in licenses %}
+| {{(percent(item)*100) | round(2)}}
+{% endfor %}
+| 100
+|}
+
+<div style="width:520px">
+'''''Note:''' These are estimates compiled from search engine results and therefore indicative only. See the [[help]] page for more information.''
+</div>
+{|
+|-
+| 
+{| class="wikitable" style="text-align:center" border="1"
+! Freedom score 
+|-
+| {{freedom_score | round(2)}}
+|}
+|
+| 
+| 
+{| border="1" style="text-align: center;" class="wikitable"
+|-
+! Ranking 
+! Volume 
+! Freedom
+|-
+| Rank 
+| {{ rank_by_volume }} out of {{ total_ranked }}
+| {{ rank_by_freedom }} out of {{ total_ranked }}
+|}
+
+|}
+''See also [[Jurisdiction Comparison]]'' 
+
+
+'''Source:''' Yahoo!  {{ '{{pad|3em}}' }}  '''Date:''' {{ date }} {{ '{{pad|3em}}' }}  [[Help]]
+

Modified: stats/wikibot/views.py
===================================================================
--- stats/wikibot/views.py	2009-05-07 16:40:23 UTC (rev 12563)
+++ stats/wikibot/views.py	2009-05-07 17:53:53 UTC (rev 12564)
@@ -12,6 +12,7 @@
 
 TEMPLATE_DIR = 'template/'
 STATS_TEMPLATE = 'stats.wiki'
+TEMPLATE_STATS_JURIS = 'stats_juris.wiki'
 LINKLIST_TEMPLATE = 'simplelinklist.wiki'
 TEMPLATE_SIDEBARLIST = 'sidebarlist.wiki'
 XML_WORLDMAP_FREEDOM = 'worldmap_freedom.xml'
@@ -215,6 +216,8 @@
                 links = []
             page = self.render(name, TEMPLATE_USER_JURIS,
                                 stats = name + '/' + BOTPAGE_STATS,
+                                juris_code = code,
+                                juris_name = name,
                                 links = links)
             yield page
         return
@@ -248,14 +251,30 @@
 
     def stats_juris(self):
         query = self.query
-        for code in query.all_juris():
+        all_data = {}
+        sorted_by_volume, sorted_by_freedom = self._sorted_stats()
+        sorted_by_volume = [x[0] for x in sorted_by_volume]
+        sorted_by_freedom = [x[0] for x in sorted_by_freedom]
+        total_ranked = len(sorted_by_volume)
+        all_juris = query.all_juris()
+        for code in all_juris:
             juris_name = query.juris_code2name(code)
             data = query.license_by_juris(code)
-            try:
+            if code:
+                # not unported
+                rank_by_volume = sorted_by_volume.index(juris_name) + 1
+                rank_by_freedom = sorted_by_freedom.index(juris_name) + 1
+                try:
+                    yield self._stats(juris_name, data, TEMPLATE_STATS_JURIS,
+                                rank_by_volume = rank_by_volume,
+                                rank_by_freedom = rank_by_freedom,
+                                total_ranked = total_ranked)
+                except ValueError:
+                    # Linkback data is empty
+                    pass
+            else:
                 yield self._stats(juris_name, data)
-            except ValueError:
-                # Linkback data is empty
-                pass
+
         # Fix for UK
         yield self._stats(query.juris_code2name('GB'), self._gb_data())
         return
@@ -371,10 +390,7 @@
 
         return
 
-    def rankdtables(self):
-        """
-        Tables of jurisdictions with ranking.
-        """
+    def _sorted_stats(self):
         query = self.query
         all_stats = []
         for code in query.all_juris():
@@ -387,12 +403,20 @@
             all_stats.append((name, stat))
 
         sorted_by_volume = sorted(all_stats, key=lambda x: x[1].total, reverse=True)
+        sorted_by_freedom = sorted(all_stats, key=lambda x: x[1].freedom_score, reverse=True)
+        return sorted_by_volume, sorted_by_freedom
+
+    def rankdtables(self):
+        """
+        Tables of jurisdictions with ranking.
+        """
+        sorted_by_volume, sorted_by_freedom = self._sorted_stats()
+
         page = self.render(self._botns(BOTPAGE_RANKED_BY_VOLUME),
                             TEMPLATE_RANKED_BY_VOLUME,
                             stats = sorted_by_volume)
         yield page
 
-        sorted_by_freedom = sorted(all_stats, key=lambda x: x[1].freedom_score, reverse=True)
         page = self.render(self._botns(BOTPAGE_RANKED_BY_FREEDOM),
                             TEMPLATE_RANKED_BY_FREEDOM,
                             stats = sorted_by_freedom)
@@ -431,10 +455,12 @@
 
     pagegen = itertools.chain(view.all_pages(), view.all_userpages())
     for page in pagegen:
-        print '='*50
+        title = page.title
+        text = page.text.replace('==', '===')
+        print 
+        print '==', title, '=='
+        print text
         print
-        print page
-        print
 
     return
 




More information about the cc-commits mailing list