• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlanticwave-sdx / pce / 3680947894

pending completion
3680947894

Pull #81

github

GitHub
Merge a6cd61918 into b40be3bdd
Pull Request #81: Updates coveralls.io configuration

845 of 1796 relevant lines covered (47.05%)

0.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Utility/results_plot_simulation.py
1
import json
×
2
import re
×
3

4
import matplotlib.pyplot as plt
×
5
import numpy as np
×
6

7

8
# Function to read
9
# last N lines of the file
10
def LastNlines(fname, N):
×
11
    # opening file using with() method
12
    # so that file get closed
13
    # after completing work
14
    results = None
×
15
    try:
×
16
        with open(fname) as file:
×
17

18
            # loop to read iterate
19
            # last n lines and convert to a dict
20
            results = {}
×
21
            for line in file.readlines()[-N:]:
×
22
                # print(line, end ='')
23
                list = re.split(", |=|;|:|\+", line.splitlines()[0])
×
24
                it = iter(list)
×
25
                res_dct = dict(zip(it, it))
×
26
                results = {**results, **res_dct}
×
27
            results["Script Execution Time"] = results["Script Execution Time"].split()[
×
28
                0
29
            ]
30
            print(results)
×
31
    except IOError as e:
×
32
        print(e)
×
33
    return results
×
34

35

36
def plot_simulation(path, title):
×
37
    tag = " Simulation"
×
38
    N = 5
×
39
    num_connection_list = []
×
40

41
    time_list_dict = {}
×
42
    total_util_list_dict = {}
×
43
    max_util_list_dict = {}
×
44
    mean_util_list_dict = {}
×
45
    std_util_list_dict = {}
×
46
    ninetypercetile_util_list_dict = {}
×
47
    objective_list_dict = {}
×
48

49
    for dir, name in title.items():
×
50
        time_list = []
×
51
        total_util_list = []
×
52
        max_util_list = []
×
53
        mean_util_list = []
×
54
        std_util_list = []
×
55
        ninetypercetile_util_list = []
×
56
        objective_list = []
×
57

58
        key = re.split(r"\D+", dir)[1]
×
59
        print("key=" + key)
×
60

61
        time_list_dict[key] = time_list
×
62
        total_util_list_dict[key] = total_util_list
×
63
        max_util_list_dict[key] = max_util_list
×
64
        mean_util_list_dict[key] = mean_util_list
×
65
        std_util_list_dict[key] = std_util_list
×
66
        ninetypercetile_util_list_dict[key] = ninetypercetile_util_list
×
67
        objective_list_dict[key] = objective_list
×
68

69
        for i in range(10, 210, 10):
×
70
            fname = path + dir + name + str(i) + ".out"
×
71
            results = LastNlines(fname, N)
×
72
            if results is not None:
×
73
                time_list.append(float(results["Script Execution Time"]))
×
74
                total_util_list.append(float(results["total_util"]))
×
75
                max_util_list.append(float(results["max_util"]))
×
76
                mean_util_list.append(float(results["mean_util"]))
×
77
                std_util_list.append(float(results["std_util"]))
×
78
                ninetypercetile_util_list.append(float(results["ninetypercetile_util"]))
×
79
                objective_list.append(float(results["Objective value "]))
×
80
            else:
81
                time_list.append(None)
×
82
                total_util_list.append(None)
×
83
                max_util_list.append(None)
×
84
                mean_util_list.append(None)
×
85
                std_util_list.append(None)
×
86
                ninetypercetile_util_list.append(None)
×
87
                objective_list.append(None)
×
88

89
    num_connection_list = [*range(10, 210, 10)]
×
90
    y_label = [
×
91
        "Compuation Time (s)",
92
        "Total Utility",
93
        "Max Utility",
94
        "Mean Utility",
95
        "STD Utility",
96
        "90% Utility",
97
        "Objective value",
98
    ]
99
    x_label = "Number of Connections"
×
100

101
    fig1, ax1 = plt.subplots()
×
102
    ax1.set_title(y_label[0])
×
103
    ax1.set_xlabel(x_label)
×
104
    for key in time_list_dict.keys():
×
105
        ax1.plot(num_connection_list, time_list_dict[key], label=str(key))
×
106
    # ax1.plot(num_connection_list,time_list, label = 'N=25')
107

108
    plt.legend()
×
109
    name = y_label[0] + tag + ".png"
×
110
    plt.savefig(name, bbox_inches="tight")
×
111

112
    fig2, ax2 = plt.subplots()
×
113
    ax2.set_title(y_label[1])
×
114
    ax2.set_xlabel(x_label)
×
115
    for key in total_util_list_dict.keys():
×
116
        ax2.plot(num_connection_list, total_util_list_dict[key], label=str(key))
×
117

118
    plt.legend()
×
119
    name = y_label[1] + tag + ".png"
×
120
    plt.savefig(name, bbox_inches="tight")
×
121
    ax2.legend()
×
122

123
    fig3, ax3 = plt.subplots()
×
124
    ax3.set_title(y_label[2])
×
125
    ax3.set_xlabel(x_label)
×
126
    for key in max_util_list_dict.keys():
×
127
        ax3.plot(num_connection_list, max_util_list_dict[key], label=str(key))
×
128

129
    plt.legend()
×
130
    name = y_label[2] + tag + ".png"
×
131
    plt.savefig(name, bbox_inches="tight")
×
132

133
    fig4, ax4 = plt.subplots()
×
134
    ax4.set_title(y_label[3])
×
135
    ax4.set_xlabel(x_label)
×
136
    for key in mean_util_list_dict.keys():
×
137
        ax4.plot(num_connection_list, mean_util_list_dict[key], label=str(key))
×
138
    plt.legend()
×
139
    name = y_label[3] + tag + ".png"
×
140
    plt.savefig(name, bbox_inches="tight")
×
141

142
    fig5, ax5 = plt.subplots()
×
143
    ax5.set_title(y_label[4])
×
144
    ax5.set_xlabel(x_label)
×
145
    for key in std_util_list_dict.keys():
×
146
        ax5.plot(num_connection_list, std_util_list_dict[key], label=str(key))
×
147
    plt.legend()
×
148
    name = y_label[4] + tag + ".png"
×
149
    plt.savefig(name, bbox_inches="tight")
×
150

151
    fig6, ax6 = plt.subplots()
×
152
    ax6.set_title(y_label[5])
×
153
    ax4.set_xlabel(x_label)
×
154
    for key in ninetypercetile_util_list_dict.keys():
×
155
        ax6.plot(
×
156
            num_connection_list, ninetypercetile_util_list_dict[key], label=str(key)
157
        )
158
    plt.legend()
×
159
    name = y_label[5] + tag + ".png"
×
160
    plt.savefig(name, bbox_inches="tight")
×
161

162
    fig7, ax7 = plt.subplots()
×
163
    ax7.set_title(y_label[6])
×
164
    ax4.set_xlabel(x_label)
×
165
    for key in objective_list_dict.keys():
×
166
        ax7.plot(num_connection_list, objective_list_dict[key], label=str(key))
×
167
    plt.legend()
×
168
    name = y_label[6] + tag + ".png"
×
169
    plt.savefig(name, bbox_inches="tight")
×
170

171

172
def plot_heur(title, path):
×
173
    tag = "heur"
×
174

175
    num_connection_list = []
×
176
    time_list = []
×
177
    weight_list = []
×
178
    util_list = []
×
179
    max_util_list = []
×
180
    for i in (2, 4, 8, 10):
×
181
        name = path + title + str(i) + ".out"
×
182
        num_connection_list.append(i)
×
183
        results = LastNlines(name, 2)
×
184
        time_list.append(float(results["Script Execution Time"]))
×
185
        weight_list.append(float(results["total_weight"]))
×
186
        util_list.append(float(results["total_util"]))
×
187
        max_util_list.append(float(results["max_util"]))
×
188

189
    y_label = ["Compuation Time (s)", "Total Weight", "Total Utility", "Max Utility"]
×
190
    x_label = "Number of Groups"
×
191
    fig1, ax1 = plt.subplots()
×
192
    ax1.set_title(y_label[0])
×
193
    ax1.set_xlabel(x_label)
×
194
    # for key in score_dict.keys():
195
    #    ax1.plot(missing_rate_list,score_dict[key], label = str(key))
196
    ax1.plot(num_connection_list, time_list, label="N=25")
×
197

198
    plt.legend()
×
199
    name = y_label[0] + tag + ".png"
×
200
    plt.savefig(name, bbox_inches="tight")
×
201

202
    fig2, ax2 = plt.subplots()
×
203
    ax2.set_title(y_label[1])
×
204
    ax2.set_xlabel(x_label)
×
205
    # for key in rmse_dict.keys():
206
    #    ax2.plot(missing_rate_list,rmse_dict[key], label = str(key))
207
    print(weight_list)
×
208
    ax2.plot(num_connection_list, weight_list, label="N=25")
×
209

210
    plt.legend()
×
211
    name = y_label[1] + tag + ".png"
×
212
    plt.savefig(name, bbox_inches="tight")
×
213

214
    fig3, ax3 = plt.subplots()
×
215
    ax3.set_title(y_label[2])
×
216
    ax3.set_xlabel(x_label)
×
217
    # for key in mse_dict.keys():
218
    #    ax3.plot(missing_rate_list,mse_dict[key], label = str(key))
219
    ax3.plot(num_connection_list, util_list, label="N=25")
×
220
    print(util_list)
×
221

222
    plt.legend()
×
223
    name = y_label[2] + tag + ".png"
×
224
    plt.savefig(name, bbox_inches="tight")
×
225

226
    fig4, ax4 = plt.subplots()
×
227
    ax4.set_title(y_label[3])
×
228
    ax4.set_xlabel(x_label)
×
229
    # for key in mse_dict.keys():
230
    #    ax3.plot(missing_rate_list,mse_dict[key], label = str(key))
231
    ax4.plot(num_connection_list, max_util_list, label="N=25")
×
232
    print(max_util_list)
×
233

234
    plt.legend()
×
235
    name = y_label[3] + tag + ".png"
×
236
    plt.savefig(name, bbox_inches="tight")
×
237

238

239
# Driver Code:
240
if __name__ == "__main__":
×
241
    # fname = '/Users/yxin/NSF/aw-sdx/sdx/pce/tests/results/simulation.57036414_10.out'
242
    # N = 2
243
    # LastNlines(fname, N)
244
    path = "../../tests/results/"
×
245
    title = {
×
246
        "out_simulation_50_10_28/": "simulation.57510402_",
247
        "out_simulation_25_10_28_200/": "simulation.57466833_",
248
    }
249
    plot_simulation(path, title)
×
250

251
    # title = "heur.57082350_"
252
    # path = '../../tests/results/out_heur_10_25/'
253
    # plot_heur(title,path)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc