Commit 4d46b0a5 authored by Deathcrow's avatar Deathcrow

Simple data smoothing script

parent 194648d9
#!/usr/bin/env python3
# vim: expandtab shiftwidth=4 softtabstop=4
#iperf -V -Z cubic -t 30 -c fdb2:f689:4248:2bc8::3 -p 12345
import argparse
import copy
import math
import os
import re
import signal
import subprocess
import tempfile
#import threading
import time
from collections import deque
def signal_handler(signum, frame):
clean_up()
raise SystemExit
def testy(a,b):
print(a)
print(b)
print(sender)
return 0
def clean_up():
# Clean up
if args.legacy:
tcpprobe.terminate()
if args.tcpdump == "1":
tcpdump.terminate()
if args.cpunetlog != "":
cpunetlog.terminate()
for i in sender:
# if i['utility'].returncode == None:
try:
i['utility'].kill()
except ProcessLookupError:
pass
# i['utility_file'].close()
time.sleep(1)
#def parse_dir(directory):
def qsort1(list):
"""Quicksort using list comprehensions"""
if list == []:
return []
else:
pivot = list[0]
lesser = qsort1([x for x in list[1:] if x < pivot])
greater = qsort1([x for x in list[1:] if x >= pivot])
return lesser + [pivot] + greater
def quantil(list,p):
length = len(list)
len_p = (length * p)-1
if math.ceil(len_p) == len_p:
return ((list[int(len_p)] + list[int(len_p + 1)]) / 2)
else:
return list[math.ceil(len_p)]
def parse_file(file_thing,x=3, y=-2):
initialized = 0
for line in file_thing:
line = line.split(" ")
#print(line[9])
#print(line[3][:-2])
#mooth_val = float(line[3][:-2])
if y == 0:
cur_val = float(line[x])
else:
cur_val = float(line[x][:y])
if args.mode == "tcp":
if initialized:
smooth_val = 0.9 * smooth_val + 0.1 * cur_val
else:
smooth_val = cur_val
print("Initialize")
initialized = 1
if args.mode == "moving_average":
if initialized:
smooth_val = smooth_val + cur_val/moving_average_size - moving_average_queue.popleft()/moving_average_size
moving_average_queue.append(cur_val)
else:
smooth_val = cur_val
moving_average_size = 30
moving_average_queue = deque(maxlen=moving_average_size)
for i in range(moving_average_size):
moving_average_queue.append(smooth_val)
initialized = 1
print(moving_average_queue)
if x == 9 and y == 0:
smoothed_values_file.write(" ".join( (" ".join(line[:9]), str(smooth_val), " ".join(line[10:]) ) ) )
else:
smoothed_values_file.write(" ".join( (" ".join(line[:3]), str(smooth_val), "\n") ) )
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
parser = argparse.ArgumentParser(description='Configure test environment.')
parser.add_argument('folders', nargs="*", default=".", help="File to smooth")
parser.add_argument('-m', '--mask', default="")
parser.add_argument('--mode', default="tcp")
args = parser.parse_args()
mypid = os.getpid()
#print(args.folders)
#for key, folder in enumerate(args.folders):
# args.folders[key] = os.path.abspath(folder)
args.folders = [os.path.abspath(folder) for folder in args.folders]
print(args.folders)
#smoothed_values_file = tempfile.TemporaryFile(mode='r+')
for folder in args.folders:
for path, dirs, files in os.walk(folder):
for file in files:
if file[:3+len(args.mask)] == "bw_"+args.mask or file[:9+len(args.mask)] == "tcpprobe_"+args.mask:
data_file = open(path + "/" + file)
smoothed_values_file = open(path + "/" + "smoothed_" + file, 'w+')
#smooth_val = float(bw_file.readline().split()[3][:-2])
#print(smooth_val)
if file[:3+len(args.mask)] == "bw_"+args.mask:
parse_file(data_file)
if file[:9+len(args.mask)] == "tcpprobe_"+args.mask:
parse_file(data_file, 9,0)
data_file.close()
smoothed_values_file.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment