File size: 7,399 Bytes
5a8a0ea
 
 
b4a6b00
b444daa
 
1dcc182
5a8a0ea
a51c8fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4839f9
cfa1f4f
 
 
b444daa
cfa1f4f
b444daa
 
cfa1f4f
 
1dcc182
 
 
 
 
 
b444daa
5a8a0ea
1dcc182
 
 
 
 
b444daa
1dcc182
b444daa
1dcc182
cfa1f4f
 
b444daa
5a8a0ea
1dcc182
 
b444daa
1dcc182
cfa1f4f
b444daa
1dcc182
cfa1f4f
 
 
 
8694ab2
1dcc182
 
 
b444daa
1dcc182
b444daa
1dcc182
cfa1f4f
 
b444daa
5a8a0ea
a4839f9
1dcc182
5a8a0ea
b444daa
 
cfa1f4f
 
 
 
 
 
 
 
 
 
b444daa
cfa1f4f
5a8a0ea
 
b444daa
 
a51c8fe
b444daa
 
 
 
a51c8fe
b444daa
 
 
cfa1f4f
a51c8fe
cfa1f4f
 
 
 
 
b444daa
9faf1b7
a4839f9
9faf1b7
5a8a0ea
 
 
b444daa
5a8a0ea
 
cfa1f4f
a4839f9
 
5a8a0ea
 
 
 
1dcc182
cfa1f4f
 
5a8a0ea
1dcc182
a4839f9
5a8a0ea
cfa1f4f
b444daa
a4839f9
5a8a0ea
9faf1b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import csv
from scipy.stats import wilcoxon
import matplotlib.gridspec as gridspec

LIBRARIES = ["7764", 
                 "250833", 
                 #"278964"
                 "734943", 
                 #"1304532",
                 #"1714548", 
                 "2009901",
                 "2670515", 
                 "3828396",
                 "3836952", 
                 "4456656", 
                 "5261717",
                 "6206924", 
                 "7071551", 
                 "7128869",
                 "7603319",
                 "7776928", 
                 "10152778",
                 "10171263", 
                 "10171270", 
                 "10171280",
                 "10174980", 
                 "12450835",
                 "12584701",
                 "12894267",
                 "14052249",
                 "14976868", 
                 "15502567",
                 "19921167",  
                 "21149814", 
                 "23285197", 
                 "28419588",
                 "28644964",  
                 "28847821", "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, list_output_TFIDF, nome_projeto, pip_choices):
    list_results = [["MbR Regressor", np.mean(list_output_MbR)], ["NEOSP-SVR Regressor", np.mean(list_output_NEOSP)], ["TFIDF-SVR Regressor", np.mean(list_output_TFIDF)]]
    
    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"])
    df_list_output_TFIDF = pd.DataFrame(list_output_TFIDF, columns=["MAE"])
        
    fig, ax = plt.subplots(2, 2)
    
    G = gridspec.GridSpec(2, 2)
    axes_1 = plt.subplot(G[0, :])
    axes_2 = plt.subplot(G[1, 0])
    axes_3 = plt.subplot(G[1, 1])
    
    # ax1
    axes_1.set_xlabel("Index Execução")
    axes_1.set_ylabel("MAE")
    axes_1.legend()
    axes_1.grid(True, which = "both", axis = "x" )
    axes_1.minorticks_on()
    if "MbR Regressor" in pip_choices:
        axes_1.scatter(range(1,51), df_list_output_MbR["MAE"].loc[1:50],  label="MbR Regressor", color="red", alpha=0.5,)
    if "NEOSP-SVR Regressor" in pip_choices:
        axes_1.scatter(range(1,51), df_list_output_NEOSP["MAE"].loc[1:50], label="NEOSP-SVR Regressor", color = "blue",  alpha=0.5)
    if "TFIDF-SVR Regressor" in pip_choices:
        axes_1.scatter(range(1,51), df_list_output_TFIDF["MAE"].loc[1:50], label="TFIDF-SVR Regressor", color = "green",  alpha=0.5)

    # ax2
    axes_2.set_ylabel("MAE Médio")
    axes_2.set_xlabel("Modelos")
    if "MbR Regressor" in pip_choices:
        graf1 = axes_2.bar(df["Model"].iloc[[0]], df["MAE"].iloc[[0]], color="red", alpha=0.5)
        axes_2.bar_label(graf1, fmt="%.03f", size=10, label_type="edge")    
    if "NEOSP-SVR Regressor" in pip_choices:
        graf2 = axes_2.bar(df["Model"].iloc[[1]], df["MAE"].iloc[[1]], color = "blue",  alpha=0.5)
        axes_2.bar_label(graf2, fmt="%.03f", size=10, label_type="edge")
    if "TFIDF-SVR Regressor" in pip_choices:
        graf3 = axes_2.bar(df["Model"].iloc[[2]], df["MAE"].iloc[[2]], color = "green",  alpha=0.5)
        axes_2.bar_label(graf3, fmt="%.03f", size=10, label_type="edge")
    
    # ax3
    axes_3.set_xlabel("MAE")
    axes_3.set_ylabel("Frequência")
    if "MbR Regressor" in pip_choices:
        axes_3.hist(df_list_output_MbR["MAE"], color="red",  alpha=0.5)
    if "NEOSP-SVR Regressor" in pip_choices:
        axes_3.hist(df_list_output_NEOSP["MAE"], color="blue", alpha=0.5)
    if "TFIDF-SVR Regressor" in pip_choices:
        axes_3.hist(df_list_output_TFIDF["MAE"], color="green", alpha=0.5)
            
    # graficos geral
    fig.set_figwidth(15)
    fig.set_figheight(8)
    fig.suptitle("Projeto {}".format(nome_projeto))
    # text
        
    resultado, resultado2 = "", ""
    #if  (pip_choices == ["NEOSP-SVR Regressor", "MbR Regressor"]) or (pip_choices == ["MbR Regressor", "NEOSP-SVR Regressor"]):
    res = wilcoxon(list_output_NEOSP, list_output_MbR)
    resultado = "NEOSP-SVR vs. MbR => Statistics: {} | valor-p: {}".format(res.statistic, res.pvalue)
    #if  (pip_choices == ["NEOSP-SVR Regressor", "MbR Regressor"]) or (pip_choices == ["MbR Regressor", "NEOSP-SVR Regressor"]):
    res = wilcoxon(list_output_NEOSP, list_output_TFIDF)
    resultado2 = "NEOSP-SVR vs. TFIDF-SVR  => Statistics: {} | valor-p: {}".format(res.statistic, res.pvalue)
    
    res = wilcoxon(list_output_TFIDF, list_output_MbR)
    resultado3 = "TFIDF-SVR vs. MbR  => Statistics: {} | valor-p: {}".format(res.statistic, res.pvalue)
    
    return gr.update(value=plt, visible=True), gr.update(value=resultado, visible=True), gr.update(value=resultado2, visible=True), gr.update(value=resultado3, visible=True)

def create_pip_plot(libraries, pip_choices):
    nome_projeto = libraries
    list_output_MbR = []
    with open("metricas/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/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]))
    list_output_TFIDF_SVR = []
    with open("metricas/metricas_{}_TFIDF.csv".format(nome_projeto), "r") as arquivo:
        arquivo_csv = csv.reader(arquivo)
        for i, linha in enumerate(arquivo_csv):
            list_output_TFIDF_SVR.append(float(linha[0]))
    
    return grafico(list_output_MbR, list_output_NEOSP_SVR, list_output_TFIDF_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", "TFIDF-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():
            star_plot = gr.Text(visible=False, label="Wilcoxon Test")
            star_plot2 = gr.Text(visible=False, label="Wilcoxon Test")
            star_plot3 = gr.Text(visible=False, label="Wilcoxon Test")
            pip_plot = gr.Plot(visible=False)
            
            # issue_plot = gr.Plot(visible=False)

    fetch.click(create_pip_plot, inputs=[libraries, pip], outputs=[pip_plot, star_plot, star_plot2, star_plot3])
    #fetch.click(create_star_plot, inputs=[libraries, pip], outputs=star_plot)
    # fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)

demo.launch()