def index(): stats = stats_lib.Stats() extra_vars = { u'largest_groups': stats.largest_groups(), u'top_tags': stats.top_tags(), u'top_package_creators': stats.top_package_creators(), } return render(u'ckanext/stats/index.html', extra_vars)
def top_tags(self): response.content_type = 'application/json; charset=UTF-8' stats = stats_lib.Stats() top_tags = stats.top_tags() data = {} for tag, num_packages in top_tags: data[tag.name] = str(num_packages) data = {"top_tags" : json.dumps(data, ensure_ascii=False)} return json.dumps(data)
def index(): stats = stats_lib.Stats() extra_vars: dict[str, Any] = { 'largest_groups': stats.largest_groups(), 'top_tags': stats.top_tags(), 'top_package_creators': stats.top_package_creators(), 'most_edited_packages': stats.most_edited_packages(), 'new_packages_by_week': stats.get_by_week('new_packages'), 'deleted_packages_by_week': stats.get_by_week('deleted_packages'), 'num_packages_by_week': stats.get_num_packages_by_week(), 'package_revisions_by_week': stats.get_by_week('package_revisions') } extra_vars['raw_packages_by_week'] = [] for week_date, num_packages, cumulative_num_packages\ in stats.get_num_packages_by_week(): extra_vars['raw_packages_by_week'].append({ 'date': h.date_str_to_datetime(week_date), 'total_packages': cumulative_num_packages }) extra_vars['raw_all_package_revisions'] = [] for week_date, _revs, num_revisions, _cumulative_num_revisions\ in stats.get_by_week('package_revisions'): extra_vars['raw_all_package_revisions'].append({ 'date': h.date_str_to_datetime(week_date), 'total_revisions': num_revisions }) extra_vars['raw_new_datasets'] = [] for week_date, _pkgs, num_packages, _cumulative_num_revisions\ in stats.get_by_week('new_packages'): extra_vars['raw_new_datasets'].append({ 'date': h.date_str_to_datetime(week_date), 'new_packages': num_packages }) extra_vars['raw_deleted_datasets'] = [] for week_date, _pkgs, num_packages, cumulative_num_packages\ in stats.get_by_week('deleted_packages'): extra_vars['raw_deleted_datasets'].append({ 'date': h.date_str_to_datetime(week_date), 'deleted_packages': num_packages }) return render(u'ckanext/stats/index.html', extra_vars)
def index(): stats = stats_lib.Stats() rev_stats = stats_lib.RevisionStats() c.top_rated_packages = stats.top_rated_packages() c.most_edited_packages = stats.most_edited_packages() c.largest_groups = stats.largest_groups() c.top_tags = stats.top_tags() c.top_package_creators = stats.top_package_creators() c.new_packages_by_week = rev_stats.get_by_week(u'new_packages') c.deleted_packages_by_week = rev_stats.get_by_week(u'deleted_packages') c.num_packages_by_week = rev_stats.get_num_packages_by_week() c.package_revisions_by_week = rev_stats.get_by_week(u'package_revisions') c.raw_packages_by_week = [] for ( week_date, num_packages, cumulative_num_packages ) in c.num_packages_by_week: c.raw_packages_by_week.append({ u'date': h.date_str_to_datetime(week_date), u'total_packages': cumulative_num_packages }) c.all_package_revisions = [] c.raw_all_package_revisions = [] for ( week_date, revs, num_revisions, cumulative_num_revisions ) in c.package_revisions_by_week: c.all_package_revisions.append( u'[new Date(%s), %s]' % (week_date.replace(u'-', u','), num_revisions) ) c.raw_all_package_revisions.append({ u'date': h.date_str_to_datetime(week_date), u'total_revisions': num_revisions }) c.new_datasets = [] c.raw_new_datasets = [] for ( week_date, pkgs, num_packages, cumulative_num_packages ) in c.new_packages_by_week: c.new_datasets.append( u'[new Date(%s), %s]' % (week_date.replace(u'-', u','), num_packages) ) c.raw_new_datasets.append({ u'date': h.date_str_to_datetime(week_date), u'new_packages': num_packages }) return render(u'ckanext/stats/index.html')
def mlg_top_tags(showtags=10): import ckanext.stats.stats as ckanstats classtags = ckanstats.Stats() return classtags.top_tags(limit=showtags)
def index(self): stats = stats_lib.Stats() rev_stats = stats_lib.RevisionStats() stats_response = { 'top_rated_packages': stats.top_rated_packages(), 'most_edited_packages': [], 'largest_groups': [], 'top_tags': [], 'top_package_creators': [], 'new_packages_by_week': rev_stats.get_by_week('new_packages'), 'deleted_packages_by_week': rev_stats.get_by_week('deleted_packages'), 'num_packages_by_week': rev_stats.get_num_packages_by_week(), 'package_revisions_by_week': rev_stats.get_by_week('package_revisions'), 'raw_packages_by_week': [], 'all_package_revisions': [], 'raw_all_package_revisions': [], 'new_datasets': [], 'raw_new_datasets': [], } for p in stats.most_edited_packages(): stats_response['most_edited_packages'].append({ 'title': p[0].title, 'name': p[0].name, 'count': p[1] }) for p in stats.largest_groups(): stats_response['largest_groups'].append({ 'title': p[0].title, 'name': p[0].name, 'count': p[1] }) for p in stats.top_tags(): stats_response['top_tags'].append({ 'name': p[0].name, 'count': p[1] }) for p in stats.top_package_creators(): stats_response['top_package_creators'].append({ 'id': p[0].id, 'name': p[0].name, 'fullname': p[0].fullname, 'gravatar': hashlib.md5(p[0].email.lower()).hexdigest(), 'count': p[1] }) for week_date, num_packages, cumulative_num_packages in stats_response[ 'num_packages_by_week']: stats_response['raw_packages_by_week'].append({ 'date': week_date, 'total_packages': cumulative_num_packages }) for week_date, revs, num_revisions, cumulative_num_revisions in stats_response[ 'package_revisions_by_week']: stats_response['all_package_revisions'].append( '[%s, %s]' % (week_date, num_revisions)) stats_response['raw_all_package_revisions'].append({ 'date': week_date, 'total_revisions': num_revisions }) for week_date, pkgs, num_packages, cumulative_num_packages in stats_response[ 'new_packages_by_week']: stats_response['new_datasets'].append('[%s, %s]' % (week_date, num_packages)) stats_response['raw_new_datasets'].append({ 'date': week_date, 'new_packages': num_packages }) return json.dumps(stats_response)