Compare commits

..

No commits in common. "ff16bd3a20cfb8c1381867d62725f608ad108c35" and "5e10cefc62317b47b0e7f58babdaa390e9a26f3e" have entirely different histories.

3 changed files with 119 additions and 152 deletions

View File

@ -49,7 +49,7 @@ def get_modem_cops(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["cops error"] = f"{e}" dictionary["cops error"] = f"{e}"
return dictionary return dictionary
@ -79,7 +79,7 @@ def get_modem_creg(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["creg error"] = f"{e}" dictionary["creg error"] = f"{e}"
return dictionary return dictionary
@ -110,7 +110,7 @@ def get_modem_csq(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["csq error"] = f"{e}" dictionary["csq error"] = f"{e}"
return dictionary return dictionary
@ -150,7 +150,7 @@ def get_modem_rsrp(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qrsrp error"] = f"{e}" dictionary["qrsrp error"] = f"{e}"
return dictionary return dictionary
@ -190,7 +190,7 @@ def get_modem_rsrq(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qrsrq error"] = f"{e}" dictionary["qrsrq error"] = f"{e}"
return dictionary return dictionary
@ -229,7 +229,7 @@ def get_modem_sinr(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qsinr error"] = f"{e}" dictionary["qsinr error"] = f"{e}"
return dictionary return dictionary
@ -271,7 +271,7 @@ def get_modem_cpol(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["cpol error"] = f"{e}" dictionary["cpol error"] = f"{e}"
return dictionary return dictionary
@ -310,7 +310,7 @@ def get_modem_qnwcfg(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qnwcfg error"] = f"{e}" dictionary["qnwcfg error"] = f"{e}"
return dictionary return dictionary
@ -338,7 +338,7 @@ def get_modem_qnwinfo(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qnwinfo error"] = f"{e}" dictionary["qnwinfo error"] = f"{e}"
return dictionary return dictionary
@ -366,5 +366,5 @@ def get_modem_qspn(port="/dev/ttyUSB2", baudrate=115200, dictionary={}):
except Exception as e: except Exception as e:
dictionary["qspn error"] = f"{e}" dictionary["qspn error"] = f"{e}"
return dictionary return dictionary

View File

@ -134,7 +134,7 @@ def save_data_to_json(data, filename):
def fix_long(bad_long): def fix_long(bad_long):
""" """
Fix longitude values incorrectly parsed from NMEA (leading zero dropped degrees). Fix longitude values incorrectly parsed from NMEA (leading zero dropped degrees).
Assumes all values should be around -79.x based on recording location. Assumes all values should be around -79.x based on recording location.
Removes the spurious leading digit from minutes. Removes the spurious leading digit from minutes.
""" """
@ -159,17 +159,18 @@ def add_distance_after(filename: str, base_location: dict):
with open(filename, "r") as file: with open(filename, "r") as file:
data = json.load(file) data = json.load(file)
except FileNotFoundError: except FileNotFoundError:
print("No file by that name") print('No file by that name')
return None return None
distance = "Unknown" distance = 'Unknown'
for dictionary in data: for dictionary in data:
if "latitude" in dictionary and type(dictionary["latitude"]) == float: if 'latitude' in dictionary:
# dictionary['longitude'] = fix_long(dictionary['longitude'])
distance = calculate_distance(base_location, dictionary) distance = calculate_distance(base_location, dictionary)
dictionary["distance"] = distance dictionary["distance"] = distance
elif "iperf_full" in dictionary: elif 'iperf_full' in dictionary:
dictionary["start_distance"] = distance dictionary['start_distance'] = distance
# Save updated data back to the file # Save updated data back to the file
with open(filename, "w") as file: with open(filename, "w") as file:
@ -177,15 +178,10 @@ def add_distance_after(filename: str, base_location: dict):
if __name__ == "__main__": if __name__ == "__main__":
filenames = [ filename = '/home/madrigal/repos/range-testing/data/boat_relay_sept_17/test_1758123903_copy.json'
"/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758215714_copy.json",
"/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758217711_copy.json",
"/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758219350_copy.json"
]
base_location = { base_location = {
"latitude": 43.656328, 'latitude': 43.656328,
"longitude": -79.307884, 'longitude': -79.307884,
"altitude": 80, 'altitude': 80,
} }
for filename in filenames: add_distance_after(filename=filename, base_location=base_location)
add_distance_after(filename=filename, base_location=base_location)

219
plots.py
View File

@ -62,65 +62,6 @@ def plot_rsrp(filename):
plt.show() plt.show()
def plot_median_rsrp(filename):
# Load the JSON file
with open(filename, "r") as file:
data = json.load(file)
# Extract distance and RSRP values (convert RSRP values to integers)
distances = []
rsrps = []
for entry in data:
try:
int(float(entry["distance"]))
antennas = []
antennas.append(
-169
if int(entry["RSRP PRX"].strip()) == -32768
else int(entry.get("RSRP PRX", -169))
)
antennas.append(
-169
if int(entry["RSRP DRX"].strip()) == -32768
else int(entry.get("RSRP DRX", -169))
)
antennas.append(
-169
if int(entry["RSRP RX2"].strip()) == -32768
else int(entry.get("RSRP RX2", -169))
)
antennas.append(
-169
if int(entry["RSRP RX3"].strip()) == -32768
else int(entry.get("RSRP RX3", -169))
)
antennas.remove(max(antennas))
antennas.remove(min(antennas))
if min(antennas) == -169 and max(antennas) != -169:
avg_rsrp = max(antennas)
else:
avg_rsrp = sum(antennas)/len(antennas)
rsrps.append(avg_rsrp)
distances.append(int(float(entry["distance"])))
except (ValueError, KeyError):
continue
# Plot the data
plt.figure(figsize=(10, 6))
plt.plot(distances, rsrps, label="RSRP PRX", marker="o", color="blue",)
plt.title("RSRP vs Distance")
plt.xlabel("Distance (m)")
plt.ylabel("RSRP (dBm)")
plt.legend()
plt.grid(True)
plt.tight_layout()
# Show the plot
plt.show()
def plot_rsrq(filename): def plot_rsrq(filename):
# Load the JSON file # Load the JSON file
with open(filename, "r") as file: with open(filename, "r") as file:
@ -178,57 +119,107 @@ def plot_rsrq(filename):
plt.show() plt.show()
def plot_median_rsrq(filename): def plot_iperf(filename):
# Load the JSON file # Load the JSON file
with open(filename, "r") as file: with open(filename, "r") as file:
data = json.load(file) data = json.load(file)
# Extract distance and RSRQ values (convert RSRQ values to integers)
distances = [] distances = []
rsrqs = [] sender = []
receiver = []
for entry in data: for entry in data:
try: try:
antennas = [] message = entry["iperf_full"]
int(float(entry["distance"])) bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
antennas.append(
-20 sender.append(float(bitrates[-2]))
if int(entry["RSRQ PRX"].strip()) == -32768 receiver.append(float(bitrates[-1]))
else int(entry.get("RSRQ PRX", -20)) distances.append(entry["start_distance"])
)
antennas.append(
-20
if int(entry["RSRQ DRX"].strip()) == -32768
else int(entry.get("RSRQ DRX", -20))
)
antennas.append(
-20
if int(entry["RSRQ RX2"].strip()) == -32768
else int(entry.get("RSRQ RX2", -20))
)
antennas.append(
-20
if int(entry["RSRQ RX3"].strip()) == -32768
else int(entry.get("RSRQ RX3", -20))
)
antennas.remove(max(antennas))
antennas.remove(min(antennas))
if min(antennas) == -169 and max(antennas) != -20:
avg_rsrq = max(antennas)
else:
avg_rsrq = sum(antennas)/len(antennas)
rsrqs.append(avg_rsrq)
distances.append(int(float(entry["distance"])))
except (ValueError, KeyError): except (ValueError, KeyError):
continue continue
# Plot the data # Plot the data
plt.figure(figsize=(10, 6)) plt.figure(figsize=(10, 6))
plt.plot(distances, rsrqs, label="RSRQ PRX", marker="o", color="blue") plt.plot(distances, sender, label="Avg Sender Bitrate", marker="o")
plt.plot(distances, receiver, label="Avg Receiver Bitrate", marker="s")
plt.title("RSRQ vs Distance") plt.title("IPERF vs Distance")
plt.xlabel("Distance (m)") plt.xlabel("Distance (m)")
plt.ylabel("RSRQ (dBm)") plt.ylabel("Bitrate (Mbits/s)")
plt.legend()
plt.grid(True)
plt.tight_layout()
# Show the plot
plt.show()
def plot_bytes(filename):
# Load the JSON file
with open(filename, "r") as file:
data = json.load(file)
distances = []
uplink = []
downlink = []
for entry in data:
try:
if (
int(entry["uplink (bytes/s)"].strip()) < 1000000
and int(entry["downlink (bytes/s)"].strip()) < 1000000
):
distances.append(entry["distance"])
uplink.append(int(entry["uplink (bytes/s)"].strip()))
downlink.append(int(entry["downlink (bytes/s)"].strip()))
except (ValueError, KeyError):
continue
# Plot the data
plt.figure(figsize=(10, 6))
plt.plot(distances, downlink, label="Downlink Bitrate", marker="o")
plt.plot(distances, uplink, label="Uplink Bitrate", marker="s")
plt.title("Bitrate vs Distance")
plt.xlabel("Distance (m)")
plt.ylabel("Bitrate (bytes/s)")
plt.legend()
plt.grid(True)
plt.tight_layout()
# Show the plot
plt.show()
def plot_manual():
distances = [0, 100, 200, 300, 400, 500, 600, 700, 800]
rsrps = [-56, -82, -90, -93, -100, -105, -105, -116, -150]
sender = [0, 6.06, 6.95, 6.37, 6.96, 8.04, 7.30, 0, 0]
receiver = [0, 5.20, 6.10, 5.24, 6.08, 6.84, 6.37, 0, 0]
# Plot the RSRP data
plt.figure(figsize=(10, 6))
plt.plot(distances, rsrps, label="RSRP", marker="o")
plt.title("RSRP vs Distance")
plt.xlabel("Distance (m)")
plt.ylabel("RSRP (dBm)")
plt.legend()
plt.grid(True)
plt.tight_layout()
# Show the plot
plt.show()
# Plot the iperf data
plt.figure(figsize=(10, 6))
plt.plot(distances, sender, label="Avg Sender Bitrate", marker="o")
plt.plot(distances, receiver, label="Avg Receiver Bitrate", marker="s")
plt.title("IPERF vs Distance")
plt.xlabel("Distance (m)")
plt.ylabel("Bitrate (Mbits/s)")
plt.legend() plt.legend()
plt.grid(True) plt.grid(True)
plt.tight_layout() plt.tight_layout()
@ -250,37 +241,35 @@ def plot_double_iperf(filename):
reverse_receiver = [] reverse_receiver = []
for entry in data: for entry in data:
if "iperf_full" in entry and entry["start_distance"] != "Unknown": if "iperf_full" in entry:
if "Reverse mode" in entry["iperf_full"]: if "Reverse mode" in entry["iperf_full"]:
try: try:
reverse_sender.append(float(entry["sender_bitrate"])) reverse_sender.append(float(entry["sender_bitrate"]))
reverse_receiver.append(float(entry["receiver_bitrate"])) reverse_receiver.append(float(entry["receiver_bitrate"]))
reverse_distances.append(int(float(entry["start_distance"]))) reverse_distances.append(entry["start_distance"])
except: except:
message = entry["iperf_full"] message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message) bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
reverse_sender.append(float(bitrates[-2])) reverse_sender.append(float(bitrates[-2]))
reverse_receiver.append(float(bitrates[-1])) reverse_receiver.append(float(bitrates[-1]))
reverse_distances.append(int(float(entry["start_distance"]))) reverse_distances.append(entry["start_distance"])
else: else:
try: try:
sender.append(float(entry["sender_bitrate"])) sender.append(float(entry["sender_bitrate"]))
receiver.append(float(entry["receiver_bitrate"])) receiver.append(float(entry["receiver_bitrate"]))
distances.append(int(float(entry["start_distance"]))) distances.append(entry["start_distance"])
except: except:
message = entry["iperf_full"] message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message) bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
sender.append(float(bitrates[-2])) sender.append(float(bitrates[-2]))
receiver.append(float(bitrates[-1])) receiver.append(float(bitrates[-1]))
distances.append(int(float(entry["start_distance"]))) distances.append(entry["start_distance"])
# Plot the data # Plot the data
plt.figure(figsize=(10, 6)) plt.figure(figsize=(10, 6))
plt.plot( plt.plot(distances, sender, label="Avg Uplink Sender Bitrate", marker="o", color="red")
distances, sender, label="Avg Uplink Sender Bitrate", marker="o", color="red"
)
plt.plot( plt.plot(
distances, distances,
receiver, receiver,
@ -315,26 +304,8 @@ def plot_double_iperf(filename):
if __name__ == "__main__": if __name__ == "__main__":
filename = "/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758215714_copy.json" filename = '/home/madrigal/repos/range-testing/data/boat_relay_sept_17/test_1758127491_copy.json'
# plot_double_iperf(filename=filename) # plot_double_iperf(filename=filename)
# plot_rsrp(filename=filename) plot_rsrp(filename=filename)
# plot_rsrq(filename=filename) plot_rsrq(filename=filename)
plot_median_rsrp(filename=filename)
plot_median_rsrq(filename=filename)
filename = "/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758217711_copy.json"
# plot_double_iperf(filename=filename)
# plot_rsrp(filename=filename)
# plot_rsrq(filename=filename)
plot_median_rsrp(filename=filename)
plot_median_rsrq(filename=filename)
filename = "/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758219350_copy.json"
# plot_double_iperf(filename=filename)
# plot_rsrp(filename=filename)
# plot_rsrq(filename=filename)
plot_median_rsrp(filename=filename)
plot_median_rsrq(filename=filename)