# Path: parsing_scripts/parse_ctcp_output.py
# def parse_file(filename, print_csv=False):
# 
# Path: parsing_scripts/parse_tcptrace.py
# def parse_file(filename, endpt_name="csail.mit.edu", dst_endpt_name="csail.mit.edu", print_csv=False):


import argparse
import math
import os
import pickle
import random
import re
from fractions import Fraction
from parsing_scripts import parse_ctcp_output
from parsing_scripts import parse_tcptrace
		# 	1.0,
		# 	'kernel',
		# 	os.path.join(output_directory, 'kernel')
		# )

def weighted_means(data):
  """ Returns (average throughput, average rtt from data)"""
  avg_throughput, avg_rtt = 0.0, 0.0
  tot_time, tot_pkts = 0.0, 0.0
  for conn in data:
    try:
      avg_throughput += conn['Throughput'] * conn['TransmitTime']
      avg_rtt += conn['RTT'] * conn['NumPkts']
      tot_time += conn['TransmitTime']
      tot_pkts += conn['NumPkts']
    except:
      print "Error:- "
      print conn

  if tot_time == 0 or tot_pkts == 0:
    return (None, None)
  avg_throughput /= tot_time
  avg_rtt /= tot_pkts

  return (avg_throughput, avg_rtt)

def analyse_pkl_data(input_directory):
	re_mahimahi_name = re.compile(r"""
		rawout-(?P<ratname>.*)-
		(?P<linkrate>[0-9.]+)-

# Path: parsing_scripts/parse_ctcp_output.py
# def parse_file(filename, print_csv=False):
# 
# Path: parsing_scripts/parse_tcptrace.py
# def parse_file(filename, endpt_name="csail.mit.edu", dst_endpt_name="csail.mit.edu", print_csv=False):


# Path: random-range-tests.py
import argparse
import math
import os
import pickle
import random
import re
from fractions import Fraction
from parsing_scripts import parse_ctcp_output
from parsing_scripts import parse_tcptrace

		# 	1.0,
		# 	'kernel',
		# 	os.path.join(output_directory, 'kernel')
		# )

def weighted_means(data):
  """ Returns (average throughput, average rtt from data)"""
  avg_throughput, avg_rtt = 0.0, 0.0
  tot_time, tot_pkts = 0.0, 0.0
  for conn in data:
    try:
      avg_throughput += conn['Throughput'] * conn['TransmitTime']
      avg_rtt += conn['RTT'] * conn['NumPkts']
      tot_time += conn['TransmitTime']
      tot_pkts += conn['NumPkts']
    except:
      print "Error:- "
      print conn

  if tot_time == 0 or tot_pkts == 0:
    return (None, None)
  avg_throughput /= tot_time
  avg_rtt /= tot_pkts

  return (avg_throughput, avg_rtt)

def analyse_pkl_data(input_directory):
	re_mahimahi_name = re.compile(r"""
		rawout-(?P<ratname>.*)-
		(?P<linkrate>[0-9.]+)-

		(?P<minrtt>[0-9.]+)-