Exemplo n.º 1
0
def update_timeSeries_graph(json_data, var):
    try:
        # call dat
        df = pd.read_json(json_data)
        colname = [col for col in df.columns if var in col]
        df = df[colname]

        fig = get_ts_plot(df, yaxis_label='')
        return fig
    except:
        return []
Exemplo n.º 2
0
def update_corr_graph(json_data, step):
    try:
        df = pd.read_json(json_data).copy()
        # current vs power corr
        for i in range(1, 4):
            df[f'Corr{i}'] = df[f'S{i}'].rolling(step).corr(
                df[f'I{i}'].rolling(step))
        df_corr = df[[col for col in df.columns if 'Corr' in col]].copy()
        fig_corr = get_ts_plot(df_corr, yaxis_label=' ', hover_mode='x')
        return fig_corr
    except:
        return []
Exemplo n.º 3
0
def update_gas_graph(json_data):
    try:
        df_gas = pd.read_json(json_data)
        df_gas = df_gas[['CH4', 'C2H2', 'C2H4', 'C2H6', 'H2']]
        # plotting
        fig = get_ts_plot(df_gas,
                          yaxis_label='ppm',
                          convert_x=False,
                          drag_mode='select')
        return fig
    except:
        return []
Exemplo n.º 4
0
def update_volt_excurs_graph(json_data, ma_win):
    try:
        # call data
        df_trans = pd.read_json(json_data).copy()

        # compute excursion percentage
        df_1 = get_excur_percent(df_trans, ma_win, channel='V')

        # plotting
        fig = get_ts_plot(df_1, yaxis_label='% Change (from MA)')
        return fig
    except:
        return []
Exemplo n.º 5
0
def update_pf_graph(json_data):
    try:
        df = pd.read_json(json_data).copy()

        # power factor
        df_P = df[[col for col in df.columns if 'P' in col]].copy()
        df_S = df[[col for col in df.columns if 'S' in col]].copy()

        df_pf = df_P.values / df_S.values
        df_pf = pd.DataFrame(df_pf,
                             index=df_P.index,
                             columns=['Pf1', 'Pf2', 'Pf3'])
        fig_pf = get_ts_plot(df_pf, yaxis_label=' ', hover_mode='x')
        return fig_pf
    except:
        return []
Exemplo n.º 6
0
def generate_pv_plot(json_data):
    try:
        datasets = json.loads(json_data)
        df_load = pd.read_json(datasets['df_load'])
        # df_temp = df_load.dropna()
        df_load = df_load[['Power Demand', 'PV Production']]
        df_load.index = pd.to_datetime(df_load.index, errors='coerce')
        # df_trunc = df_combined.iloc[-60:,:].copy()
        df_trunc = df_load[df_load.index > df_load.index[-1] -
                           timedelta(hours=60)].copy()
        fig = get_ts_plot(df_trunc, yaxis_label='Power [KW]')
        pv_peak = round(get_pv_peak(df_load['PV Production']), 3)

        # evaluate performance
        return fig, 'Note: PV is estimated based on GHI, Power Peak (past 60 days) and Real Power.', pv_peak
    except:
        return [], 'Loading...', 0
Exemplo n.º 7
0
def update_average_graph(datetype, json_data, var):
    df = pd.read_json(json_data)
    df = df[[col for col in df.columns if var in col]]

    if datetype == 'Month':
        df = df.groupby(df.index.month).mean()
        df.index = df.index.map(lambda x: calendar.month_name[x])
    elif datetype == 'Hour':
        df = df.groupby(df.index.hour).mean()

    elif datetype == 'Dai':
        df = df.groupby(df.index.day).mean()
    else:
        df = df.groupby(df.index.dayofweek).mean()
        df.index = df.index.map(lambda x: calendar.day_name[x])

    fig = get_ts_plot(df, yaxis_label='', convert_x=False, xtick=1)
    return fig
Exemplo n.º 8
0
def update_normalized_graph(json_data, phase, var):
    try:
        df = pd.read_json(json_data)
        if var != 'All':
            df = df[[col for col in df.columns if var in col]]
        else:
            pass
        if phase != 'All':
            # filter by phase
            df = df[[col for col in df.columns if col[-1] == str(phase)]]
        else:
            pass

        df_zs = (df - df.mean()) / df.std()
        fig = get_ts_plot(df_zs, yaxis_label='z-score')
        return fig
    except:
        return []
Exemplo n.º 9
0
def update_tsbox_graph(rows, selectedRows, json_data):
    try:
        # call data according to selected station
        df = pd.read_json(json_data)
        df_selected = pd.DataFrame(rows).loc[selectedRows]

        df_selected['target'] = df_selected['Station'] + '__' + df_selected[
            'Variable (phase)']
        df = df[[
            col for col in df.columns if col in df_selected['target'].unique()
        ]]

        # plotting
        fig_ts = get_ts_plot(df,
                             yaxis_label=' ',
                             convert_x=False,
                             xaxis_label=' ')
        fig_box = get_box_plot(df, y_label=' ')
        return fig_ts, fig_box
    except:
        return [], []
Exemplo n.º 10
0
def generate_real_time_plot(json_data):
    try:
        datasets = json.loads(json_data)
        df_combined = pd.read_json(datasets['df_combined'])

        df_combined.index = pd.to_datetime(df_combined.index, errors='coerce')
        df_trunc = df_combined[df_combined.index > df_combined.index[-1] -
                               timedelta(hours=60)].copy()

        df_t = df_combined.dropna()
        fig = get_ts_plot(df_trunc,
                          yaxis_label='Active Power [kW]',
                          hover_mode='closest')

        r2 = r2_score(df_t[df_t.columns[0]], df_t[df_t.columns[1]])
        rmse = np.sqrt(
            mean_squared_error(df_t[df_t.columns[0]], df_t[df_t.columns[1]]))
        mae = mean_absolute_error(df_t[df_t.columns[0]], df_t[df_t.columns[1]])
        fc_p = 'Performance: r2 = {}______RMSE = {}______MAE = {}'.format(
            round(r2, 3), round(rmse, 3), round(mae, 3))
        return fig, fc_p
    except:
        return [], 'Loading...'
Exemplo n.º 11
0
def update_dev_graph(json_data, var):
    try:
        # call data
        df = pd.read_json(json_data)
        df = df[[col for col in df.columns if var in col]]

        # comptue MAD
        df_mad = df.mad(axis=1)
        alpha = 1 - 0.1
        idx = get_sh_esd(df_mad, alpha=alpha)

        # get outlier
        if idx != None:
            df_out = df_mad[idx]
            fig = get_ts_plot_outlier(df_mad, df_out, yaxis_label='MAD')
        else:
            fig = get_ts_plot(
                df_mad,
                title='Anamoly Detection of Unbalances in {}'.format(var),
                yaxis_label='MAD',
            )
        return fig
    except:
        return []
Exemplo n.º 12
0
def update_co_ratio_graph(json_data):
    try:
        #ratio
        df_gas = pd.read_json(json_data)

        # CO2/CO figure
        df_r1 = pd.DataFrame({
            'CO2/CO': df_gas['CO2'] / df_gas['CO'],
            'th': 3.0,
        })
        df_r1.replace([np.inf, np.nan], 0, inplace=True)
        fig_co = get_ts_plot(df_r1,
                             yaxis_label='',
                             convert_x=False,
                             legend_bool=False)

        # C2H2/H2 ratio plot
        df_r2 = pd.DataFrame({
            'C2H2/H2': df_gas['C2H2'] / df_gas['H2'],
            'low_th': 2.0,
            'high_th': 3.0,
        })
        df_r2.replace([np.inf, np.nan], 0, inplace=True)
        fig_ch = get_ts_plot(df_r2,
                             yaxis_label='',
                             convert_x=False,
                             legend_bool=True)

        # O2/N2 ratio plot
        df_r3 = pd.DataFrame({'O2/N2': df_gas['O2'] / df_gas['N2']})
        df_r3.replace([np.inf, np.nan], 0, inplace=True)
        fig_on = get_ts_plot(df_r3,
                             yaxis_label='',
                             convert_x=False,
                             legend_bool=False)

        # error log details
        report = [
            html.H2('Analytic Result for DGA', className='test-center'),
        ]
        # for CO
        for i in df_r1[df_r1['CO2/CO'] < 3].index.tolist():
            report.append(
                html.Div('[{}]: Paper Fault (CO2/CO ratio)'.format(i), ))
        # for C2H2/H2
        for i in df_r2[(df_r2['C2H2/H2'] > 2)
                       & (df_r2['C2H2/H2'] < 3)].index.tolist():
            print(i)
            report.append(
                html.Div(
                    '[{}]: LTC Contamination (C2H2/H2 ratio)'.format(i), ))
        # for O2/N2
        df_r3['decreasing'] = np.nan
        for i in range(len(df_r3)):
            x = df_r3.iloc[i:i + 4, 0]
            if ((x.empty) | (x.mean() == 0)):
                df_r3.iloc[i, -1] = np.nan
            else:
                df_r3.iloc[i, -1] = x.is_monotonic_decreasing

        # for C2H2/H2
        for i in df_r3[df_r3['decreasing'].diff() == 1].index.tolist():
            print(i)
            report.append(
                html.Div(
                    '[{}]: Excessive Heating (Decreasing O2/N2 ratio)'.format(
                        i), ))

        return fig_co, fig_ch, fig_on, report
    except:
        return [], [], [], []