Changeset - 9153e519ff54
[Not reviewed]
feature-cli
0 1 1
Dennis Fink - 9 years ago 2015-10-24 01:45:47
dennis.fink@c3l.lu
Add stats subcommand

This is intended for the staff to get some overview
2 files changed with 39 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/cli/commands/__init__.py
Show inline comments
 
from .config import config
 
from .stats import stats
 

	
 
__all__ = ['config']
 
__all__ = ['config', 'stats']
ennstatus/cli/commands/stats.py
Show inline comments
 
new file 100644
 
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())
 
    )
0 comments (0 inline, 0 general)