# Path: aqmt/processes.py
# def kill_known_pids():
# def add_known_pid(pid):
# def kill_pid(pid):
# def is_running(pid):
# def waitpid(pid):
# 
# Path: aqmt/plot/collectionutil.py
# def get_tree_details(tree):
#     def traverse(branch, depthnow=0):
# def get_gap(tree):
# def get_testcases(leaf):
# def get_all_testcases_folders(tree):
#     def parse_leaf(leaf, first_set, x):
# def make_xtics(tree, xoffset, x_axis):
#     def frange(start, stop, step):
# def get_testmeta_min_max_count(leaf, x_axis):
# def get_x_coordinate(leaf, value, x_axis):
# def merge_testcase_data_set_x(testcases, x_axis):
# def get_leaf_tests_stats(leaf, statsname):
# def merge_testcase_data(leaf, statsname, x_axis):
# def merge_testcase_data_group(leaf, statsname, x_axis):
# def get_xlabel(tree):
#     def fn(leaf, first_set, x):
# def pt_generator():
#     def get_val(tag):
# 
# Path: aqmt/plot/treeutil.py
# def get_depth_sizes(tree):
#     def check_node(item, x, depth):
# def walk_leaf(tree, fn):
#     def walk(branch):
# def walk_tree_reverse(tree, fn):
#     def walk(branch, depth=0):
# def walk_tree(tree, fn, include_leaf_collection=False):
#     def walk(collection, depth=0):
# def swap_levels(tree, level=0):
#         def walk(branch, depth):
#     def check_level(node, x, depth):
#     def build_swap(node, x, depth):
# def build_swap_list(level_order):
# def reorder_levels(tree, level_order=None):
# def skip_levels(tree, number_of_levels):
# 
# Path: aqmt/plot/common.py
# def add_plot(gpi):
#     """
#     Remove trailing comma from plot command because gnuplot complains about it
#     (We use the trailing comma to easier build plot commands)
#     """
#     return re.sub(r',(\s*\\?\s*\\?\s*)$', '\g<1>', gpi)
# 
# def add_scale(y_logarithmic, range_from=None, range_from_log=None,
#         range_to=None, range_to_log=None):
#     if y_logarithmic:
#         if range_from_log is None:
#             range_from_log = '1'
#         if range_to_log is None:
#             range_to_log = '*'
#         return """
#             set logscale y
#             set yrange [""" + range_from_log + """:""" + range_to_log + """]
#             """
#     else:
#         if range_from is None:
#             range_from = '0'
#         if range_to is None:
#             range_to = '1<*'
#         return """
#             set yrange [""" + range_from + """:""" + range_to + """]
#             """
# 
# Path: aqmt/testenv.py
# def read_metadata(file):
#     """
#     Reads metadata from a `details` file
# 
#     Returns a map of the properties as well as a list of properties to be used
#     if properties of the same key is repeated
#     """
#     if not os.path.isfile(file):
#         raise Exception('Missing metadata file: ' + file)
# 
#     metadata = {}
#     lines = []
# 
#     with open(file, 'r') as f:
#         for line in f:
#             s = line.split(maxsplit=1)
#             key = s[0]
#             value = s[1].strip() if len(s) > 1 else ''
#             metadata[key.strip()] = value
#             lines.append((key, value))
# 
#     return metadata, lines


import numpy as np
import operator
import os
from functools import partial
from plumbum.cmd import bash
from aqmt import processes
from aqmt.plot import collectionutil, treeutil
from aqmt.plot.common import add_plot, add_scale
from ..testenv import read_metadata

        ylabel_extra = ''
        if subtract_base_rtt:
            ylabel_extra = '\\n{/Times:Italic=10 Excluding base RTT}'

        gpi = """
            set ylabel "RTT at sender""" + ylabel_extra + """\\n{/Times:Italic=10 [ms] (p_1, mean, p_{99})}"
            """ + add_scale(y_logarithmic)

        # add hidden line to force autoscaling if using logarithimic plot without any points
        plot_gpi = " 1 lc rgb '#FFFF0000' notitle, \\\n"

        def leaf(subtree, is_first_set, x):
            nonlocal gpi, plot_gpi
            leaf_hook(subtree, is_first_set, x)
            add_title = keys and is_first_set

            def parse_rtt(node, testcase_folder):
                rtts = _parse_rtt_of_test(testcase_folder, node, subtract_base_rtt)

                # take last half, so it is stable
                rtts = rtts[int(len(rtts)/2):]

                # get second element of list which is the rtt value
                rtts = [x[1] for x in rtts]

                return _generate_stats(rtts)

            gpi += """
                $data_rtt_a""" + str(x) + """ << EOD

# Path: aqmt/processes.py
# def kill_known_pids():
# def add_known_pid(pid):
# def kill_pid(pid):
# def is_running(pid):
# def waitpid(pid):
# 
# Path: aqmt/plot/collectionutil.py
# def get_tree_details(tree):
#     def traverse(branch, depthnow=0):
# def get_gap(tree):
# def get_testcases(leaf):
# def get_all_testcases_folders(tree):
#     def parse_leaf(leaf, first_set, x):
# def make_xtics(tree, xoffset, x_axis):
#     def frange(start, stop, step):
# def get_testmeta_min_max_count(leaf, x_axis):
# def get_x_coordinate(leaf, value, x_axis):
# def merge_testcase_data_set_x(testcases, x_axis):
# def get_leaf_tests_stats(leaf, statsname):
# def merge_testcase_data(leaf, statsname, x_axis):
# def merge_testcase_data_group(leaf, statsname, x_axis):
# def get_xlabel(tree):
#     def fn(leaf, first_set, x):
# def pt_generator():
#     def get_val(tag):
# 
# Path: aqmt/plot/treeutil.py
# def get_depth_sizes(tree):
#     def check_node(item, x, depth):
# def walk_leaf(tree, fn):
#     def walk(branch):
# def walk_tree_reverse(tree, fn):
#     def walk(branch, depth=0):
# def walk_tree(tree, fn, include_leaf_collection=False):
#     def walk(collection, depth=0):
# def swap_levels(tree, level=0):
#         def walk(branch, depth):
#     def check_level(node, x, depth):
#     def build_swap(node, x, depth):
# def build_swap_list(level_order):
# def reorder_levels(tree, level_order=None):
# def skip_levels(tree, number_of_levels):
# 
# Path: aqmt/plot/common.py
# def add_plot(gpi):
#     """
#     Remove trailing comma from plot command because gnuplot complains about it
#     (We use the trailing comma to easier build plot commands)
#     """
#     return re.sub(r',(\s*\\?\s*\\?\s*)$', '\g<1>', gpi)
# 
# def add_scale(y_logarithmic, range_from=None, range_from_log=None,
#         range_to=None, range_to_log=None):
#     if y_logarithmic:
#         if range_from_log is None:
#             range_from_log = '1'
#         if range_to_log is None:
#             range_to_log = '*'
#         return """
#             set logscale y
#             set yrange [""" + range_from_log + """:""" + range_to_log + """]
#             """
#     else:
#         if range_from is None:
#             range_from = '0'
#         if range_to is None:
#             range_to = '1<*'
#         return """
#             set yrange [""" + range_from + """:""" + range_to + """]
#             """
# 
# Path: aqmt/testenv.py
# def read_metadata(file):
#     """
#     Reads metadata from a `details` file
# 
#     Returns a map of the properties as well as a list of properties to be used
#     if properties of the same key is repeated
#     """
#     if not os.path.isfile(file):
#         raise Exception('Missing metadata file: ' + file)
# 
#     metadata = {}
#     lines = []
# 
#     with open(file, 'r') as f:
#         for line in f:
#             s = line.split(maxsplit=1)
#             key = s[0]
#             value = s[1].strip() if len(s) > 1 else ''
#             metadata[key.strip()] = value
#             lines.append((key, value))
# 
#     return metadata, lines


# Path: aqmt/plugins/ss_rtt.py
import numpy as np
import operator
import os
from functools import partial
from plumbum.cmd import bash
from aqmt import processes
from aqmt.plot import collectionutil, treeutil
from aqmt.plot.common import add_plot, add_scale
from ..testenv import read_metadata


        ylabel_extra = ''
        if subtract_base_rtt:
            ylabel_extra = '\\n{/Times:Italic=10 Excluding base RTT}'

        gpi = """
            set ylabel "RTT at sender""" + ylabel_extra + """\\n{/Times:Italic=10 [ms] (p_1, mean, p_{99})}"
            """ + add_scale(y_logarithmic)

        # add hidden line to force autoscaling if using logarithimic plot without any points
        plot_gpi = " 1 lc rgb '#FFFF0000' notitle, \\\n"

        def leaf(subtree, is_first_set, x):
            nonlocal gpi, plot_gpi
            leaf_hook(subtree, is_first_set, x)
            add_title = keys and is_first_set

            def parse_rtt(node, testcase_folder):
                rtts = _parse_rtt_of_test(testcase_folder, node, subtract_base_rtt)

                # take last half, so it is stable
                rtts = rtts[int(len(rtts)/2):]

                # get second element of list which is the rtt value
                rtts = [x[1] for x in rtts]

                return _generate_stats(rtts)

            gpi += """
                $data_rtt_a""" + str(x) + """ << EOD

                """ + collectionutil.merge_testcase_data(subtree, partial(parse_rtt, 'A'), plotdef.x_axis) + """