示例#1
0
def updatetask1(start_date, end_date, n, db):
    start_date = pd.to_datetime(start_date)
    start_date = dt.date(start_date)
    end_date = pd.to_datetime(end_date)
    end_date = dt.date(end_date)

    Tasks = db_onnections.tasksDB(from_data=start_date,
                                  to_data=end_date,
                                  section=db)

    Tasks = Tasks[['args.task_name', 'name']].copy()
    Tasks = Tasks.groupby('args.task_name').count()
    Tasks.columns = ['NumberEvents']
    Tasks['Name'] = Tasks.index

    return {
        'data': [
            go.Pie(labels=Tasks.Name,
                   values=Tasks.NumberEvents,
                   pull=.1,
                   hole=.1,
                   hoverinfo='label+percent',
                   textinfo='label',
                   showlegend=True,
                   marker=dict(colors=colors,
                               line=dict(color='#000000', width=1)))
        ],
        'layout':
        go.Layout(title='Tasks Frequency',
                  autosize=True,
                  font={
                      'family': 'Glacial Indifference',
                      'color': colors['text']
                  })
    }
示例#2
0
def update_db_(db):
    from_data = (pd.to_datetime(datetime.datetime.now()) -
                 timedelta(days=160)).strftime("%Y-%m-%d")
    data = db_onnections.tasksDB(from_data=from_data, section=db)

    data['event_time'] = pd.to_datetime(data['event_time'])

    return data['event_time'].max() - timedelta(days=14)
示例#3
0
def update_graph6(n, db):
    Templ = db_onnections.tasksDB(from_data=FROM, section=db)
    Templ['event_time'] = pd.to_datetime(Templ['event_time'])
    alpha = Templ.groupby('args.task_name').resample('W-Mon', on='event_time').count()
    alpha = alpha[['args.task_name']]
    alpha.columns = ["NumberEvents"]
    alpha = alpha.reset_index()

    alpha = alpha.pivot_table(index='event_time', columns='args.task_name', values='NumberEvents', aggfunc="sum")
    alpha = alpha.fillna(0)

    data = [{
        'x': alpha.index,
        'y': alpha[col],
        'name': col,
        'connectgaps': False,
        'fill': "tozeroy",
        'line': {
            "shape": "linear",
            "width": 2}
    } for col in alpha.columns]

    return {

        'data': data,
        'layout': go.Layout(
            title='Each Tasks over Time per Week',
            font={'color': colors['text'], 'family': 'Glacial Indifference'},
            xaxis=dict(
                rangeselector=dict(
                    buttons=list([
                        dict(count=1,
                             label='1m',
                             step='month',
                             stepmode='todate'),
                        dict(count=6,
                             label='6m',
                             step='month',
                             stepmode='backward'),
                        dict(count=1,
                             label='YTD',
                             step='year',
                             stepmode='todate'),
                        dict(count=1,
                             label='1y',
                             step='year',
                             stepmode='backward'),
                        dict(step='all')
                    ])
                ),
                rangeslider=dict(),
                type='date'),
            yaxis={
                'title': 'Tasks per Week',
                'type': 'linear'
            }),
    }
示例#4
0
def themeriverbuildertasks(db):
    '''
    construct for the FLask streamline
    '''
    from_data = (pd.to_datetime(datetime.datetime.now()) -
                 timedelta(days=160)).strftime("%Y-%m-%d")
    data = db_onnections.tasksDB(from_data=from_data, section=db)

    data['event_time'] = pd.to_datetime(data['event_time'])

    from_data = (data['event_time'].max() -
                 timedelta(days=21)).strftime("%Y-%m-%d")

    Templ = db_onnections.tasksDB(from_data=from_data, section=db)
    # if the entry is empty
    if Templ.empty:
        return None

    Templ['event_time'] = pd.to_datetime(Templ['event_time'])

    alpha = Templ.groupby('args.task_name').resample('D',
                                                     on='event_time').count()
    alpha = alpha[['args.task_name']]
    alpha.columns = ["NumberEvents"]

    ######################################
    # To remember the echart lib expect  #
    # an entry for each day for each     #
    # label serie and day                #
    ######################################

    alpha = alpha.reset_index()
    alpha['event_time'] = alpha['event_time'].dt.strftime('%Y/%m/%d')
    alpha['event_time'] = alpha['event_time'].apply(str)
    alpha['NumberEvents'] = alpha['NumberEvents'].apply(str)

    alpha['output'] = '["' + alpha['event_time'] + '",' + alpha[
        'NumberEvents'] + ',"' + alpha['args.task_name'] + '"]'

    events = '{}'.format(alpha.output.values)
    events = events.replace("\' \'", ",")
    events = events.replace("\'\n \'", ",")
    events = events.replace("\'", "")
    return events
示例#5
0
def update_graph5(n, db):
    Templ = db_onnections.tasksDB(from_data=FROM, section=db)

    Templ = Templ.groupby('event_time')[['event_time']].count()

    Templ['Day'] = Templ.index
    Templ['Day'] = pd.to_datetime(Templ['Day'])
    alpha = Templ.resample('W-Mon', on='Day').sum()
    data = [{
        'x': alpha.index,
        'y': alpha[col],
        'name': col,
        'connectgaps': False,
        'fill': "tozeroy",
        "fillcolor": "rgb(217,217,217)",
        'line': {
            "shape": "linear",
            "color": "rgb(37, 52, 113)",
            "width": 2}
    } for col in alpha.columns]

    return {
        'data': data,
        'layout': go.Layout(
            title='Tasks over Time per Week',
            font={'color': colors['text'], 'family': 'Glacial Indifference'},
            xaxis=dict(
                rangeselector=dict(
                    buttons=list([
                        dict(count=1,
                             label='1m',
                             step='month',
                             stepmode='todate'),
                        dict(count=6,
                             label='6m',
                             step='month',
                             stepmode='backward'),
                        dict(count=1,
                             label='YTD',
                             step='year',
                             stepmode='todate'),
                        dict(count=1,
                             label='1y',
                             step='year',
                             stepmode='backward'),
                        dict(step='all')
                    ])
                ),
                rangeslider=dict(),
                type='date'),
            yaxis={
                'title': 'Tasks per Week',
                'type': 'linear'
            }
        ),
    }
示例#6
0
def update_index1(start_date, end_date, db):

    start_date = pd.to_datetime(start_date)
    start_date = dt.date(start_date)
    end_date = pd.to_datetime(end_date)
    end_date = dt.date(end_date)

    tempdf = db_onnections.tasksDB(from_data=start_date,
                                   to_data=end_date,
                                   section=db)

    available_users = sorted(tempdf['args.actioned_by_username'].unique())
    return [{'label': i, 'value': i} for i in available_users]
示例#7
0
def update_userlab(start_date, end_date, db):

    start_date = pd.to_datetime(start_date)
    start_date = dt.date(start_date)
    end_date = pd.to_datetime(end_date)
    end_date = dt.date(end_date)

    tempdf = db_onnections.tasksDB(from_data=start_date,
                                   to_data=end_date,
                                   section=db)

    available_users = sorted(tempdf['args.actioned_by_username'].unique())

    return available_users[0]
示例#8
0
def tasksparkline(from_data, db):
    from apps import db_onnections

    templ = db_onnections.tasksDB(from_data=from_data, section=db)
    templ['event_time'] = pd.to_datetime(templ['event_time'])
    alpha = templ.resample('W-Mon', on='event_time').count()
    alpha = alpha[['args.task_name']]
    alpha.columns = ["NumberEvents"]
    # Add value for missing weeks
    alpha = alpha.reset_index()
    max_ = alpha.NumberEvents.max()
    events = alpha.NumberEvents
    events = "{}".format(events.values).replace(" ",
                                                ",").replace('[', '').replace(
                                                    ']', '').replace('\n', '')
    return events, max_
示例#9
0
def update_task2(user, start_date, end_date, n, db):
    start_date = pd.to_datetime(start_date)
    start_date = dt.date(start_date)
    end_date = pd.to_datetime(end_date)
    end_date = dt.date(end_date)

    Data = db_onnections.tasksDB(from_data=start_date,
                                 to_data=end_date,
                                 section=db)
    Tasks = Data[Data['args.actioned_by_username'] == user].copy()

    Tasks['event_time'] = Tasks['event_time'].dt.date
    Tasks = Tasks[Tasks['event_time'] >= start_date]
    Tasks = Tasks[Tasks['event_time'] <= end_date]

    Tasks = Tasks[['args.task_name', 'name']].copy()

    Tasks = Tasks.groupby('args.task_name').count()
    Tasks.columns = ['NumberEvents']
    Tasks['Name'] = Tasks.index

    return {
        'data': [
            go.Pie(labels=Tasks.Name,
                   values=Tasks.NumberEvents,
                   pull=.1,
                   hole=.1,
                   hoverinfo='label+percent',
                   textinfo='label',
                   showlegend=False,
                   marker=dict(colors=colors,
                               line=dict(color='#000000', width=1)))
        ],
        'layout':
        go.Layout(title='Tasks Performed by {}'.format(user),
                  font={
                      'family': 'Glacial Indifference',
                      'color': colors['text']
                  })
    }
示例#10
0
def update_task4(user, start_date, end_date, n, db):
    start_date = pd.to_datetime(start_date)
    start_date = dt.date(start_date)
    end_date = pd.to_datetime(end_date)
    end_date = dt.date(end_date)

    DataUser = db_onnections.tasksDB(from_data=start_date,
                                     to_data=end_date,
                                     section=db)

    DataUser['event_time'] = DataUser['event_time'].dt.date
    DataUser = DataUser[DataUser['event_time'] >= start_date]
    DataUser = DataUser[DataUser['event_time'] <= end_date]

    DataUser = DataUser[DataUser['args.actioned_by_username'] == user]
    TaskNode = DataUser[['args.task_name']].copy()
    TaskNode = TaskNode.drop_duplicates()
    TaskNode.columns = ['Nome_nodo']

    UserNode = DataUser[['args.actioned_by_username']].copy()
    UserNode = UserNode.drop_duplicates()
    UserNode.columns = ['Nome_nodo']

    DeviceNode = DataUser[['args.device_display_name']].copy()
    DeviceNode = DeviceNode.drop_duplicates()
    DeviceNode.columns = ['Nome_nodo']

    nodes = pd.concat([TaskNode, UserNode, DeviceNode], axis=0)
    refrenza = [x for x in range(0, nodes.shape[0])]
    nodesDict = dict(zip(nodes.Nome_nodo, refrenza))

    links = DataUser[[
        'args.task_name', 'args.actioned_by_username',
        'args.device_display_name'
    ]].copy()
    links = links[links['args.actioned_by_username'] != 'nan']
    links = links[links['args.actioned_by_username'] != 'enzo_server']
    links = links[links['args.task_name'] != 'nan']

    links = links.groupby(['args.task_name', 'args.device_display_name'],
                          as_index=False).count()
    links['value'] = links['args.actioned_by_username']
    links['source'] = links['args.task_name'].map(nodesDict)
    links['target'] = links['args.device_display_name'].map(nodesDict)
    links = links[['source', 'target', 'value']]

    links2 = DataUser[['args.task_name', 'args.actioned_by_username',
                       'name']].copy()
    links2 = links2[links2['args.task_name'] != 'nan']

    links2 = links2[links2['args.actioned_by_username'] != 'nan']
    links2 = links2[links2['args.actioned_by_username'] != 'enzo_server']

    links2 = links2.groupby(['args.task_name', 'args.actioned_by_username'],
                            as_index=False).count()
    links2['value'] = links2['name']
    links2['source'] = links2['args.actioned_by_username'].map(nodesDict)
    links2['target'] = links2['args.task_name'].map(nodesDict)
    links2 = links2[['source', 'target', 'value']]
    links = pd.concat([links, links2], axis=0)

    return {
        'data': [
            dict(
                type="sankey",
                domain=dict(x=[0, 1], y=[0, 1]),
                link={
                    "source": links.source.dropna(axis=0, how='any'),
                    "target": links.target.dropna(axis=0, how='any'),
                    "value": links['value'].dropna(axis=0, how='any')
                },
                node=dict(label=nodes.Nome_nodo, pad=6, thickness=20),
            )
        ],
        'layout':
        go.Layout(title="Sankey Diagram for {}".format(user),
                  autosize=True,
                  font={
                      'family': 'Glacial Indifference',
                      'color': colors['text']
                  })
    }
示例#11
0
from app import app
from apps import db_onnections, general_configurations

colors = {
    'background': '#111111',
    'text': '#253471',
}

image_filename = os.getcwd() + '/pics//enzo_logo.png'
encoded_image = base64.b64encode(open(image_filename, 'rb').read())

FROM = (pd.to_datetime(datetime.datetime.now()) -
        timedelta(days=90)).strftime("%Y-%m-%d")

Data = db_onnections.tasksDB(from_data=FROM,
                             section=general_configurations.Current_active_DB)

list_db = db_onnections.list_dbs()

# Enable the DB selector
if len(list_db) == 1:
    enable_db_selector = True
else:
    enable_db_selector = False

# if Data.empty:
#     layout = html.Div([
#         html.Div([
#             html.A(
#                 html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode()), style={
#                     'height': '20px',
示例#12
0
    'background': '#111111',
    'text': '#253471',
}

list_db = db_onnections.list_dbs()

# Enable the DB selector
if len(list_db) == 1:
    enable_db_selector = True
else:
    enable_db_selector = False

image_filename = os.getcwd() + '/pics//enzo_logo.png'
encoded_image = base64.b64encode(open(image_filename, 'rb').read())

Data = db_onnections.tasksDB(section=general_configurations.Current_active_DB)
# if Data.empty:
#     layout = html.Div([
#         html.Div([
#             html.A(
#                 html.Img(src='data:image/png;base64,{}'.format(encoded_image.decode()), style={
#                     'height': '20px',
#                     'float': 'left',
#                     'position': 'relative',
#                     'bottom': '-10px',
#                     'width': '100px',
#                 }), href='/', target="_self"),
#             html.H1(
#                 children="Analytics Menu",
#
#                 style={