<jupyter_start><jupyter_text>Data preparation<jupyter_code>import sqlite3
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import Cdf
import Pmf

# define global plot parameters
params = {'axes.labelsize' : 12, 'axes.titlesize' : 12,
          'font.size' : 12, 'legend.fontsize' : 12,
          'xtick.labelsize' : 10, 'ytick.labelsize' : 12}
plt.rcParams.update(params)
plt.rcParams.update({'figure.max_open_warning': 0})

# connect to database and get data
conn = sqlite3.connect('data/youtube-traceroute.db')

# read necessary tables from database
pair_medians = pd.read_sql_query('select * from pair_medians', conn)

conn.close()<jupyter_output><empty_output><jupyter_text>CDF over deltas of destination pairs for TTL and RTT<jupyter_code># get CDF
ttl_cdf = Cdf.MakeCdfFromList(pair_medians['ttl_delta'])
rtt_cdf = Cdf.MakeCdfFromList(pair_medians['rtt_delta'])
## Both TTL and RTT in one plot
cdf_fig, cdf_ax = plt.subplots(figsize = (5, 2))
cdf_ax.plot(rtt_cdf.xs, rtt_cdf.ps,
            label = 'RTT delta [ms]',
            marker = '^',
            linewidth = 0.5,
            markersize = 3,
            fillstyle = 'none',
            color = 'green')
cdf_ax.plot(ttl_cdf.xs, ttl_cdf.ps,
            label = 'TTL delta',
            marker = 's',
            linewidth = 1.5,
            markersize = 3,
            fillstyle = 'none',
            color = 'orange')

# PLOT FORMATTING
# customize axes and grid appearance
cdf_ax.legend(loc = 'lower right', fontsize = 'smaller')
cdf_ax.set_xscale('symlog')
cdf_ax.set_xlim([-1250, 1250])
cdf_ax.set_ylim([-0.05, 1.05])
cdf_ax.set_xlabel('delta')
cdf_ax.set_ylabel('CDF')

yticks = np.arange(0.0, 1.01, 0.2)
cdf_ax.set_yticks(yticks)
cdf_ax.grid(False)
cdf_ax.spines['right'].set_color('none')
cdf_ax.spines['top'].set_color('none')
cdf_ax.yaxis.set_ticks_position('left')
cdf_ax.xaxis.set_ticks_position('bottom')
cdf_ax.spines['bottom'].set_position(('axes', -0.02))
cdf_ax.spines['left'].set_position(('axes', -0.02))

from matplotlib.ticker import ScalarFormatter
cdf_ax.xaxis.set_major_formatter(ScalarFormatter())


# add arrows and text which indicate in which region IPv6 was better/worse than IPv4
cdf_ax.annotate('', xy = (0.4, 1.1),
                xycoords = 'axes fraction',
                xytext = (0.1, 1.1),
                arrowprops = dict(arrowstyle = '<-'))
cdf_ax.annotate('', xy = (0.9, 1.1),
                xycoords = 'axes fraction',
                xytext = (0.6, 1.1),
                arrowprops = dict(arrowstyle = '->'))
cdf_ax.text(-70, 1.2, 'IPv6 slower')
cdf_ax.text(2.5, 1.2, 'IPv6 faster')

# dotted vertical line to separate positive and negative delta region
cdf_ax.axvline(0, linestyle = 'dotted', color = 'black', linewidth = 0.5)

# saving and showing plot
cdf_fig.savefig('plots/destination_pair_cdf.pdf', bbox_inches = 'tight')
plt.show()
# get rough idea of absolute distribution of TTL deltas
pair_medians.groupby(['ttl_delta']).size()<jupyter_output><empty_output><jupyter_text>Distributions of median deltas<jupyter_code>print('------ TTL ------')
print('m_ttl_delta; cdf')
print('-----------------')
for x, y in zip(ttl_cdf.xs, ttl_cdf.ps):
    print('%.2f; %.5f' % (x, y))
print('------ RTT ------')
print('m_rtt_delta; cdf')
print('-----------------')
for x, y in list(zip(rtt_cdf.xs, rtt_cdf.ps))[0::100]:
    print('%.2f; %.5f' % (x, y))<jupyter_output>------ RTT ------
m_rtt_delta; cdf
-----------------
-9961.96; 0.00002
-275.92; 0.00235
-139.20; 0.00466
-85.51; 0.00697
-63.05; 0.00928
-53.78; 0.01161
-49.16; 0.01394
-48.32; 0.01639
-47.89; 0.01888
-46.49; 0.02126
-45.76; 0.02368
-44.51; 0.02599
-40.76; 0.02832
-37.06; 0.03070
-35.30; 0.03300
-33.93; 0.03536
-31.16; 0.03774
-29.22; 0.04009
-28.01; 0.04251
-26.54; 0.04491
-25.43; 0.04734
-23.74; 0.04965
-22.80; 0.05200
-21.62; 0.05442
-20.68; 0.05680
-19.61; 0.05925
-18.93; 0.06174
-18.52; 0.06432
-18.17; 0.06691
-17.92; 0.06966
-17.73; 0.07247
-17.51; 0.07529
-17.27; 0.07808
-17.06; 0.08073
-16.77; 0.08346
-16.41; 0.08597
-15.99; 0.08856
-15.52; 0.09107
-15.06; 0.09350
-14.94; 0.09768
-14.71; 0.10038
-14.31; 0.10305
-13.76; 0.10559
-13.10; 0.10804
-12.54; 0.11049
-11.97; 0.11295
-11.46; 0.11545
-10.99; 0.11794
-10.60; 0.12048
-10.25; 0.12318
-9.88; 0.12576
-9.54; 0.12835
-9.24; 0.13107
-9.00; 0.13377
-8.78; 0.13657
-8.56; 0.13938
-8.33; 0.14197
-8.08; 0.14462
-7.79; 0.14737
-7.51; 0[...]
{'fraction_non_alphanumeric': 0.18994540491355777, 'fraction_numerical': 0.15423111919927207, 'mean_word_length': 3.00090991810737, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '140049', 'license': 'MIT', 'n_tokens_mistral': 2339, 'n_tokens_neox': 1904, 'n_words': 389, 'path': 'nb-destination_pair_deltas.ipynb', 'repo_name': 'tv-doan/youtube-traceroutes', 'size': '4396'}