#!./venv/bin/python

import os
import sys

import matplotlib.pyplot as plt
import numpy as np

# Read file from argument
path = str(sys.argv[1])
with open(path) as f:
    values = f.readlines()
values = [float(x.strip()) for x in values]

points = np.arange(1, len(values) + 1, step=1)

# Calculate the simple average of the data
value_mean = [np.mean(values)] * len(points)
fig, ax = plt.subplots()

# Plot the data
data_line = ax.plot(points, values, label="Data", marker="o")

# Plot the average line
mean_line = ax.plot(
    points, value_mean, label="Mean=" + str(round(value_mean[0], 4)), linestyle="--"
)

# Make a legend
legend = ax.legend(loc="upper right")

# Plot values
plt.plot(points, values, marker="o", color="b", linestyle="-")

# Make sure x-axis has correct steps
plt.xticks(points)

# Uncomment for grid
# plt.grid(color="r", linestyle=":", linewidth=1)

plt.xlabel("Packet count")
plt.ylabel("RTT in ms")
filename = "plots/PLOT_" + os.path.basename(path)[:-4]
plt.savefig(filename + ".png")

#!./venv/bin/python

import os
import sys

import matplotlib.pyplot as plt
import numpy as np

# Read file from argument
path = str(sys.argv[1])
with open(path) as f:
    values = f.readlines()
values = [float(x.strip()) for x in values]

points = np.arange(1, len(values) + 1, step=1)

# Calculate the simple average of the data
value_mean = [np.mean(values)] * len(points)
fig, ax = plt.subplots()

# Plot the data
data_line = ax.plot(points, values, label="Data", marker="o")

# Plot the average line
mean_line = ax.plot(
    points, value_mean, label="Mean=" + str(round(value_mean[0], 4)), linestyle="--"
)

# Make a legend
legend = ax.legend(loc="upper right")

# Plot values
plt.plot(points, values, marker="o", color="b", linestyle="-")

# Make sure x-axis has correct steps
plt.xticks(points)

# Uncomment for grid
# plt.grid(color="r", linestyle=":", linewidth=1)

plt.xlabel("Packet count")
plt.ylabel("RTT in ms")
filename = "plots/PLOT_" + os.path.basename(path)[:-4]
plt.savefig(filename + ".png")

#!./venv/bin/python # Read file from argument # Calculate the simple average of the data # Plot the data # Plot the average line # Make a legend # Plot values # Make sure x-axis has correct steps # Uncomment for grid # plt.grid(color="r", linestyle=":", linewidth=1)