Exemplo n.º 1
0
def algorithms_sarima():
    text = desc_list['08sarima']

    form = FormSARIMA()

    if form.validate_on_submit():
        filename = secrets.token_hex(8) + '.csv'
        form.dados.data.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file_url = files.url(filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        # Retrieving results from the form
        p = form.p.data
        q = form.q.data
        d = form.d.data
        ptest = form.percent_test.data

        P = form.P.data
        Q = form.Q.data
        D = form.D.data
        s = form.sazon.data

        predict_range = form.predict_range.data

        # Get data from file
        separator = form.sep.data
        serie, rd, quality_param = deal_inputs(file_path,
                                               filename,
                                               form,
                                               isseries=True)

        # Generate plot
        elementos, img_name_diag, img_name_mse, img_name_forecast, df_output = fit_sarima(
            serie, p, d, q, P, D, Q, s, ptest, predict_range)

        image_file_diag = url_for('static', filename='images/' + img_name_diag)
        image_file_mse = url_for('static', filename='images/' + img_name_mse)
        image_file_forecast = url_for('static',
                                      filename='images/' + img_name_forecast)

        ### Create report

        # Report title
        title = dict_lista['08sarima']['title']

        # Model parameters
        model_param = [['p', str(p)], ['d', str(d)], ['q', str(q)],
                       ['P', str(P)], ['D', str(D)], ['Q', str(Q)],
                       ['s', str(s)], ['Dados para Teste (%)',
                                       str(ptest)],
                       ['Dados Preditos', str(predict_range)]]
        readdata_param = readdata_table(form)
        summary_param = summary_maincol(serie)
        file_title = 'sarima'
        address_pdf = create_report_arima(
            title, model_param, readdata_param, quality_param, summary_param,
            [img_name_diag, img_name_mse, img_name_forecast], file_title,
            elementos)

        # Generate array of values

        # Create csv for downloading
        address_csv = '%s_%s.csv' % (file_title, secrets.token_hex(6))

        mydir = os.path.join(dir, 'static', 'reports', address_csv)

        df_output.to_csv(mydir,
                         sep=separator,
                         index=True,
                         encoding='utf-8-sig',
                         header=['Dado_predito'])

        rd = list(df_output.index)
        pred = list(df_output)

        return render_template('algorithms_sarima_output.html',
                               title='SARIMA',
                               text=text,
                               form=form,
                               file_url=file_url,
                               p=p,
                               q=q,
                               d=d,
                               P=P,
                               D=D,
                               Q=Q,
                               s=s,
                               listap=list(range(p)),
                               listaq=list(range(q)),
                               listaP=list(range(P)),
                               listaQ=list(range(Q)),
                               ptest=ptest,
                               range=predict_range,
                               image_diag=image_file_diag,
                               image_mse=image_file_mse,
                               image_forecast=image_file_forecast,
                               address_pdf=address_pdf,
                               address_csv=address_csv,
                               result_data=elementos,
                               rd=rd,
                               pred=pred)

    else:
        file_url = None

    return render_template('algorithms_sarima.html',
                           title='SARIMA',
                           text=text,
                           form=form,
                           file_url=file_url)
Exemplo n.º 2
0
def algorithms_diff():
    text = desc_list['07diff']

    form = FormDiff()

    if form.validate_on_submit() and request.method == 'POST':
        filename = secrets.token_hex(8) + '.csv'
        form.dados.data.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file_url = files.url(filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        # Retrieving results from the form
        order = form.diff.data

        # Get data from file
        separator = form.sep.data
        serie, rd, quality_param = deal_inputs(file_path,
                                               filename,
                                               form,
                                               isseries=True)

        # Generate plot and array of values
        img_name, diff_data, df_output = diff(serie, order, rd)

        image_file = url_for('static', filename='images/' + img_name)

        ### Create report

        # Report title
        title = dict_lista['07diff']['title']

        # Model parameters
        model_param = [['Ordem', str(order)]]
        readdata_param = readdata_table(form)
        summary_param = summary_maincol(serie)
        file_title = 'diff'
        address_pdf = create_report(title, model_param, readdata_param,
                                    quality_param, summary_param, [img_name],
                                    file_title)

        # Create csv for downloading
        address_csv = '%s_%s.csv' % (file_title, secrets.token_hex(6))

        mydir = os.path.join(dir, 'static', 'reports', address_csv)

        df_output.to_csv(mydir,
                         sep=separator,
                         index=False,
                         encoding='utf-8-sig')

        return render_template('algorithms_diff_output.html',
                               title='Diferença',
                               text=text,
                               form=form,
                               file_url=file_url,
                               order=order,
                               image=image_file,
                               data_diff=diff_data,
                               raw_data=rd,
                               address_pdf=address_pdf,
                               address_csv=address_csv)

    else:
        file_url = None

    return render_template('algorithms_diff.html',
                           title='Diferença',
                           text=text,
                           form=form,
                           file_url=file_url)
Exemplo n.º 3
0
def algorithms_decomposition():
    text = desc_list['03decomposition']

    form = FormDecomposition()

    if form.validate_on_submit():
        filename = secrets.token_hex(8) + '.csv'
        form.dados.data.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file_url = files.url(filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        # Retrieving results from the form
        model = form.model.data
        frequencia = form.sazon.data

        ts = form.reference.data
        if ts == 'center':
            two_sided = True
        elif ts == 'right':
            two_sided = False

        # Get data from file
        separator = form.sep.data
        serie, rd, quality_param = deal_inputs(file_path,
                                               filename,
                                               form,
                                               isseries=True)

        # Generate plot
        img_name = decomposition_plot(serie, model, frequencia, two_sided)

        image_file = url_for('static', filename='images/' + img_name)

        ### Create report

        # Report title
        title = dict_lista['03decomposition']['title']

        # Model parameters
        model_param = [['Modelo', str(model)],
                       ['Referência da Média Móvel',
                        str(ts)], ['Periodicidade',
                                   str(frequencia)]]
        readdata_param = readdata_table(form)
        summary_param = summary_maincol(serie)
        file_title = 'decomposition'
        address_pdf = create_report(title, model_param, readdata_param,
                                    quality_param, summary_param, [img_name],
                                    file_title)

        # Generate array of values
        trend, seasonal, residual, df_output = data_decomposition(
            serie, model, frequencia, two_sided, rd)

        # Create csv for downloading
        address_csv = '%s_%s.csv' % (file_title, secrets.token_hex(6))
        mydir = os.path.join(dir, 'static', 'reports', address_csv)
        df_output.to_csv(mydir,
                         sep=separator,
                         index=False,
                         encoding='utf-8-sig')

        return render_template('algorithms_decomposition_output.html',
                               title='Decomposição de Séries',
                               text=text,
                               form=form,
                               file_url=file_url,
                               model=model,
                               image=image_file,
                               trend=trend,
                               seasonal=seasonal,
                               residual=residual,
                               rd=rd,
                               two_sided=ts,
                               frequencia=frequencia,
                               address_pdf=address_pdf,
                               address_csv=address_csv)

    else:
        file_url = None

    return render_template('algorithms_decomposition.html',
                           title='Decomposição de Séries',
                           text=text,
                           form=form,
                           file_url=file_url)
Exemplo n.º 4
0
def algorithms_periodogram():
    text = desc_list['05periodogram']

    form = FormPeriodogram()

    if form.validate_on_submit() and request.method == 'POST':
        filename = secrets.token_hex(8) + '.csv'
        form.dados.data.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file_url = files.url(filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        # Retrieving results from the form

        # Get data from file
        separator = form.sep.data
        serie, rd, quality_param = deal_inputs(file_path,
                                               filename,
                                               form,
                                               isseries=True)

        # Generate plot
        img_name = periodogram_plot(serie)

        image_file = url_for('static', filename='images/' + img_name)

        ### Create report

        # Report title
        title = dict_lista['05periodogram']['title']

        # Model parameters
        model_param = [['Não há parâmetros no método', '-']]
        readdata_param = readdata_table(form)
        summary_param = summary_maincol(serie)
        file_title = 'periodogram'
        address_pdf = create_report(title, model_param, readdata_param,
                                    quality_param, summary_param, [img_name],
                                    file_title)

        # Generate array of values
        periodogram_data, freq, df_output, index, freq_max, T = data_periodogram(
            serie)

        # Create csv for downloading
        address_csv = '%s_%s.csv' % (file_title, secrets.token_hex(6))

        mydir = os.path.join(dir, 'static', 'reports', address_csv)

        df_output.to_csv(mydir, sep=separator, index=False)

        return render_template('algorithms_periodogram_output.html',
                               title='Periodograma',
                               text=text,
                               form=form,
                               file_url=file_url,
                               image=image_file,
                               data_periodogram=periodogram_data,
                               address_pdf=address_pdf,
                               address_csv=address_csv,
                               periodo=T,
                               index=index,
                               freq_max=freq_max)

    else:
        file_url = None

    return render_template('algorithms_periodogram.html',
                           title='Periodograma',
                           text=text,
                           form=form,
                           file_url=file_url)
Exemplo n.º 5
0
def algorithms_pacf():
    text = desc_list['02pacf']

    form = FormPACF()

    if form.validate_on_submit():
        filename = secrets.token_hex(8) + '.csv'
        form.dados.data.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        file_url = files.url(filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

        # Retrieving results from the form
        lags = form.lags.data

        # Get data from file
        separator = form.sep.data
        serie, rd, quality_param = deal_inputs(file_path,
                                               filename,
                                               form,
                                               isseries=True)

        # Generate plot
        img_name = pacf_plot(serie, lags)

        image_file = url_for('static', filename='images/' + img_name)

        ### Create report

        # Report title
        title = dict_lista['02pacf']['title']

        # Model parameters
        model_param = [['Lags', str(lags)]]
        readdata_param = readdata_table(form)
        summary_param = summary_maincol(serie)
        file_title = 'pacf'
        address_pdf = create_report(title, model_param, readdata_param,
                                    quality_param, summary_param, [img_name],
                                    file_title)

        # Generate array of values
        pacf_data, df_output = data_pacf(serie, lags, rd)

        # Create csv for downloading
        address_csv = '%s_%s.csv' % (file_title, secrets.token_hex(6))

        mydir = os.path.join(dir, 'static', 'reports', address_csv)

        df_output.to_csv(mydir,
                         sep=separator,
                         index=False,
                         encoding='utf-8-sig')

        return render_template('algorithms_pacf_output.html',
                               title='Função de Autocorrelação Parcial',
                               text=text,
                               form=form,
                               file_url=file_url,
                               lag=lags,
                               image=image_file,
                               data_acf=pacf_data,
                               address_pdf=address_pdf,
                               address_csv=address_csv)

    else:
        file_url = None

    return render_template('algorithms_pacf.html',
                           title='Função de Autocorrelação Parcial',
                           text=text,
                           form=form,
                           file_url=file_url)