Changes related to presentation, and new tabs.
Changes related to presentation, and new tabs.

- Changed nearly all values to percentages of the total
- Added non-version info for OS and browsers
- Made tabs into dropdowns for Browser/OS

--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -76,8 +76,14 @@
                     mins, secs = divmod(float(val), 60)
                     hours, mins = divmod(mins, 60)
                     val = '%02d:%02d:%02d (%s seconds) ' % (hours, mins, secs, val)
+                if key == 'Percent new visits':
+                    key = 'New visits'
+                    val = "%s%%" % val
             if key in ['Bounces', 'Total pageviews']:
                 val = int(val)
+                if key == 'Total pageviews':
+                    key = 'Total page views'
+
             return key, val
 
         c.global_totals = []
@@ -99,8 +105,10 @@
                 c.global_totals = sorted(c.global_totals, key=operator.itemgetter(0))
 
         keys = {
-            'Browser versions': 'browsers',
-            'Operating Systems versions': 'os',
+            'Browser versions': 'browser_versions',
+            'Browsers': 'browsers',
+            'Operating Systems versions': 'os_versions',
+            'Operating Systems': 'os',
             'Social sources': 'social_networks',
             'Languages': 'languages',
             'Country': 'country'
@@ -143,9 +151,14 @@
                 entries.append((key,val,))
             entries = sorted(entries, key=operator.itemgetter(1), reverse=True)
 
-            setattr(c, v, [(k,v) for k,v in entries ])
-
-
+            def percent(num, total):
+                p = 100 * float(num)/float(total)
+                return "%.2f%%" % round(p, 2)
+
+            # Get the total for each set of values and then set the value as
+            # a percentage of the total
+            total = sum([num for _,num in entries])
+            setattr(c, v, [(k,percent(v,total)) for k,v in entries ])
 
         return render('ga_report/site/index.html')
 

--- a/ckanext/ga_report/templates/ga_report/ga_util.html
+++ b/ckanext/ga_report/templates/ga_report/ga_util.html
@@ -12,6 +12,20 @@
      <td><a href="/publisher/${group.name}">${title}</a></td>
    </tr>
    </py:for>
+ </table>
+
+
+<table py:def="stat_table(items)" class="table table-condensed table-bordered table-striped">
+    <tr>
+        <th>Name</th>
+        <th>% Views</th>
+    </tr>
+    <py:for each="name, value in items">
+    <tr>
+        <td>${name}</td>
+        <td>${value}</td>
+    </tr>
+    </py:for>
  </table>
 
 

--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -44,8 +44,22 @@
     <div class="tabbable">
       <ul class="nav nav-tabs">
         <li class="active"><a href="#totals" data-toggle="tab">Totals</a></li>
-        <li><a href="#browsers" data-toggle="tab">Browsers</a></li>
-        <li><a href="#os" data-toggle="tab">Operating Systems</a></li>
+        <li class="dropdown">
+            <a href="#browsers" class="dropdown-toggle" data-toggle="dropdown">Browsers
+                <b class="caret"></b></a>
+            <ul class="dropdown-menu">
+                <li><a href="#browsers_names" data-toggle="tab">Browsers</a></li>
+                <li><a href="#browsers_versions" data-toggle="tab">Versions</a></li>
+            </ul>
+        </li>
+        <li class="dropdown">
+            <a href="#browsers" class="dropdown-toggle" data-toggle="dropdown">Operating<br/>Systems
+                <b class="caret"></b></a>
+            <ul class="dropdown-menu">
+                <li><a href="#os" data-toggle="tab">Operating Systems</a></li>
+                <li><a href="#os_versions" data-toggle="tab">Versions</a></li>
+            </ul>
+        </li>
         <li><a href="#social_networks" data-toggle="tab">Social Networks</a></li>
         <li><a href="#languages" data-toggle="tab">Languages</a></li>
         <li><a href="#country" data-toggle="tab">Country</a></li>
@@ -65,75 +79,26 @@
                 </py:for>
                </table>
         </div>
-        <div class="tab-pane" id="browsers">
-             <table class="table table-condensed table-bordered table-striped">
-            	 <tr>
-            	   <th>Name</th>
-            	   <th>Value</th>
-            	 </tr>
-                <py:for each="name, value in c.browsers">
-                    <tr>
-                        <td>${name}</td>
-                        <td>${value}</td>
-                    </tr>
-                </py:for>
-               </table>
-        </div>
-        <div class="tab-pane" id="os">
-             <table class="table table-condensed table-bordered table-striped">
-            	 <tr>
-            	   <th>Name</th>
-            	   <th>Value</th>
-            	 </tr>
-                <py:for each="name, value in c.os">
-                    <tr>
-                        <td>${name}</td>
-                        <td>${value}</td>
-                    </tr>
-                </py:for>
-               </table>
-        </div>
+         <div class="tab-pane" id="browsers_versions">
+             ${stat_table(c.browser_versions)}
+         </div>
+         <div class="tab-pane" id="browsers_names">
+             ${stat_table(c.browsers)}
+         </div>
+         <div class="tab-pane" id="os">
+             ${stat_table(c.os)}
+         </div>
+         <div class="tab-pane" id="os_versions">
+             ${stat_table(c.os_versions)}
+         </div>
         <div class="tab-pane" id="social_networks">
-             <table class="table table-condensed table-bordered table-striped">
-            	 <tr>
-            	   <th>Name</th>
-            	   <th>Value</th>
-            	 </tr>
-                <py:for each="name, value in c.social_networks">
-                    <tr>
-                        <td>${name}</td>
-                        <td>${value}</td>
-                    </tr>
-                </py:for>
-               </table>
+             ${stat_table(c.social_networks)}
         </div>
         <div class="tab-pane" id="languages">
-             <table class="table table-condensed table-bordered table-striped">
-            	 <tr>
-            	   <th>Name</th>
-            	   <th>Value</th>
-            	 </tr>
-                <py:for each="name, value in c.languages">
-                    <tr>
-                        <td>${name}</td>
-                        <td>${value}</td>
-                    </tr>
-                </py:for>
-               </table>
+             ${stat_table(c.languages)}
         </div>
         <div class="tab-pane" id="country">
-             <table class="table table-condensed table-bordered table-striped">
-            	 <tr>
-            	   <th>Name</th>
-            	   <th>Value</th>
-            	 </tr>
-                <py:for each="name, value in c.country">
-                    <tr>
-                        <td>${name}</td>
-                        <td>${value}</td>
-                    </tr>
-                </py:for>
-               </table>
+             ${stat_table(c.country)}
         </div>
 
 
@@ -148,6 +113,7 @@
 
   <py:def function="optional_footer">
     <script type='text/javascript'>
+        $('.dropdown-toggle').dropdown();
         $('.nav-tabs li a').click(function (e) {
           e.preventDefault();
           $(this).tab('show');