# HG changeset patch # User Dennis Fink # Date 2015-10-24 01:45:47 # Node ID 9153e519ff54a8cd610eab6cae8881f9441107ca # Parent acea8f3f6a6fbd9d8a2c516ce816c823009d72d9 Add stats subcommand This is intended for the staff to get some overview diff --git a/ennstatus/cli/commands/__init__.py b/ennstatus/cli/commands/__init__.py --- a/ennstatus/cli/commands/__init__.py +++ b/ennstatus/cli/commands/__init__.py @@ -1,3 +1,4 @@ from .config import config +from .stats import stats -__all__ = ['config'] +__all__ = ['config', 'stats'] diff --git a/ennstatus/cli/commands/stats.py b/ennstatus/cli/commands/stats.py new file mode 100644 --- /dev/null +++ b/ennstatus/cli/commands/stats.py @@ -0,0 +1,37 @@ +import json + +from collections import defaultdict + +import click + +from ennstatus import create_app +from ...status.functions import split_all_servers_to_types + + +@click.group(short_help='Get statistics') +def stats(): + pass + + +@stats.command('countries') +@click.pass_obj +def countries(obj): + app = create_app() + + with app.app_context(): + app.logger.removeHandler(app.logger.handlers[1]) + servers = split_all_servers_to_types() + + countries = defaultdict(int) + + for key, value in servers.items(): + for server in value: + countries[server.country] += 1 + + for key, value in sorted(countries.items(), key=lambda x: x[1]): + click.echo('%s: %s' % (key, value)) + + click.echo('Most servers are in: %s' % max(countries)) + click.echo( + 'We are hosted in %s different countries' % len(countries.keys()) + )