GenerateChart.py

该脚本从给定的JSON数据中读取信息,计算最大路损和平均上传吞吐量,并生成图表数据。它创建了一个包含标准和当前吞吐量的折线图,突出显示了一个异常值。最后,将图表配置信息保存到'chart.json'文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import os
from LogUtil import get_json_log
import json

def generate_ulThroughput(calc_pl_json):
    data = get_json_log(calc_pl_json)
    max_pl = data[str(len(data)-1)]['ulPL']
    ulThroughput = data['0']['ulThroughput']['avg']
    print(max_pl, ulThroughput)
    
    name_x = "路损:dB"
    title = "THROUGHPUT"
    name_y = "THROUGHPUT"
    x = max_pl
    standard = []
    current = []
    data_x = []
    abnormal_pos = 3
    abnormal_value = data[str(abnormal_pos)]['ulThroughput']['avg']
    for i in range(len(data)):
        standard.append(data[str(i)]['ulThroughput']['avg']+200)
        current.append(data[str(i)]['ulThroughput']['avg'])
        data_x.append(data[str(i)]['ulPL'])
    chart_json = {}
    chart_json["title"] = {"text": title,"subtext": "TEST"}
    chart_json["tooltip"] = {"trigger":"axis"}
    chart_json["legend"] = {"data":["Standard","Current"]}
    chart_json["toolbox"] = {"show" : "true", "feature": {"mark" : {"show": "true"}, "dataView" : {"show": "true", "readOnly": "true"}, "magicType" : {"show": "true", "type": ["line", "bar"]},"restore" : {"show": "true"},"saveAsImage" : {"show": "true"}}}
    chart_json["dataZoom"] =[{"type": "slider","show": "true","xAxisIndex": [0],"start": 0,"end": x},{"type": "inside","xAxisIndex": [0],"start": 0,"end": x}]
    chart_json["calculable"] = "true"
    
    chart_json["xAxis"] = [{"name": name_x,"type" : "category","boundaryGap" : False,"data" : data_x}]
    chart_json["yAxis"] = [{"name": name_y,"type" : "value","axisLabel" :{ "formatter": "{value}"}}]
    chart_json["series"] = [{"name":"Standard","type":"line","data":standard},{"name":"Current","type":"line","data": current,"markPoint" : {"data" : [{"coord":[abnormal_pos,abnormal_value],"value":abnormal_value}]}}]
    str_json = str(chart_json)
    str_json = str_json.replace("False", "false")
    str_json = str_json.replace("'", '"')
    f = open('chart.json','w', encoding='utf-8')
    f.write(str_json)
    f.close()
    print(str_json)

    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值