def avgFlow(flow): _flowUp = [] _flowDown = [] for i in range(len(flow[0])): if i + 1 == len(flow[0]): break _flowUp.append((flow[0][i + 1] - flow[0][i]) / 1024) for i in range(len(flow[1])): if i + 1 == len(flow[1]): break _flowDown.append((flow[1][i + 1] - flow[1][i]) / 1024) avgFpsUp = str(math.ceil(sum(_flowUp) / len(_flowUp))) + "KB" avgFpsDown = str(math.ceil(sum(_flowDown) / len(_flowDown))) + "KB" return avgFpsUp, avgFpsDown
def maxFlow(flow): _flowUp = [] _flowDown = [] for i in range(len(flow[0])): if i + 1 == len(flow[0]): break _flowUp.append(math.ceil((flow[0][i + 1] - flow[0][i]) / 1024)) for i in range(len(flow[1])): if i + 1 == len(flow[1]): break _flowDown.append(math.ceil((flow[1][i + 1] - flow[1][i]) / 1024)) maxFpsUp = str(max(_flowUp)) + "KB" # 上行流量 maxFpsDown = str(max(_flowDown)) + "KB" # 下行流量 return maxFpsUp, maxFpsDown
def avgMen(men, total): if len(men): _men = [math.ceil(((men[i]) / total) * 1024) for i in range(len(men))] return str(math.ceil(sum(_men) / len(_men))) + "%" return "0%"
def maxMen(men): if len(men): print("men=" + str(men)) return str(math.ceil((max(men)) / 1024)) + "M" return "0M"
def avgFps(fps): if len(fps): return '%.2f' % float(str(math.ceil(sum(fps) / len(fps)))) return 0.00
def avgCpu(cpu): if len(cpu): return str(math.ceil(sum(cpu) / len(cpu))) + "%" return "0%"
def analysis(self, worksheet, data): print("------data-----") print(data) worksheet.set_column("A:A", 10) worksheet.set_column("B:B", 10) worksheet.set_column("C:C", 10) worksheet.set_column("D:D", 10) worksheet.set_column("E:E", 10) worksheet.set_column("F:F", 10) worksheet.set_row(1, 30) worksheet.set_row(2, 30) worksheet.set_row(3, 30) worksheet.set_row(4, 30) worksheet.set_row(5, 30) worksheet.set_row(6, 30) define_format_H1 = get_format(self.wd, {'bold': True, 'font_size': 18}) define_format_H2 = get_format(self.wd, {'bold': True, 'font_size': 14}) define_format_H1.set_border(1) define_format_H2.set_border(1) define_format_H1.set_align("center") define_format_H2.set_align("center") define_format_H2.set_bg_color("blue") define_format_H2.set_color("#ffffff") _write_center(worksheet, "A1", 'cpu(%)', self.wd) _write_center(worksheet, "B1", 'men(M)', self.wd) _write_center(worksheet, "C1", 'fps', self.wd) _write_center(worksheet, "D1", 'battery(%)', self.wd) _write_center(worksheet, "E1", '上行流量(KB)', self.wd) _write_center(worksheet, "F1", '下行流量(KB)', self.wd) temp = 2 for item in data["cpu"]: _write_center(worksheet, "A" + str(temp), item, self.wd) temp = temp + 1 temp = 2 for item in data["men"]: _write_center(worksheet, "B" + str(temp), math.ceil(item / 1024), self.wd) temp = temp + 1 temp = 2 for item in data["fps"]: _write_center(worksheet, "C" + str(temp), item, self.wd) temp = temp + 1 temp = 2 for item in data["battery"]: _write_center(worksheet, "D" + str(temp), item, self.wd) temp = temp + 1 temp = 2 for item in data["flow"][0]: _write_center(worksheet, "E" + str(temp), math.ceil(item / 1024), self.wd) temp = temp + 1 temp = 2 for item in data["flow"][1]: _write_center(worksheet, "F" + str(temp), math.ceil(item / 1024), self.wd) temp = temp + 1 self.plot(self.wd, worksheet, "cpu", len(data["cpu"])) self.plot(self.wd, worksheet, "men", len(data["men"])) self.plot(self.wd, worksheet, "battery", len(data["battery"])) self.plot(self.wd, worksheet, "fps", len(data["fps"])) self.plot(self.wd, worksheet, "flowUp", len(data["flow"][0])) self.plot(self.wd, worksheet, "flowDown", len(data["flow"][1]))
def monitor(self, worksheet, header, data): worksheet.set_column("A:A", 15) worksheet.set_column("B:B", 10) worksheet.set_column("C:C", 10) worksheet.set_column("D:D", 10) worksheet.set_column("E:E", 10) worksheet.set_column("F:F", 10) worksheet.set_column("G:G", 10) worksheet.set_column("H:H", 10) worksheet.set_column("I:I", 10) worksheet.set_column("J:J", 10) worksheet.set_column("K:K", 10) worksheet.set_column("L:L", 10) worksheet.set_row(1, 30) worksheet.set_row(2, 30) worksheet.set_row(3, 30) worksheet.set_row(4, 30) worksheet.set_row(5, 30) worksheet.set_row(6, 30) worksheet.set_row(7, 30) worksheet.set_row(8, 30) worksheet.set_row(9, 30) worksheet.set_row(10, 30) worksheet.set_row(11, 30) worksheet.set_row(12, 30) define_format_H1 = get_format(self.wd, {'bold': True, 'font_size': 18}) define_format_H2 = get_format(self.wd, {'bold': True, 'font_size': 14}) define_format_H1.set_border(1) define_format_H2.set_border(1) define_format_H1.set_align("center") define_format_H2.set_align("center") define_format_H2.set_bg_color("blue") define_format_H2.set_color("#ffffff") worksheet.merge_range('A1:L1', 'monkey性能监控_' + header["phone_name"], define_format_H1) _write_center(worksheet, "A2", 'CPU', self.wd) _write_center(worksheet, "C2", '内存', self.wd) _write_center(worksheet, "E2", '分辨率', self.wd) _write_center(worksheet, "G2", '网络', self.wd) _write_center(worksheet, "H2", header["net"], self.wd) _write_center(worksheet, "I2", "耗时", self.wd) _write_center(worksheet, "B2", header["kel"], self.wd) _write_center(worksheet, "D2", str(math.ceil(header["rom"] / 1024)) + "M", self.wd) _write_center(worksheet, "F2", header["pix"], self.wd) _write_center(worksheet, "J2", header["time"], self.wd) _write_center(worksheet, "A3", 'CPU最大峰值', self.wd) _write_center(worksheet, "B3", 'CPU均值', self.wd) _write_center(worksheet, "C3", '内存使用峰值', self.wd) _write_center(worksheet, "D3", '内存使用均值', self.wd) _write_center(worksheet, "E3", 'fps峰值', self.wd) _write_center(worksheet, "F3", 'fps均值', self.wd) _write_center(worksheet, "G3", '电量测试之前', self.wd) _write_center(worksheet, "H3", '电量测试之后', self.wd) _write_center(worksheet, "I3", '上行流量峰值', self.wd) _write_center(worksheet, "J3", '上行流量均值', self.wd) _write_center(worksheet, "K3", '下行流量峰值', self.wd) _write_center(worksheet, "L3", '下行流量均值', self.wd) temp = 4 print(data) _write_center(worksheet, "A" + str(temp), data["maxCpu"], self.wd) _write_center(worksheet, "B" + str(temp), data["avgCpu"], self.wd) _write_center(worksheet, "C" + str(temp), data["maxMen"], self.wd) _write_center(worksheet, "D" + str(temp), data["avgMen"], self.wd) _write_center(worksheet, "E" + str(temp), data["maxFps"], self.wd) _write_center(worksheet, "F" + str(temp), data["avgFps"], self.wd) _write_center(worksheet, "G" + str(temp), data["beforeBattery"], self.wd) _write_center(worksheet, "H" + str(temp), data["afterBattery"], self.wd) _write_center(worksheet, "I" + str(temp), data["maxFlowUp"], self.wd) _write_center(worksheet, "J" + str(temp), data["avgFlowUp"], self.wd) _write_center(worksheet, "K" + str(temp), data["maxFlowDown"], self.wd) _write_center(worksheet, "L" + str(temp), data["avgFlowDown"], self.wd)