giseldo's picture
ultima versao
b444daa
raw
history blame
4.31 kB
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import csv
from scipy.stats import wilcoxon
LIBRARIES = ["ALOY", "APSTUD", "CLI", "CLOV", "COMPASS", "CONFCLOUD", "CONFSERVER", "DAEMON", "DM", "DNN", "DURACLOUD", "EVG", "FAB",
"MDL", "MESOS" ,"MULE", "NEXUS", "SERVER", "STL", "TIDOC", "TIMOB", "TISTUD", "XD"]
def grafico(list_output_MbR, list_output_NEOSP, nome_projeto, pip_choices):
list_results = [["MbR Regressor", np.mean(list_output_MbR)], ["NEOSP-SVR Regressor", np.mean(list_output_NEOSP)]]
df = pd.DataFrame(list_results, columns=["Model", "MAE"])
df_list_output_MbR = pd.DataFrame(list_output_MbR, columns=["MAE"])
df_list_output_NEOSP = pd.DataFrame(list_output_NEOSP, columns=["MAE"])
fig, (ax1, ax2, ax3)= plt.subplots(1, 3)
# ax1
ax1.set_xlabel("Index Execução")
ax1.set_ylabel("MAE")
ax1.legend()
if "MbR Regressor" in pip_choices:
ax1.plot(df_list_output_MbR.index, df_list_output_MbR["MAE"], label="MbR Regressor", color="red", alpha=0.5)
if "NEOSP-SVR Regressor" in pip_choices:
ax1.plot(df_list_output_NEOSP.index, df_list_output_NEOSP["MAE"], label="NEOSP-SVR Regressor", color="blue", alpha=0.5)
# ax2
ax2.set_ylabel("MAE Médio")
ax2.set_xlabel("Modelos")
if "MbR Regressor" in pip_choices:
graf1 = ax2.bar(df["Model"].iloc[[0]], df["MAE"].iloc[[0]], color="red", alpha=0.5)
ax2.bar_label(graf1, fmt="%.01f", size=10, label_type="edge")
if "NEOSP-SVR Regressor" in pip_choices:
graf2 = ax2.bar(df["Model"].iloc[[1]], df["MAE"].iloc[[1]], color = "blue", alpha=0.5)
ax2.bar_label(graf2, fmt="%.01f", size=10, label_type="edge")
ax3.set_xlabel("MAE")
ax3.set_ylabel("Frequência")
if "MbR Regressor" in pip_choices:
ax3.hist(df_list_output_MbR["MAE"], color="red", alpha=0.5)
if "NEOSP-SVR Regressor" in pip_choices:
ax3.hist(df_list_output_NEOSP["MAE"], color="blue", alpha=0.5)
# graficos geral
fig.set_figwidth(15)
fig.set_figheight(4)
fig.suptitle("Projeto {}".format(nome_projeto))
# text
resultado = ""
if ("MbR Regressor" and "NEOSP-SVR Regressor") in pip_choices:
res = wilcoxon(list_output_MbR, list_output_NEOSP)
resultado = "MbR vs. NEOSP-SVR -> Wilcoxon -> Statistics: {} | valor-p: {}".format(res.statistic, res.pvalue)
return gr.update(value=plt, visible=True), gr.update(value=resultado, visible=True)
def create_pip_plot(libraries, pip_choices):
nome_projeto = libraries
list_output_MbR = []
with open("metricas_{}_MbR.csv".format(nome_projeto), "r") as arquivo:
arquivo_csv = csv.reader(arquivo)
for i, linha in enumerate(arquivo_csv):
list_output_MbR.append(float(linha[0]))
list_output_NEOSP_SVR = []
with open("metricas_{}_NEOSP_SVR.csv".format(nome_projeto), "r") as arquivo:
arquivo_csv = csv.reader(arquivo)
for i, linha in enumerate(arquivo_csv):
list_output_NEOSP_SVR.append(float(linha[0]))
return grafico(list_output_MbR, list_output_NEOSP_SVR, nome_projeto, pip_choices)
demo = gr.Blocks()
with demo:
with gr.Row():
with gr.Column():
gr.Markdown("## Conjunto de Dados")
libraries = gr.Dropdown(choices=LIBRARIES, label="Projeto", value="ALOY")
with gr.Column():
gr.Markdown("## Gráficos")
pip = gr.CheckboxGroup(choices=["MbR Regressor", "NEOSP-SVR Regressor"], label="Modelos Preditivos")
# stars = gr.CheckboxGroup(choices=["Stars", "Week over Week"], label="")
# issues = gr.CheckboxGroup(choices=["Issue", "Exclude org members", "week over week"], label="")
with gr.Row():
fetch = gr.Button(value="Fetch")
with gr.Row():
with gr.Column():
pip_plot = gr.Plot(visible=False)
star_plot = gr.Text(visible=False)
# issue_plot = gr.Plot(visible=False)
fetch.click(create_pip_plot, inputs=[libraries, pip], outputs=[pip_plot, star_plot])
#fetch.click(create_star_plot, inputs=[libraries, pip], outputs=star_plot)
# fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)
demo.launch()