Changeset - df1ad42ffdc0
[Not reviewed]
feature-cli
0 1 0
Dennis Fink - 9 years ago 2016-03-05 19:19:31
dennis.fink@c3l.lu
Added exit_probability command
1 file changed with 56 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/cli/commands/stats.py
Show inline comments
 
@@ -166,3 +166,59 @@ def countries(obj, by_type):
 
                    )
 
                )
 
            )
 

	
 

	
 
@stats.command('exit_probability')
 
@click.option('--by-server', 'by_server', is_flag=True, default=False)
 
@click.pass_obj
 
def exit_probability(obj, by_server):
 

	
 
    app = create_app()
 
    with app.app_context():
 
        app.logger.disabled = True
 
        servers = split_all_servers_to_types()
 

	
 
    if not by_server:
 
        exit_probability = defaultdict(int)
 
        for server in servers['exit']:
 
            for subkey in ('1_week', '1_month', '3_months', '1_year', '5_years'):
 
                if server.mean_exit_probability[subkey] is not None:
 
                    exit_probability[subkey] += server.mean_exit_probability[subkey]
 

	
 
        for subkey in ('1_week', '1_month', '3_months', '1_year', '5_years'):
 
            click.echo(
 
                'Mean exit probability over %s: %s' % (
 
                    click.style(
 
                        subkey,
 
                        fg='blue'
 
                    ),
 
                    click.style(
 
                        str(round(exit_probability[subkey], 2)) + '%',
 
                        fg='red'
 
                    )
 
                )
 
            )
 
    else:
 
        for server in servers['exit']:
 
            click.echo(
 
                click.style(
 
                    server.name.capitalize(),
 
                    fg='red',
 
                    bold=True,
 
                    underline=True
 
                )
 
            )
 
            for subkey in ('1_week', '1_month', '3_months', '1_year', '5_years'):
 
                if server.mean_exit_probability[subkey] is not None:
 
                    click.echo(
 
                        'Mean exit probabilty over %s: %s' % (
 
                            click.style(
 
                                subkey,
 
                                fg='blue'
 
                            ),
 
                            click.style(
 
                                str(round(server.mean_exit_probability[subkey], 2)) + "%",
 
                                fg='red'
 
                            )
 
                        )
 
                    )
0 comments (0 inline, 0 general)