Exemple #1
0
def hello():
    provider = str(os.environ.get('PROVIDER', 'world'))
    site = os.environ.get('SITE', 'T2_UK_SGrid_Bristol')
    datasets = getSubscriptions(site, test=False)
    template = '{:<50} {:<10} {:<10}'
    lines = [template.format('Name', 'group', 'request')]
    for dataset in datasets:
        name = dataset['name']
        group = dataset['group']
        request = dataset['requested_by_name']
        line = template.format(name, group, request)
        lines.append(line)

    body = '<br>'.join(lines)

    return body
Exemple #2
0
def hello():
    provider = str(os.environ.get('PROVIDER', 'world'))
    site = os.environ.get('SITE', 'T2_UK_SGrid_Bristol')
    datasets = getSubscriptions(site, test=False)
    template = '{:<50} {:<10} {:<10}'
    lines = [template.format('Name', 'group', 'request')]
    for dataset in datasets:
        name = dataset['name']
        group = dataset['group']
        request = dataset['requested_by_name']
        line = template.format(name, group, request)
        lines.append(line)

    body = '<br>'.join(lines)

    return body
Exemple #3
0
def test():
    provider = str(os.environ.get('PROVIDER', 'world'))
    site = os.environ.get('SITE', 'T2_UK_SGrid_Bristol')
    datasets = getSubscriptions(site, test=True)
    template = '{:<50} {:<10} {:<10}'
    lines = [template.format('Name', 'group', 'request')]

    grouped_by_user = datasets.groupby(['requested_by_name'])['bytes_raw'].sum()
    #print datasets.groupby('requested_by_name').groups
    #print grouped.sum()

    for g in grouped_by_user:
        print 'Total', g
    import pandas as pd
    #test = pd.DataFrame({'usage': datasets.groupby(['requested_by_name'])['bytes_raw'].sum()}).reset_index()
    #print test

    test = pd.DataFrame(
        {
            'usage': datasets.groupby(['requested_by_name'])['bytes_raw'].sum()
        }).reset_index()
    #test['group'] = datasets[test['requested_by_name']]
    from units import fmtscaled
    from functools import partial
    scaleUnits = partial(fmtscaled, unit="B")
    #test['usage'] = test['usage'].apply(scaleUnits)
    #print test

#    for dataset in datasets:
#        print dataset.values, dataset
#        name = dataset['name']
#        group = dataset['group']
#        request = dataset['requested_by_name']
#        line = template.format(name, group, request)
#        lines.append(line)
#        break

    body = '<br>'.join(lines)
    #body += '<br> RAW: <br>' + test.to_html()

    return plot(body, test)
Exemple #4
0
def test():
    pd.set_option('display.max_colwidth', -1)
    provider = str(os.environ.get('PROVIDER', 'world'))
    site = os.environ.get('SITE', 'T2_UK_SGrid_Bristol')
    datasets = getSubscriptions(site, test=True)
    template = '{:<50} {:<10} {:<10}'
    lines = [template.format('Name', 'group', 'request')]

    datasets = datasets[datasets['group'] == 'local']

    grouped_by_user = datasets.groupby(['requested_by_name'])
    datasets_by_user = datasets[['requested_by_name', 'name', 'bytes'
                                 ]].groupby(datasets['requested_by_name'])

    test = pd.DataFrame({
        'usage': grouped_by_user['bytes_raw'].sum(),
    }).sort_values('usage', ascending=False).reset_index()

    users = datasets['requested_by_name'].unique()

    datasets_by_user_str = ''
    for user in users:
        data = datasets[datasets['requested_by_name'] == user].sort_values(
            'bytes_raw', ascending=False).reset_index()
        datasets_by_user_str += '<h1>{0}</h1><br >'.format(user)
        datasets_by_user_str += data[['name', 'bytes']].to_html()
        datasets_by_user_str += '<br />'

    from units import fmtscaled
    from functools import partial
    scaleUnits = partial(fmtscaled, unit="B")
    test['usage_scaled'] = test['usage'].apply(scaleUnits)

    body = '<br>'.join(lines)
    body += '<br> RAW: <br>' + test[['requested_by_name', 'usage_scaled'
                                     ]].to_html()
    body += datasets_by_user_str

    body += '<br \>' + plot_bar(test)

    return plot(body, test)