python txt 数据处理 errorbar画均值方差图

需求又增加了:
对fps数据进行求均值和标准差的操作
每隔固定时间统计一次,求每个统计间隔的均值和标准差,并找出超出3 sigma的异常数据
对异常数据画图,正常为蓝色,异常为红色,临界值为橙色
分类统计以上求出的所有均值(最终采用字典存储)
代码越来越长,拆分为函数

贴上自己写的垃圾代码,只为记录

import os
import argparse
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from pylab import *
import time
mpl.rcParams['font.sans-serif'] = ['SimHei']

###命令函参数

    
    
def ParseAugments():
    parser = argparse.ArgumentParser("Demo of argparse")
    parser.add_argument('log_path', type=str,
                        default=" ", help="path to log file")
    parser.add_argument('out_path',type=str,
                        default=" ",help ="path to result file")
    parser.add_argument('frequency',type=int,
                        default=60 ,help ="time interval")
    
    
                        
    args = parser.parse_args()
    log_path = args.log_path
    frequency=args.frequency
    out_path=args.out_path
    current_path = os.path.abspath(log_path)
    current_outpath = os.path.abspath(out_path)
    os.mkdir(out_path)
    print("输入文件路径为: {}".format(current_path))
    print("输出结果文件保存在: {}".format(current_outpath))
    
    return log_path,out_path,frequency


def stat_txt_data(log_path,out_path,frequency):
    files = os.listdir(log_path)
    for file_name in files:
        fname,fename=os.path.splitext(file_name)
        #print(fname)
        input = open(log_path+"\\"+file_name, 'r')
    
        fpsNumArr = []
        timestamp=[]
        for line in input:
            line = line.split()

            if 'fps->' in line:
                #print(line)
                line[-1]=line[-1].lstrip('"')
                fpsNumArr.append(int(line[-1].rstrip('"')))
                
                timestamp.append(line[0]+' '+line[1])
            
        

    
        input.close()
        
        
        
        
        
            
            
                
        fpsNumArrAll_np = np.array(fpsNumArr)
        fps_mean=np.mean(fpsNumArrAll_np)
        
        
        timestamp_i=idealformat(timestamp)
        
        outlier_num,mean,std,outlier,outlier_x=error_count(fpsNumArr,timestamp_i,frequency)
        
        mean_error_xr,mean_error_xo,mean_errorr,mean_erroro,std_errorr,std_erroro=mean_errors(mean,std)
        
        plot_experiment_data(out_path,fname,mean,std,mean_error_xr,mean_error_xo,mean_errorr,mean_erroro,std_errorr,std_erroro)
        
        a,b,c,d,e=count_fps_distribution(fpsNumArr)
        
        print_info(file_name,a,b,c,d,e,outlier)
        dict_d=meanclass(mean,std)
        
        #########################log信息保存到txt##########################
        save_result_file=out_path+"\\"+"result_"+file_name
        with open(save_result_file,"w") as f:
            length=a+b+c+d+e
            
            f.write("检测到fps个数为:"
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值