From: Tom Rees Date: Tue, 02 Apr 2013 16:25:45 +0000 Subject: [403] Fix rickshaw choking if there is an empty 'Others' series. X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=712b17e95c6b16fa6a688d274665b2d1701515ba --- [403] Fix rickshaw choking if there is an empty 'Others' series. --- --- a/ckanext/ga_report/controller.py +++ b/ckanext/ga_report/controller.py @@ -218,7 +218,10 @@ 'x':_get_unix_epoch(stat.period_name), 'y':float(stat.value) }) - graph = [ graph_dict[x[0]] for x in entries ] + stats_in_table = [x[0] for x in entries] + stats_not_in_table = set(graph_dict.keys()) - set(stats_in_table) + stats = stats_in_table + sorted(list(stats_not_in_table)) + graph = [graph_dict[x] for x in stats] setattr(c, v+'_graph', json.dumps( _to_rickshaw(graph,percentageMode=True) )) # Get the total for each set of values and then set the value as @@ -445,12 +448,13 @@ fraction = float(point['y']) / totals[point['x']] if not (series in data) and fraction>THRESHOLD: data.append(series) - # Overwrite data with a set of intereting series + # Overwrite data with a set of interesting series others = [ x for x in raw_data if not (x in data) ] - data.append({ - 'name':'Other', - 'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] - }) + if len(others): + data.append({ + 'name':'Other', + 'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] + }) # Turn each point into a percentage for series in data: for point in series['data']: --- a/ckanext/ga_report/templates/ga_report/ga_util.html +++ b/ckanext/ga_report/templates/ga_report/ga_util.html @@ -59,41 +59,21 @@ -
- - - Site-wide - | - Publishers - | - Datasets - -
- -
-
-
-

Download

-

- Download as CSV
-

-
-
-

Graph Legend

-
-
(No graph loaded)
-
-
-
-

Notes

-
    -
  • "Views" is the number of times a page was loaded in users' browsers.
  • -
  • "Downloads" is the number of times a user has clicked to download either an original or cached resource for a particular dataset. Download information is only available from 2nd December 2012; 'No data' is shown for records before that date.
  • -
  • These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.
  • -
  • The results are not shown when the number of views/visits is tiny. Where these relate to site pages, results are available in full in the CSV download. Where these relate to users' web browser information, results are not disclosed, for privacy reasons.
  • +
    +
    + -
    +
--- /dev/null +++ b/ckanext/ga_report/templates/ga_report/notes.html @@ -1,1 +1,16 @@ + +
  • +

    Notes

    +
      +
    • "Views" is the number of times a page was loaded in users' browsers.
    • +
    • "Downloads" is the number of times a user has clicked to download either an original or cached resource for a particular dataset. Download information is only available from 2nd December 2012; 'No data' is shown for records before that date.
    • +
    • These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.
    • +
    • The results are not shown when the number of views/visits is tiny. Where these relate to site pages, results are available in full in the CSV download. Where these relate to users' web browser information, results are not disclosed, for privacy reasons.
    • +
    +
  • + + --- a/ckanext/ga_report/templates/ga_report/publisher/index.html +++ b/ckanext/ga_report/templates/ga_report/publisher/index.html @@ -7,9 +7,19 @@ Usage by Publisher - - ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publisher_csv',month=c.month or 'all'))} +
  • +

    Download

    +

    + Download as CSV
    +

    +
  • +
  • +

    Graph Legend

    +
    +
    +
  • +
    @@ -25,12 +35,13 @@
    -

    Site Usage ${usage_nav('Publishers')}

    +

    Site Usage

    -
    + ${usage_nav('Publishers')} + ${rickshaw_graph(c.top_publishers_graph,'publishers')} -
    +
    ${month_selector(c.month, c.months, c.day)} @@ -38,21 +49,22 @@ - - - - + + + + - - - - + + + +
    PublisherDataset Views
    PublisherDataset Views
    - ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name) + (("?month=" + c.month) if c.month else ''))} - ${views}
    + ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name) + (("?month=" + c.month) if c.month else ''))} + ${views}
    -
    -
    + + +