Skip to content
Snippets Groups Projects
parse_rtcm3_logs.ipynb 7.08 KiB
Newer Older
Ashwin Rao's avatar
Ashwin Rao committed
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Parse the RTCM3 Logs\n",
    "import seaborn as sns\n",
    "import pandas\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "import matplotlib.pyplot as plt\n",
    "import numpy\n",
    "\n",
    "# to avoid type 3 fonts. \n",
    "plt.rc('pdf',fonttype = 42)"
Ashwin Rao's avatar
Ashwin Rao committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Read the files and pre process them for plotting. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read the file\n",
    "timestamps = pandas.read_csv(\"./timestamps.csv\")\n",
    "\n",
    "# Compute the latency in ms \n",
    "timestamps[\"Latency\"] = (timestamps[\"ts_client\"]-timestamps[\"ts_relay\"])*1000\n",
    "\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "# Remember the diff is still in seconds. \n",
Ashwin Rao's avatar
Ashwin Rao committed
    "timestamps['relay_iat'] = timestamps['ts_relay'].diff()\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "timestamps['relay_iat'] = timestamps['relay_iat'].apply(lambda x : x if x > 0 else numpy.nan)  # Dirty hack for jumps between experiments.\n",
    "timestamps['relay_iat'] = timestamps['relay_iat'].apply(lambda x : x if x < 100 else numpy.nan)  # Dirty hack for jumps between experiments.\n",
    "\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "timestamps['client_iat'] = timestamps['ts_client'].diff()\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "timestamps['client_iat'] = timestamps['client_iat'].apply(lambda x : x if x > 0 else numpy.nan)  # Dirty hack for jumps between experiments.\n",
    "timestamps['client_iat'] = timestamps['client_iat'].apply(lambda x : x if x < 100 else numpy.nan)  # Dirty hack for jumps between experiments.\n",
    "\n",
    "# Inter-arrival time between messages. The diff is in millisec.  \n",
    "timestamps['iat_diff'] = abs(timestamps['relay_iat']-timestamps['client_iat'])*1000\n",
    "print(timestamps[\"iat_diff\"])\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "\n",
    "\n",
    "ping = pandas.read_csv(\"./ping.csv\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "#print(ping)\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "ping['Latency'] = ping['rtt']/2.0\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "\n",
    "print(timestamps[timestamps[\"Latency\"] == max(timestamps[\"Latency\"])])\n"
Ashwin Rao's avatar
Ashwin Rao committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Ashwin Rao's avatar
Ashwin Rao committed
   "metadata": {
    "scrolled": true
   },
Ashwin Rao's avatar
Ashwin Rao committed
   "outputs": [],
   "source": [
Ashwin Rao's avatar
Ashwin Rao committed
    "fig, ax = plt.subplots(figsize=(17.5,5))\n",
    "sns.set_context(\"poster\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.set_style(\"white\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.color_palette(\"husl\", 8)\n",
    "\n",
    "\n",
    "#plot_data = timestamps[timestamps[\"Technology\"].isin([\"Ethernet\", \"Wi-Fi(PE)\", \"Wi-Fi(PE)\", \"5G(BE)\", \"5G(BD)\"]) ]\n",
    "plot_data = timestamps\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.boxplot(data=plot_data, x=\"Location\", y=\"Latency\",hue=\"Technology\", whis=[5,95], showfliers=False)\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "        \n",
Ashwin Rao's avatar
Ashwin Rao committed
    "handles, labels = ax.get_legend_handles_labels()    \n",
    "ax.set_yticklabels(labels=['0.1', '1', '10', '100'])\n",
    "ax.set_ylim(0.1,300)\n",
    "ax.set_xlabel(\"Location\", weight=\"bold\")\n",
    "ax.set_ylabel(\"Latency (ms)\", weight=\"bold\")\n",
    "handles, labels = ax.get_legend_handles_labels()\n",
    "ax.legend(ncol=5, title=\"Technology\", bbox_to_anchor=(-0.02, 1.35), loc=\"upper left\")\n",
    "ax.set_yscale(\"log\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "ax.grid(True, which='major', axis='y')\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "ax.grid(True, which='minor', axis='y')\n",
    "\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "plt.savefig(\"timestamps.pdf\", dpi=1200, bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plot the one way latency between the client and the relay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
Ashwin Rao's avatar
Ashwin Rao committed
   "source": [
    "fig, ax = plt.subplots(figsize=(17.5,5))\n",
    "sns.set_context(\"poster\"),\n",
    "sns.set_style(\"white\")\n",
    "sns.set_palette(\"colorblind\")\n",
    "\n",
    "sns.boxplot(data=ping, x=\"Location\", y=\"Latency\",hue=\"Technology\", whis=[5,95], showfliers=False)\n",
    "\n",
    "ax.set_ylim(0.1,300)\n",
    "ax.set_xlabel(\"Location\", weight=\"bold\")\n",
    "ax.set_ylabel(\"Latency (ms)\", weight=\"bold\")\n",
    "ax.legend(ncol=5, title=\"Technology\", bbox_to_anchor=(-0.02, 1.35), loc=\"upper left\")\n",
    "ax.set_yscale(\"log\")\n",
    "ax.grid(True, which='major', axis='y')\n",
    "ax.grid(True, which='minor', axis='y')\n",
    "plt.savefig(\"ping.pdf\", dpi=1200, bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plot the difference in the inter-arrival time of the messages. "
   ]
Ashwin Rao's avatar
Ashwin Rao committed
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
Ashwin Rao's avatar
Ashwin Rao committed
    "fig, ax = plt.subplots(figsize=(17.5,5))\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.set_context(\"poster\"),\n",
    "sns.set_style(\"white\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.set_palette(\"colorblind\")\n",
    "\n",
    "\n",
    "sns.boxplot(data=timestamps, x=\"Location\", y=\"iat_diff\",hue=\"Technology\", whis=[5,95], showfliers=False)\n",
    "ax.set_ylim(0.01,300)\n",
    "ax.set_xlabel(\"Location\", weight=\"bold\")\n",
    "ax.set_ylabel(\"Inter-arrival Time \\n Difference (ms)\", weight=\"bold\")\n",
    "#ax.set_yscale(\"log\")\n",
    "ax.legend(ncol=5, title=\"Technology\", bbox_to_anchor=(-0.02, 1.35), loc=\"upper left\")\n",
    "ax.set_yscale(\"log\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "ax.grid(True, which='major', axis='y')\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "ax.grid(True, which='minor', axis='y')\n",
    "plt.savefig(\"iat.pdf\", dpi=1200, bbox_inches='tight')"
Ashwin Rao's avatar
Ashwin Rao committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Ashwin Rao's avatar
Ashwin Rao committed
    "# Plot the CDF of the IAT"
Ashwin Rao's avatar
Ashwin Rao committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
Ashwin Rao's avatar
Ashwin Rao committed
    "fig, ax = plt.subplots(figsize=(15,5))\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.set_context(\"poster\"),\n",
    "sns.set_style(\"white\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "sns.set_palette(\"colorblind\")\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "\n",
Ashwin Rao's avatar
Ashwin Rao committed
    "\n",
    "def ecdf(x):\n",
    "    xs = numpy.sort(x)\n",
    "    ys = numpy.arange(1, len(xs)+1)/float(len(xs))\n",
    "    return xs, ys\n",
    "\n",
    "plot_data = timestamps[timestamps[\"relay_iat\"].notnull()]\n",
    "#plot_data = plot_data[plot_data[\"relay_iat\"]>0]\n",
    "\n",
    "x = plot_data[\"relay_iat\"]*1000 # Convert to ms.\n",
    "xs, ys = ecdf(x)\n",
    "plt.plot(xs,ys)\n",
    "ax.set_xscale(\"log\")\n",
    "ax.grid(True, which='major')\n",
    "ax.grid(True, which='minor')\n",
    "ax.set_ylabel(\"ECDF\", weight=\"bold\")\n",
    "ax.set_xlabel(\"Inter Arrival Time (ms)\", weight=\"bold\")\n",
    "plt.savefig(\"ecdfiat.pdf\", dpi=1200, bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for font in plt.rcParams['font.sans-serif']:\n",
    "    print(font)\n"
Ashwin Rao's avatar
Ashwin Rao committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "5Give-venv",
   "language": "python",
   "name": "5give-venv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}