mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/cief-dashboard.git
synced 2026-08-19 04:24:13 +00:00
76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
import dash
|
|
import dash_core_components as dcc
|
|
import dash_html_components as html
|
|
from dash.dependencies import Input, Output, State
|
|
import dash_bootstrap_components as dbc
|
|
import plotly.graph_objects as go
|
|
from dash.exceptions import PreventUpdate
|
|
|
|
import pandas as pd
|
|
import numpy as np
|
|
import plotly.express as px
|
|
import mysql.connector
|
|
|
|
app = dash.Dash(__name__, suppress_callback_exceptions=True,external_stylesheets=[dbc.themes.SLATE])
|
|
server = app.server
|
|
|
|
db_connection = mysql.connector.connect(
|
|
host="localhost",
|
|
user="monty",
|
|
password="so",
|
|
database="mydb",
|
|
auth_plugin='mysql_native_password'
|
|
)
|
|
|
|
def remove_outlier(column, level=1.5):
|
|
q1=column.quantile(0.25)
|
|
q3=column.quantile(0.75)
|
|
gap=q3-q1
|
|
lower_border=q1-gap*level
|
|
upper_border=q3+gap*level
|
|
column.mask(column<lower_border, inplace=True)
|
|
column.mask(column>upper_border, inplace=True)
|
|
|
|
def correct_outlier(column, level=1.5):
|
|
q1=column.quantile(0.25)
|
|
q3=column.quantile(0.75)
|
|
gap=q3-q1
|
|
lower_border=q1-gap*level
|
|
upper_border=q3+gap*level
|
|
column.mask(column<lower_border, other=lower_border, inplace=True)
|
|
column.mask(column>upper_border, other=upper_border, inplace=True)
|
|
|
|
colors = {
|
|
'background': '#111111',
|
|
'text': '#7FDBFF'}
|
|
def update_backgroud(fig):
|
|
fig.update_layout(
|
|
plot_bgcolor=colors['background'],
|
|
paper_bgcolor=colors['background'],
|
|
font_color=colors['text']
|
|
)
|
|
|
|
def remove_grid(fig):
|
|
fig.update_xaxes(showgrid=False)
|
|
fig.update_yaxes(showgrid=False)
|
|
|
|
def update_theme(fig):
|
|
update_backgroud(fig)
|
|
fig.update_xaxes(showgrid=False)
|
|
|
|
def to_json(data):
|
|
if type(data)==dict:
|
|
for i in data:
|
|
data[i]=data[i].to_json()
|
|
elif type(data)==list:
|
|
for i in range(len(data)):
|
|
data[i]=data[i].to_json()
|
|
|
|
def to_df(data):
|
|
if type(data)==dict:
|
|
for i in data:
|
|
data[i]=pd.read_json(data[i])
|
|
elif type(data)==list:
|
|
for i in range(len(data)):
|
|
data[i]=pd.read_json(data[i])
|