Compare commits

..

2 Commits

Author SHA1 Message Date
ff16bd3a20 Added median rsrp and rsrq functions, removed unused functions 2025-09-19 09:57:54 -04:00
1fc33eb6f4 Linting, minor fixes 2025-09-19 09:41:03 -04:00
3 changed files with 152 additions and 119 deletions

View File

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

View File

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

219
plots.py
View File

@ -62,6 +62,65 @@ def plot_rsrp(filename):
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):
# Load the JSON file
with open(filename, "r") as file:
@ -119,107 +178,57 @@ def plot_rsrq(filename):
plt.show()
def plot_iperf(filename):
def plot_median_rsrq(filename):
# Load the JSON file
with open(filename, "r") as file:
data = json.load(file)
# Extract distance and RSRQ values (convert RSRQ values to integers)
distances = []
sender = []
receiver = []
rsrqs = []
for entry in data:
try:
message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
sender.append(float(bitrates[-2]))
receiver.append(float(bitrates[-1]))
distances.append(entry["start_distance"])
antennas = []
int(float(entry["distance"]))
antennas.append(
-20
if int(entry["RSRQ PRX"].strip()) == -32768
else int(entry.get("RSRQ PRX", -20))
)
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):
continue
# Plot the 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.plot(distances, rsrqs, label="RSRQ PRX", marker="o", color="blue")
plt.title("IPERF vs Distance")
plt.title("RSRQ vs Distance")
plt.xlabel("Distance (m)")
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.ylabel("RSRQ (dBm)")
plt.legend()
plt.grid(True)
plt.tight_layout()
@ -241,35 +250,37 @@ def plot_double_iperf(filename):
reverse_receiver = []
for entry in data:
if "iperf_full" in entry:
if "iperf_full" in entry and entry["start_distance"] != "Unknown":
if "Reverse mode" in entry["iperf_full"]:
try:
reverse_sender.append(float(entry["sender_bitrate"]))
reverse_receiver.append(float(entry["receiver_bitrate"]))
reverse_distances.append(entry["start_distance"])
reverse_distances.append(int(float(entry["start_distance"])))
except:
message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
reverse_sender.append(float(bitrates[-2]))
reverse_receiver.append(float(bitrates[-1]))
reverse_distances.append(entry["start_distance"])
reverse_distances.append(int(float(entry["start_distance"])))
else:
try:
sender.append(float(entry["sender_bitrate"]))
receiver.append(float(entry["receiver_bitrate"]))
distances.append(entry["start_distance"])
distances.append(int(float(entry["start_distance"])))
except:
message = entry["iperf_full"]
bitrates = re.findall(r"(\d+\.\d+) Mbits/sec", message)
sender.append(float(bitrates[-2]))
receiver.append(float(bitrates[-1]))
distances.append(entry["start_distance"])
distances.append(int(float(entry["start_distance"])))
# Plot the data
plt.figure(figsize=(10, 6))
plt.plot(distances, sender, label="Avg Uplink Sender Bitrate", marker="o", color="red")
plt.plot(
distances, sender, label="Avg Uplink Sender Bitrate", marker="o", color="red"
)
plt.plot(
distances,
receiver,
@ -304,8 +315,26 @@ def plot_double_iperf(filename):
if __name__ == "__main__":
filename = '/home/madrigal/repos/range-testing/data/boat_relay_sept_17/test_1758127491_copy.json'
filename = "/home/madrigal/repos/range-testing/data/boat_relay_sept_18/test_1758215714_copy.json"
# plot_double_iperf(filename=filename)
plot_rsrp(filename=filename)
plot_rsrq(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_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)