Skip to content

Commit

Permalink
Forgot to push untracked files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwalibas committed Jul 19, 2024
1 parent 0e8b47e commit 6769343
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ckanext/googleanalytics/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .utils.numerize import numerize
from ckan.plugins import toolkit


def get_package_stats(package_id):
package_stat = toolkit.get_action('package_stats')({}, {'package_id': package_id})
return numerize(int(package_stat))


def get_resource_stats(resource_id):
resource_stat = toolkit.get_action('resource_stats')({}, {'resource_id': resource_id})
return numerize(int(resource_stat))
11 changes: 11 additions & 0 deletions ckanext/googleanalytics/utils/numerize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def numerize(num):
'''
Shows a number is a human readable format.
Source: https://stackoverflow.com/a/45846841
'''
num = float('{:.3g}'.format(num))
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])

0 comments on commit 6769343

Please sign in to comment.