mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 19:54:32 +02:00
test: use pyecharts to replace matplotlib in iperf test
This commit is contained in:
@@ -70,6 +70,9 @@ class TestResult(object):
|
|||||||
# we need at least 1/2 valid points to qualify the test result
|
# we need at least 1/2 valid points to qualify the test result
|
||||||
THROUGHPUT_QUALIFY_COUNT = TEST_TIME // 2
|
THROUGHPUT_QUALIFY_COUNT = TEST_TIME // 2
|
||||||
|
|
||||||
|
RSSI_RANGE = [-x for x in range(10, 100)]
|
||||||
|
ATT_RANGE = [x for x in range(0, 64)]
|
||||||
|
|
||||||
def __init__(self, proto, direction, config_name):
|
def __init__(self, proto, direction, config_name):
|
||||||
self.proto = proto
|
self.proto = proto
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
@@ -180,16 +183,6 @@ class TestResult(object):
|
|||||||
analysis_bad_point(self.throughput_by_rssi, "rssi")
|
analysis_bad_point(self.throughput_by_rssi, "rssi")
|
||||||
analysis_bad_point(self.throughput_by_att, "att")
|
analysis_bad_point(self.throughput_by_att, "att")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _convert_to_draw_format(data, label):
|
|
||||||
keys = list(data.keys())
|
|
||||||
keys.sort()
|
|
||||||
return {
|
|
||||||
"x-axis": keys,
|
|
||||||
"y-axis": [data[x] for x in keys],
|
|
||||||
"label": label,
|
|
||||||
}
|
|
||||||
|
|
||||||
def draw_throughput_figure(self, path, ap_ssid, draw_type):
|
def draw_throughput_figure(self, path, ap_ssid, draw_type):
|
||||||
"""
|
"""
|
||||||
:param path: folder to save figure. make sure the folder is already created.
|
:param path: folder to save figure. make sure the folder is already created.
|
||||||
@@ -200,25 +193,24 @@ class TestResult(object):
|
|||||||
if draw_type == "rssi":
|
if draw_type == "rssi":
|
||||||
type_name = "RSSI"
|
type_name = "RSSI"
|
||||||
data = self.throughput_by_rssi
|
data = self.throughput_by_rssi
|
||||||
|
range_list = self.RSSI_RANGE
|
||||||
elif draw_type == "att":
|
elif draw_type == "att":
|
||||||
type_name = "Att"
|
type_name = "Att"
|
||||||
data = self.throughput_by_att
|
data = self.throughput_by_att
|
||||||
|
range_list = self.ATT_RANGE
|
||||||
else:
|
else:
|
||||||
raise AssertionError("draw type not supported")
|
raise AssertionError("draw type not supported")
|
||||||
if isinstance(ap_ssid, list):
|
if isinstance(ap_ssid, list):
|
||||||
file_name = "ThroughputVs{}_{}_{}_{}.png".format(type_name, self.proto, self.direction,
|
file_name = "ThroughputVs{}_{}_{}_{}.html".format(type_name, self.proto, self.direction,
|
||||||
hash(ap_ssid)[:6])
|
hash(ap_ssid)[:6])
|
||||||
data_list = [self._convert_to_draw_format(data[_ap_ssid], _ap_ssid)
|
|
||||||
for _ap_ssid in ap_ssid]
|
|
||||||
else:
|
else:
|
||||||
file_name = "ThroughputVs{}_{}_{}_{}.png".format(type_name, self.proto, self.direction, ap_ssid)
|
file_name = "ThroughputVs{}_{}_{}_{}.html".format(type_name, self.proto, self.direction, ap_ssid)
|
||||||
data_list = [self._convert_to_draw_format(data[ap_ssid], ap_ssid)]
|
|
||||||
|
|
||||||
LineChart.draw_line_chart(os.path.join(path, file_name),
|
LineChart.draw_line_chart(os.path.join(path, file_name),
|
||||||
"Throughput Vs {} ({} {})".format(type_name, self.proto, self.direction),
|
"Throughput Vs {} ({} {})".format(type_name, self.proto, self.direction),
|
||||||
"{} (dbm)".format(type_name),
|
"{} (dbm)".format(type_name),
|
||||||
"Throughput (Mbps)",
|
"Throughput (Mbps)",
|
||||||
data_list)
|
data, range_list)
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
def draw_rssi_vs_att_figure(self, path, ap_ssid):
|
def draw_rssi_vs_att_figure(self, path, ap_ssid):
|
||||||
@@ -228,17 +220,15 @@ class TestResult(object):
|
|||||||
:return: file_name
|
:return: file_name
|
||||||
"""
|
"""
|
||||||
if isinstance(ap_ssid, list):
|
if isinstance(ap_ssid, list):
|
||||||
file_name = "AttVsRSSI_{}.png".format(hash(ap_ssid)[:6])
|
file_name = "AttVsRSSI_{}.html".format(hash(ap_ssid)[:6])
|
||||||
data_list = [self._convert_to_draw_format(self.att_rssi_map[_ap_ssid], _ap_ssid)
|
|
||||||
for _ap_ssid in ap_ssid]
|
|
||||||
else:
|
else:
|
||||||
file_name = "AttVsRSSI_{}.png".format(ap_ssid)
|
file_name = "AttVsRSSI_{}.html".format(ap_ssid)
|
||||||
data_list = [self._convert_to_draw_format(self.att_rssi_map[ap_ssid], ap_ssid)]
|
|
||||||
LineChart.draw_line_chart(os.path.join(path, file_name),
|
LineChart.draw_line_chart(os.path.join(path, file_name),
|
||||||
"Att Vs RSSI",
|
"Att Vs RSSI",
|
||||||
"Att (dbm)",
|
"Att (dbm)",
|
||||||
"RSSI (dbm)",
|
"RSSI (dbm)",
|
||||||
data_list)
|
self.att_rssi_map,
|
||||||
|
self.ATT_RANGE)
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
def get_best_throughput(self):
|
def get_best_throughput(self):
|
||||||
|
@@ -12,18 +12,13 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import matplotlib
|
from collections import OrderedDict
|
||||||
# fix can't draw figure with docker
|
|
||||||
matplotlib.use('Agg')
|
import pyecharts.options as opts
|
||||||
import matplotlib.pyplot as plt # noqa: E402 - matplotlib.use('Agg') need to be before this
|
from pyecharts.charts import Line
|
||||||
|
|
||||||
|
|
||||||
# candidate colors
|
def draw_line_chart(file_name, title, x_label, y_label, data_series, range_list):
|
||||||
LINE_STYLE_CANDIDATE = ['b-o', 'r-o', 'k-o', 'm-o', 'c-o', 'g-o', 'y-o',
|
|
||||||
'b-s', 'r-s', 'k-s', 'm-s', 'c-s', 'g-s', 'y-s']
|
|
||||||
|
|
||||||
|
|
||||||
def draw_line_chart(file_name, title, x_label, y_label, data_list):
|
|
||||||
"""
|
"""
|
||||||
draw line chart and save to file.
|
draw line chart and save to file.
|
||||||
|
|
||||||
@@ -31,20 +26,33 @@ def draw_line_chart(file_name, title, x_label, y_label, data_list):
|
|||||||
:param title: chart title
|
:param title: chart title
|
||||||
:param x_label: x-axis label
|
:param x_label: x-axis label
|
||||||
:param y_label: y-axis label
|
:param y_label: y-axis label
|
||||||
:param data_list: a list of line data.
|
:param data_series: a dict {"name": data}. data is a dict.
|
||||||
each line is a dict of ("x-axis": list, "y-axis": list, "label": string)
|
:param range_list: a list of x-axis range
|
||||||
"""
|
"""
|
||||||
|
|
||||||
plt.figure(figsize=(12, 6))
|
line = Line()
|
||||||
plt.grid(True)
|
# echarts do not support minus number for x axis, convert to string
|
||||||
|
_range_list = [str(x) for x in range_list]
|
||||||
for i, data in enumerate(data_list):
|
line.add_xaxis(_range_list)
|
||||||
plt.plot(data["x-axis"], data["y-axis"], LINE_STYLE_CANDIDATE[i], label=data["label"])
|
for item in data_series:
|
||||||
|
_data = OrderedDict.fromkeys(_range_list, None)
|
||||||
plt.xlabel(x_label)
|
for key in data_series[item]:
|
||||||
plt.ylabel(y_label)
|
_data[str(key)] = data_series[item][key]
|
||||||
plt.legend(fontsize=12)
|
_data = list(_data.values())
|
||||||
plt.title(title)
|
try:
|
||||||
plt.tight_layout(pad=3, w_pad=3, h_pad=3)
|
legend = item + " (max: {:.02f})".format(max([x for x in _data if x]))
|
||||||
plt.savefig(file_name)
|
except TypeError:
|
||||||
plt.close()
|
legend = item
|
||||||
|
line.add_yaxis(legend, _data, is_smooth=True, is_connect_nones=True,
|
||||||
|
label_opts=opts.LabelOpts(is_show=False))
|
||||||
|
line.set_global_opts(
|
||||||
|
datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=100),
|
||||||
|
title_opts=opts.TitleOpts(title=title, pos_left="center"),
|
||||||
|
legend_opts=opts.LegendOpts(pos_top="10%", pos_left="right", orient="vertical"),
|
||||||
|
tooltip_opts=opts.TooltipOpts(trigger="axis"),
|
||||||
|
xaxis_opts=opts.AxisOpts(type_="category", name=x_label, splitline_opts=opts.SplitLineOpts(is_show=True)),
|
||||||
|
yaxis_opts=opts.AxisOpts(type_="value", name=y_label,
|
||||||
|
axistick_opts=opts.AxisTickOpts(is_show=True),
|
||||||
|
splitline_opts=opts.SplitLineOpts(is_show=True)),
|
||||||
|
)
|
||||||
|
line.render(file_name)
|
||||||
|
@@ -229,7 +229,7 @@ class ThroughputVsRssiReport(object):
|
|||||||
result.draw_throughput_figure(self.raw_data_path, ap_ssid, "att")
|
result.draw_throughput_figure(self.raw_data_path, ap_ssid, "att")
|
||||||
result.draw_rssi_vs_att_figure(self.raw_data_path, ap_ssid)
|
result.draw_rssi_vs_att_figure(self.raw_data_path, ap_ssid)
|
||||||
|
|
||||||
ret += "\r\n\r\n".format(os.path.join("raw_data", file_name))
|
ret += "\r\n[throughput Vs RSSI]({})\r\n".format(os.path.join("raw_data", file_name))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user