def update_graph3(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) Templ = db_onnections.templateDB(from_data=start_date, to_data=end_date, section=db) Templ = Templ[['typesdisplayname', 'protocol']].copy() Templ = Templ.groupby('typesdisplayname').count() Templ.columns = ['NumberEvents'] Templ['type'] = Templ.index return { 'data': [go.Pie( labels=Templ.type, values=Templ.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='Templates Types', autosize=True, font={ 'color': colors['text'], 'family': 'Glacial Indifference' } ) }
def update_db_(db): FROM = (pd.to_datetime(datetime.datetime.now()) - timedelta(days=140)).strftime("%Y-%m-%d") df = db_onnections.templateDB(from_data=FROM, section=db) df['created_at'] = pd.to_datetime(df['created_at']) return df['created_at'].max()
def update_graph5(yaxis_type, n, db): templ = db_onnections.templateDB(from_data=FROM, section=db) templ['created_at'] = pd.to_datetime(templ['created_at']) alpha = templ.groupby('dispalynametemp').resample('W-Mon', on='created_at').count() alpha = alpha[['vendor']] alpha.columns = ["NumberEvents"] alpha = alpha.reset_index() alpha = alpha.pivot_table(index='created_at', columns='dispalynametemp', values='NumberEvents', aggfunc="sum") alpha = alpha.fillna(0) data = [{ 'x': alpha.index, 'y': alpha[col], 'name': col, 'connectgaps': False, 'fill': "tozeroy", 'opacity': 0.1, 'line': { "shape": "linear", "width": 2 } } for col in alpha.columns] return { 'data': data, 'layout': go.Layout( title='Templates used per Weeks', 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': 'Templates Usage', 'type': 'linear' if yaxis_type == 'Linear' else 'log' }, ) }
def update_graph4(yaxis_type, n, db): Templ = db_onnections.templateDB(from_data=FROM, section=db) Templ['created_at'] = pd.to_datetime(Templ['created_at']) Templ['created_at'] = Templ['created_at'].dt.date alpha = Templ.pivot_table(index='created_at', columns='dispalynametemp', values='vendor', aggfunc="count") 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='Templates Used per Days', 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': 'Templates Usage', 'type': 'linear' if yaxis_type == 'Linear' else 'log' }), }
import flask import pandas as pd import dash import dash_core_components as dcc import dash_html_components as html import plotly.graph_objs as go from datetime import timedelta from datetime import datetime as dt import os import datetime from app import app from apps import db_onnections, general_configurations FROM = (pd.to_datetime(datetime.datetime.now()) - timedelta(days=45)).strftime("%Y-%m-%d") df = db_onnections.templateDB(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 df['created_at']=pd.to_datetime(df['created_at']) dataMax = df['created_at'].max() dataMin = df['created_at'].min() colors = { 'background': '#111111', 'text': '#253471'