Commit a541379b authored by Larkin Heintzman's avatar Larkin Heintzman

ping packet loss updates

parent ed54eafd
#!/bin/bash
endpoints="192.168.111.200"
filename="/home/llh/pingStats/pingStats.json"
downtime=1
gpstopic="/rossettiModem/dji_sdk/gps_position"
echo "pinging: $endpoints"
echo "save to: $filename"
echo "gps topic: $gpstopic"
echo " "
# enable ros commands
source /opt/ros/noetic/setup.bash
source /home/larkin/catkin_ws/devel/setup.bash
ROS_IP=192.168.111.202
ROS_MASTER_URI=http://192.168.111.200:11311
echo ping "${endpoints} every ${downtime:=1} sec, saving to ${filename}"
# for endpoints in "${endpoints[@]}"; do
# done
while true; do
rawData=$(ping -c 3 -q -w 3 ${endpoints:=localhost})
newPacketData=$(echo "$rawData" | grep -oP '\d+(?=% packet loss)')
newLatencyData=$(echo "$rawData" | tail -n 1)
OLDIFS=$IFS
IFS=" "
read bit1 bit2 bit3 bit4 bit5 <<< "$newLatencyData"
IFS="/"
read num1 num2 num3 num4 <<< "$bit4"
IFS=$OLDIFS
echo "------------------"
if [[ -z $num4 ]]; then
# no network data, or all packets lost
num1="0"
num2="0"
num3="0"
num4="0"
fi
# debugging help
# echo "------------------"
# echo $num1
# echo $num2
# echo $num3
# echo $num4
# echo "------------------"
# echo "$rawData"
# echo "------------------"
# echo "$newPacketData"
# echo "------------------"
# echo "$newLatencyData"
# exit
if test -f "$filename"; then
false
else
touch "$filename"
echo "{}" > "$filename"
fi
# get gps data if present (timeout 5s)
gpsData=$(timeout 5 rostopic echo -n 1 $gpstopic | grep "latitude:\|longitude:\|altitude:")
gpsData=$(echo $gpsData | tr '\n' ' ')
OLDIFS=$IFS
IFS=" "
read trash1 latitude trash2 longitude trash3 altitude <<< "$gpsData"
IFS=$OLDIFS
# ping can return standard deviation and gps data may not be available
if [[ -z "$latitude" ]]; then
# echo "gps data is not there"
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson packetLoss $newPacketData --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev,"timedate":$timedate,"packetLoss":$packetLoss}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
else
echo "gps data IS there"
echo $latitude
echo $longitude
echo $altitude
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson altitude $altitude --argjson longitude $longitude --argjson latitude $latitude --argjson packetLoss $newPacketData --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target] += [{"lat":$latitude,"long":$longitude,"alt":$altitude,"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev,"timedate":$timedate,"packetLoss":$packetLoss}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
fi
sleep ${downtime:=1}
done
if test -f "$filename.tmp"; then
rm "$filename.tmp"
fi
#!/bin/bash
docker run --env endpoints=192.168.111.200 --env filename=/tmp/pingStats/pingStatsDocker.json --env gpstopic=/rossettiModem/dji_sdk/gps_position --env downtime=1 --env ROS_IP=192.168.111.202 --env ROS_MASTER_URI=http://192.168.111.200:11311 -v /home/larkin/pingStats:/tmp/pingStats/ doorbell:latest /ping.sh
......@@ -21,32 +21,45 @@ fi
# enable ros commands
source /ros_entrypoint.sh
echo ping "${endpoints} every ${downtime:=3} sec, saving to ${filename}"
echo ping "${endpoints} every ${downtime:=1} sec, saving to ${filename}"
# for endpoints in "${endpoints[@]}"; do
# done
while true; do
# for endpoints in "${endpoints[@]}"; do
# echo pinging "${endpoints} now ..."
newData=$(ping -c 3 ${endpoints:=localhost} | tail -n 1)
# if nothing comes back, we dont write anything
if [[ -n "$newData" ]]; then
false
echo "$newData"
else
echo "${endpoints} might be unreachable"
continue
fi
rawData=$(ping -c 3 -q -w 3 ${endpoints:=localhost})
newPacketData=$(echo "$rawData" | grep -oP '\d+(?=% packet loss)')
newLatencyData=$(echo "$rawData" | tail -n 1)
OLDIFS=$IFS
IFS=" "
read bit1 bit2 bit3 bit4 bit5 <<< "$newData"
read bit1 bit2 bit3 bit4 bit5 <<< "$newLatencyData"
IFS="/"
read num1 num2 num3 num4 <<< "$bit4"
IFS=$OLDIFS
echo "------------------"
if [[ -z $num4 ]]; then
# no network data, or all packets lost
num1="0"
num2="0"
num3="0"
num4="0"
fi
# debugging help
# echo "------------------"
# echo $num1
# echo $num2
# echo $num3
# echo $num4
# echo "------------------"
# echo "$rawData"
# echo "------------------"
# echo "$newPacketData"
# echo "------------------"
# echo "$newLatencyData"
# exit
if test -f "$filename"; then
false
else
......@@ -62,37 +75,20 @@ while true; do
read trash1 latitude trash2 longitude trash3 altitude <<< "$gpsData"
IFS=$OLDIFS
echo $latitude
echo $longitude
echo $altitude
echo "------------------"
# ping can return standard deviation and gps data may not be available
if [[ -z "$latitude" ]]; then
# echo "gps data is not there"
if [[ -n "$num4" ]]; then
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
else
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 '.[$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
fi
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson packetLoss $newPacketData --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev,"timedate":$timedate,"packetLoss":$packetLoss}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
else
echo "gps data IS there"
echo $latitude
echo $longitude
echo $altitude
if [[ -n "$num4" ]]; then
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson altitude $altitude --argjson longitude $longitude --argjson latitude $latitude --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target][$timedate] += [{"lat":$latitude,"long":$longitude,"alt":$altitude,"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
else
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson altitude $altitude --argjson longitude $longitude --argjson latitude $latitude --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 '.[$target][$timedate] += [{"lat":$latitude,"long":$longitude,"alt":$altitude,"min":$rttMin,"avg":$rttAvg,"max":$rttMax}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
fi
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson altitude $altitude --argjson longitude $longitude --argjson latitude $latitude --argjson packetLoss $newPacketData --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target] += [{"lat":$latitude,"long":$longitude,"alt":$altitude,"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev,"timedate":$timedate,"packetLoss":$packetLoss}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
fi
sleep ${downtime:=3}
sleep ${downtime:=1}
done
if test -f "$filename.tmp"; then
rm "$filename.tmp"
fi
# if test -f "$nfsFilename.tmp"; then
# rm "$nfsFilename.tmp"
# fi
......@@ -24,8 +24,17 @@ def inflateBounds(bbox=[38.865,-77.072,38.876,-77.001], amt=0.001):
return [bbox[0]-amt, bbox[1]-amt, bbox[2]+amt, bbox[3]+amt]
font = {'family' : 'DejaVu Sans',
'weight' : 'normal',
'size' : 8}
matplotlib.rc('font', **font)
filenames = ["/home/llh/ros-kubernetes/plottingTools/pingStats_may_29th_2022/pingStats.json",
"/home/llh/ros-kubernetes/plottingTools/pingStats_may_29th_2022/pingStatsDocker.json"]
# filenames = ["/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStats.json",
# "/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStatsDocker.json",
# "/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStatsKubernetes.json"]
plotColors = ["orange","slateblue","mediumspringgreen"]
lats = []
longs = []
avgLatencies = []
......@@ -71,16 +80,8 @@ ax.xaxis.set_major_formatter(FormatStrFormatter('%.2f'))
mapPlot = plt.imread('mapImg.jpeg')
for i in range(len(lats)):
# get latency coloring
if i == 0:
latencyColor = [((maxAvgLatency-val*0.7)/maxAvgLatency,0.0,0.0) for val in avgLatencies[i]]
if i == 1:
latencyColor = [(0.0,(maxAvgLatency-val*0.7)/maxAvgLatency,0.0) for val in avgLatencies[i]]
else:
latencyColor = [(0.0,0.0,(maxAvgLatency-val*0.7)/maxAvgLatency) for val in avgLatencies[i]]
latencySize = [20*(siz/maxAvgLatency) + 5 for siz in avgLatencies[i]]
plt.scatter(longs[i], lats[i], zorder=1, alpha=1, c=latencyColor, s=latencySize, label=[f.split('/') for f in filenames][i][-1])
latencySize = [50*(siz/maxAvgLatency) + 5 for siz in avgLatencies[i]]
plt.scatter(longs[i], lats[i], zorder=1, alpha=0.8, c=plotColors[i], s=latencySize, label=[f.split('/') for f in filenames][i][-1])
plt.imshow(mapPlot, zorder=0, extent=[bigBox[1], bigBox[3], bigBox[0], bigBox[2]], aspect='equal')
plt.title('Network latency visualized')
......
{
"192.168.111.200": {
"17:19_2022-05-25": [
{
"min": 13.61,
"avg": 47.29,
"max": 65.992,
"std": 23.864
},
{
"min": 14.095,
"avg": 18.46,
"max": 26.597,
"std": 5.758
},
{
"min": 14.263,
"avg": 16.891,
"max": 22.078,
"std": 3.667
},
{
"min": 14.522,
"avg": 14.7,
"max": 14.983,
"std": 0.202
},
{
"min": 14.492,
"avg": 16.341,
"max": 19.84,
"std": 2.475
},
{
"min": 13.269,
"avg": 13.79,
"max": 14.406,
"std": 0.468
},
{
"min": 13.988,
"avg": 14.704,
"max": 15.567,
"std": 0.652
}
],
"17:20_2022-05-25": [
{
"min": 14.56,
"avg": 17.736,
"max": 24.085,
"std": 4.489
},
{
"min": 14.192,
"avg": 32.577,
"max": 68.605,
"std": 25.476
},
{
"min": 14.268,
"avg": 31.412,
"max": 63.884,
"std": 22.972
},
{
"min": 15.617,
"avg": 15.786,
"max": 15.878,
"std": 0.12
},
{
"min": 13.992,
"avg": 14.747,
"max": 15.73,
"std": 0.727
},
{
"min": 14.6,
"avg": 14.923,
"max": 15.348,
"std": 0.313
},
{
"min": 14.853,
"avg": 14.871,
"max": 14.899,
"std": 0.019
}
],
"17:53_2022-05-25": [
{
"lat": 37.196939979340556,
"long": -80.5783337433134,
"alt": 100,
"min": 14.835,
"avg": 14.92,
"max": 15.083,
"std": 0.114
},
{
"lat": 37.196939979340556,
"long": -80.5783337433134,
"alt": 100,
"min": 13.982,
"avg": 14.471,
"max": 14.933,
"std": 0.388
}
],
"17:54_2022-05-25": [
{
"lat": 37.196939979340556,
"long": -80.5783337433134,
"alt": 100,
"min": 14.271,
"avg": 14.657,
"max": 14.92,
"std": 0.279
},
{
"lat": 37.196939979340556,
"long": -80.5783337433134,
"alt": 100,
"min": 14.565,
"avg": 14.811,
"max": 15.131,
"std": 0.236
},
{
"lat": 37.196939979340556,
"long": -80.5783337433134,
"alt": 100,
"min": 14.533,
"avg": 58.677,
"max": 146.526,
"std": 62.118
},
{
"min": 13.851,
"avg": 16.983,
"max": 23.149,
"std": 4.359
},
{
"min": 14.396,
"avg": 96.282,
"max": 252.182,
"std": 110.284
},
{
"min": 14.044,
"avg": 14.499,
"max": 15.34,
"std": 0.595
}
],
"17:55_2022-05-25": [
{
"min": 14.349,
"avg": 14.473,
"max": 14.69,
"std": 0.153
}
],
"10:53_2022-05-29": [
{
"min": 14.014,
"avg": 15.557,
"max": 17.397,
"std": 1.396
}
],
"10:55_2022-05-29": [
{
"min": 12.545,
"avg": 16.675,
"max": 20.36,
"std": 3.206
},
{
"min": 13.681,
"avg": 16.985,
"max": 23.185,
"std": 4.387
}
],
"10:56_2022-05-29": [
{
"min": 14.285,
"avg": 28.395,
"max": 54.467,
"std": 18.456
},
{
"min": 13.459,
"avg": 14.014,
"max": 14.303,
"std": 0.392
}
],
"10:57_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 14.482,
"avg": 26.972,
"max": 39.171,
"std": 10.081
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 15.134,
"avg": 17.034,
"max": 20.588,
"std": 2.514
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.662,
"avg": 13.72,
"max": 13.821,
"std": 0.071
}
],
"00:08_2022-01-10": [
{
"lat": 37.196903649550386,
"long": -80.57842676351463,
"alt": 452.704345703125,
"min": 13.924,
"avg": 20.884,
"max": 29.807,
"std": 6.63
},
{
"lat": 37.19690354330419,
"long": -80.57842880829693,
"alt": 452.6966857910156,
"min": 15.322,
"avg": 19.689,
"max": 23.059,
"std": 3.236
},
{
"lat": 37.19690285992929,
"long": -80.5784279312738,
"alt": 452.7027587890625,
"min": 13.847,
"avg": 14.494,
"max": 15.314,
"std": 0.611
},
{
"lat": 37.19692744324189,
"long": -80.57839505337084,
"alt": 452.8310852050781,
"min": 14.106,
"avg": 23.007,
"max": 34.252,
"std": 8.389
}
],
"00:09_2022-01-10": [
{
"lat": 37.196928638760795,
"long": -80.5783967615331,
"alt": 452.83001708984375,
"min": 14.277,
"avg": 14.948,
"max": 15.332,
"std": 0.476
},
{
"lat": 37.19692906786556,
"long": -80.5783988930217,
"alt": 452.832763671875,
"min": 14.465,
"avg": 17.519,
"max": 23.35,
"std": 4.124
},
{
"lat": 37.19692955794904,
"long": -80.578399626419,
"alt": 452.8398132324219,
"min": 13.922,
"avg": 18.29,
"max": 22.659,
"std": 4.368
},
{
"lat": 37.19693034994929,
"long": -80.57839790479248,
"alt": 452.81781005859375,
"min": 13.967,
"avg": 14.824,
"max": 15.374,
"std": 0.614
},
{
"lat": 37.196931061419725,
"long": -80.57839602305584,
"alt": 452.8205261230469,
"min": 13.824,
"avg": 14.352,
"max": 14.978,
"std": 0.476
}
],
"00:10_2022-01-10": [
{
"lat": 37.19693184103729,
"long": -80.57839521905511,
"alt": 452.8119201660156,
"min": 12.532,
"avg": 13.068,
"max": 13.769,
"std": 0.518
},
{
"lat": 37.19693157080352,
"long": -80.57839447158058,
"alt": 452.78143310546875,
"min": 14.652,
"avg": 15.316,
"max": 15.741,
"std": 0.475
},
{
"lat": 37.19693132840638,
"long": -80.57839495833116,
"alt": 452.8045654296875,
"min": 13.514,
"avg": 14.356,
"max": 14.982,
"std": 0.618
},
{
"lat": 37.19693145391381,
"long": -80.57839351852824,
"alt": 452.77899169921875,
"min": 14.68,
"avg": 20.155,
"max": 23.998,
"std": 3.975
},
{
"lat": 37.196930854688766,
"long": -80.5783929741205,
"alt": 452.7967529296875,
"min": 14.421,
"avg": 16.252,
"max": 18.584,
"std": 1.735
},
{
"lat": 37.19693044973708,
"long": -80.57839193587594,
"alt": 452.78680419921875,
"min": 14.432,
"avg": 14.991,
"max": 15.55,
"std": 0.559
}
],
"00:11_2022-01-10": [
{
"lat": 37.19693100104679,
"long": -80.5783905777553,
"alt": 452.80780029296875,
"min": 14.353,
"avg": 15.102,
"max": 15.942,
"std": 0.651
},
{
"lat": 37.19699790683763,
"long": -80.57830637877835,
"alt": 469.3252868652344,
"min": 14.99,
"avg": 17.011,
"max": 20.837,
"std": 2.706
},
{
"lat": 37.19698941525778,
"long": -80.57829973783991,
"alt": 469.2551574707031,
"min": 14.436,
"avg": 17.209,
"max": 22.554,
"std": 3.78
},
{
"lat": 37.19705687346568,
"long": -80.57837773956425,
"alt": 471.8620910644531,
"min": 13.388,
"avg": 16.115,
"max": 21.471,
"std": 3.787
},
{
"lat": 37.197230225302555,
"long": -80.57814398954477,
"alt": 473.3555603027344,
"min": 13.702,
"avg": 13.835,
"max": 14.059,
"std": 0.158
},
{
"lat": 37.197486845669076,
"long": -80.57780834647683,
"alt": 474.8621826171875,
"min": 14.017,
"avg": 15.994,
"max": 19.339,
"std": 2.378
}
],
"00:12_2022-01-10": [
{
"lat": 37.197350816140165,
"long": -80.5779784926944,
"alt": 474.99468994140625,
"min": 15.642,
"avg": 17.829,
"max": 20.016,
"std": 2.187
},
{
"lat": 37.197306145915086,
"long": -80.57793717946808,
"alt": 479.6341857910156,
"min": 13.341,
"avg": 16.814,
"max": 22.401,
"std": 3.989
},
{
"lat": 37.19709258326234,
"long": -80.57770355121815,
"alt": 480.7821960449219,
"min": 13.609,
"avg": 13.843,
"max": 14.061,
"std": 0.184
},
{
"lat": 37.19700224049839,
"long": -80.57762343256924,
"alt": 484.26629638671875,
"min": 14.415,
"avg": 17.684,
"max": 24.139,
"std": 4.564
},
{
"lat": 37.19731554492907,
"long": -80.57737766866396,
"alt": 486.0531921386719,
"min": 14.09,
"avg": 14.72,
"max": 15.35,
"std": 0.63
}
],
"00:13_2022-01-10": [
{
"lat": 37.19759253621806,
"long": -80.57702315996397,
"alt": 486.17474365234375,
"min": 14.302,
"avg": 17.595,
"max": 23.654,
"std": 4.289
},
{
"lat": 37.19783534451343,
"long": -80.57727874929449,
"alt": 486.23736572265625,
"min": 12.786,
"avg": 16.77,
"max": 24.13,
"std": 5.209
},
{
"lat": 37.19781975595318,
"long": -80.57763534892784,
"alt": 485.5032958984375,
"min": 14.743,
"avg": 45.44,
"max": 92.3,
"std": 33.661
},
{
"lat": 37.19764575819725,
"long": -80.5781387130008,
"alt": 485.88983154296875,
"min": 14.711,
"avg": 15.11,
"max": 15.731,
"std": 0.445
},
{
"lat": 37.19791311191174,
"long": -80.57853587456033,
"alt": 486.7338562011719,
"min": 13.206,
"avg": 24.406,
"max": 35.607,
"std": 11.2
}
],
"00:14_2022-01-10": [
{
"lat": 37.19787902276859,
"long": -80.578119392429,
"alt": 487.0986328125,
"min": 14.137,
"avg": 14.665,
"max": 15.36,
"std": 0.513
},
{
"lat": 37.19808711133519,
"long": -80.57763973340104,
"alt": 487.2243347167969,
"min": 15.192,
"avg": 17.454,
"max": 21.123,
"std": 2.617
},
{
"lat": 37.19808706829216,
"long": -80.57757682765724,
"alt": 487.2271423339844,
"min": 15.091,
"avg": 15.362,
"max": 15.688,
"std": 0.246
},
{
"lat": 37.19804897239513,
"long": -80.57758971884984,
"alt": 487.35302734375,
"min": 13.519,
"avg": 16.705,
"max": 21.566,
"std": 3.492
},
{
"lat": 37.197623628920034,
"long": -80.57767629612897,
"alt": 487.1825256347656,
"min": 13.883,
"avg": 21.101,
"max": 28.32,
"std": 7.218
}
],
"00:15_2022-01-10": [
{
"lat": 37.19712503951909,
"long": -80.57742193443889,
"alt": 487.24993896484375,
"min": 14.036,
"avg": 14.803,
"max": 15.693,
"std": 0.682
},
{
"lat": 37.1971201998617,
"long": -80.57708950666277,
"alt": 487.1660461425781,
"min": 15.119,
"avg": 20.624,
"max": 27.698,
"std": 5.253
},
{
"lat": 37.19751203647312,
"long": -80.57728095499519,
"alt": 487.2936096191406,
"min": 13.767,
"avg": 14.247,
"max": 15.047,
"std": 0.569
},
{
"lat": 37.19786081650415,
"long": -80.5770232599337,
"alt": 487.2278747558594,
"min": 14.15,
"avg": 16.544,
"max": 20.723,
"std": 2.965
},
{
"lat": 37.19769218547432,
"long": -80.57670481398392,
"alt": 487.2012634277344,
"min": 40.799,
"avg": 40.799,
"max": 40.799,
"std": 0
},
{
"lat": 37.19738313754873,
"long": -80.57694762258755,
"alt": 487.2094421386719,
"min": 12.922,
"avg": 13.203,
"max": 13.54,
"std": 0.255
}
],
"00:16_2022-01-10": [
{
"lat": 37.197057658701375,
"long": -80.57762427138591,
"alt": 487.16448974609375,
"min": 12.61,
"avg": 28.716,
"max": 58.218,
"std": 20.89
},
{
"lat": 37.19678146369544,
"long": -80.57801308157919,
"alt": 487.1002197265625,
"min": 13.948,
"avg": 14.746,
"max": 15.898,
"std": 0.834
},
{
"lat": 37.196616182817834,
"long": -80.57828673318123,
"alt": 487.419677734375,
"min": 14.149,
"avg": 19.173,
"max": 27.08,
"std": 5.658
},
{
"lat": 37.19666667013148,
"long": -80.57834412050074,
"alt": 487.3398742675781,
"min": 14.028,
"avg": 15.066,
"max": 15.795,
"std": 0.754
},
{
"lat": 37.19683130562415,
"long": -80.5785382619616,
"alt": 487.2439880371094,
"min": 14.893,
"avg": 32.31,
"max": 66.815,
"std": 24.398
},
{
"lat": 37.19681008770236,
"long": -80.57852103890465,
"alt": 487.4251403808594,
"min": 14.741,
"avg": 17.391,
"max": 22.284,
"std": 3.463
}
],
"00:17_2022-01-10": [
{
"lat": 37.196860868279224,
"long": -80.57856820817896,
"alt": 487.7696533203125,
"min": 22.328,
"avg": 22.328,
"max": 22.328,
"std": 0
}
],
"16:58_2022-06-03": [
{
"lat": 37.19700887077722,
......
{
"192.168.111.200": {
"15:09_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.318,
"avg": 13.471,
"max": 13.609,
"std": 0.119
}
],
"15:10_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.657,
"avg": 17.744,
"max": 24.858,
"std": 5.048
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.605,
"avg": 17.848,
"max": 25.55,
"std": 5.455
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 12.431,
"avg": 21.991,
"max": 31.337,
"std": 7.719
}
],
"15:11_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.934,
"avg": 20.05,
"max": 31.881,
"std": 8.367
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.886,
"avg": 14.735,
"max": 15.6,
"std": 0.699
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.593,
"avg": 14.113,
"max": 14.954,
"std": 0.6
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.914,
"avg": 17.259,
"max": 23.152,
"std": 4.179
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.206,
"avg": 13.527,
"max": 13.84,
"std": 0.258
}
],
"15:12_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.457,
"avg": 17.872,
"max": 25.477,
"std": 5.4
}
],
"05:23_2022-01-10": [
{
"lat": 37.19703455310033,
"long": -80.57814568498682,
"alt": 453.06365966796875,
"min": 12.727,
"avg": 14.155,
"max": 15.089,
"std": 1.025
},
{
"lat": 37.197036689215,
"long": -80.57814645267614,
"alt": 453.0914611816406,
"min": 12.997,
"avg": 22.964,
"max": 33.591,
"std": 8.42
},
{
"lat": 37.19703877931635,
"long": -80.57814934429226,
"alt": 453.12225341796875,
"min": 12.704,
"avg": 14.437,
"max": 17.093,
"std": 1.906
},
{
"lat": 37.196961096688334,
"long": -80.57837534935616,
"alt": 454.3573303222656,
"min": 15.034,
"avg": 17.341,
"max": 20.452,
"std": 2.283
}
],
"05:24_2022-01-10": [
{
"lat": 37.196958347425415,
"long": -80.57837539671705,
"alt": 452.5787353515625,
"min": 14.885,
"avg": 15.306,
"max": 15.65,
"std": 0.317
},
{
"lat": 37.19695475089611,
"long": -80.57837558433236,
"alt": 452.5632019042969,
"min": 14.739,
"avg": 31.79,
"max": 48.842,
"std": 17.051
},
{
"lat": 37.19694877286517,
"long": -80.57837578650063,
"alt": 452.568603515625,
"min": 13.661,
"avg": 20.475,
"max": 27.289,
"std": 6.814
},
{
"lat": 37.19694763413663,
"long": -80.5783751699529,
"alt": 452.568603515625,
"min": 14.825,
"avg": 23.361,
"max": 28.649,
"std": 6.093
},
{
"lat": 37.196947017324376,
"long": -80.57837445538193,
"alt": 452.57342529296875,
"min": 14.074,
"avg": 16.824,
"max": 21.021,
"std": 3.015
},
{
"lat": 37.19694568152154,
"long": -80.57837429132067,
"alt": 452.6016540527344,
"min": 13.19,
"avg": 20.858,
"max": 32.065,
"std": 8.101
}
],
"05:25_2022-01-10": [
{
"lat": 37.196945574878,
"long": -80.57837516086572,
"alt": 452.6947326660156,
"min": 13.933,
"avg": 21.16,
"max": 34.872,
"std": 9.7
},
{
"lat": 37.196947766604026,
"long": -80.578376833735,
"alt": 452.7162780761719,
"min": 14.302,
"avg": 14.978,
"max": 15.987,
"std": 0.726
},
{
"lat": 37.196950075330506,
"long": -80.57837467988637,
"alt": 452.7153625488281,
"min": 14.399,
"avg": 21.925,
"max": 29.452,
"std": 7.526
},
{
"lat": 37.19695215108527,
"long": -80.57837503129947,
"alt": 452.72283935546875,
"min": 14.465,
"avg": 15.099,
"max": 15.518,
"std": 0.455
},
{
"lat": 37.19695281414207,
"long": -80.57837566722198,
"alt": 452.716796875,
"min": 14.233,
"avg": 22.284,
"max": 31.544,
"std": 7.118
}
],
"05:26_2022-01-10": [
{
"lat": 37.196954363482774,
"long": -80.57837490135145,
"alt": 452.7495422363281,
"min": 13.123,
"avg": 14.317,
"max": 15.402,
"std": 0.933
},
{
"lat": 37.19705516345618,
"long": -80.57807292349135,
"alt": 495.4686584472656,
"min": 14.839,
"avg": 15.287,
"max": 15.996,
"std": 0.507
},
{
"lat": 37.19705778031357,
"long": -80.57807198836132,
"alt": 496.10546875,
"min": 14.256,
"avg": 15.096,
"max": 16.117,
"std": 0.77
},
{
"lat": 37.19779795981652,
"long": -80.57798985504684,
"alt": 497.03271484375,
"min": 13.519,
"avg": 32.645,
"max": 59.701,
"std": 19.669
},
{
"lat": 37.19710323280406,
"long": -80.57735325238846,
"alt": 496.07952880859375,
"min": 14.917,
"avg": 15.091,
"max": 15.265,
"std": 0.174
},
{
"lat": 37.19724335272374,
"long": -80.577034457663,
"alt": 496.5080261230469,
"min": 14.529,
"avg": 14.953,
"max": 15.498,
"std": 0.404
}
],
"05:27_2022-01-10": [
{
"lat": 37.1975313778021,
"long": -80.57702838480242,
"alt": 496.5955810546875,
"min": 14.721,
"avg": 15.207,
"max": 15.677,
"std": 0.39
},
{
"lat": 37.19787404780704,
"long": -80.57680489229688,
"alt": 496.57049560546875,
"min": 15.639,
"avg": 21.565,
"max": 26.648,
"std": 4.533
},
{
"lat": 37.19804232063131,
"long": -80.57669643252781,
"alt": 496.6546630859375,
"min": 13.852,
"avg": 14.43,
"max": 15.37,
"std": 0.67
},
{
"lat": 37.19772697904325,
"long": -80.5770454442686,
"alt": 496.8408203125,
"min": 12.592,
"avg": 13.209,
"max": 13.826,
"std": 0.617
},
{
"lat": 37.197320775803846,
"long": -80.57764520541079,
"alt": 484.6840515136719,
"min": 15.311,
"avg": 18.126,
"max": 20.942,
"std": 2.815
},
{
"lat": 37.19697810863891,
"long": -80.57831185561668,
"alt": 452.6222229003906,
"min": 16.089,
"avg": 33.024,
"max": 49.96,
"std": 16.935
}
],
"05:28_2022-01-10": [
{
"lat": 37.196979074384366,
"long": -80.57830769844665,
"alt": 451.330078125,
"min": 13.864,
"avg": 17.702,
"max": 21.54,
"std": 3.838
},
{
"lat": 37.196976985950535,
"long": -80.57830557177756,
"alt": 451.3295593261719,
"min": 13.009,
"avg": 16.344,
"max": 21.833,
"std": 3.91
},
{
"lat": 37.196975308522944,
"long": -80.57830415577975,
"alt": 451.3286437988281,
"min": 14.521,
"avg": 17.74,
"max": 24.035,
"std": 4.451
},
{
"lat": 37.19697392936116,
"long": -80.57830460670286,
"alt": 451.36322021484375,
"min": 14.28,
"avg": 14.856,
"max": 15.747,
"std": 0.638
},
{
"lat": 37.19697282650723,
"long": -80.57830317042826,
"alt": 451.3707275390625,
"min": 15.08,
"avg": 15.537,
"max": 16.164,
"std": 0.458
}
],
"05:29_2022-01-10": [
{
"lat": 37.19697340995266,
"long": -80.57830267877954,
"alt": 451.375244140625,
"min": 14.455,
"avg": 16.149,
"max": 17.631,
"std": 1.305
},
{
"lat": 37.196974324167634,
"long": -80.5783022709802,
"alt": 451.36737060546875,
"min": 15.24,
"avg": 18.919,
"max": 25.997,
"std": 5.006
},
{
"lat": 37.196975020125514,
"long": -80.57830335829631,
"alt": 451.41864013671875,
"min": 12.96,
"avg": 14.009,
"max": 14.98,
"std": 0.826
},
{
"lat": 37.19697379239599,
"long": -80.57830354899805,
"alt": 451.42034912109375,
"min": 14.571,
"avg": 15.491,
"max": 16.261,
"std": 0.698
},
{
"lat": 37.19697497482871,
"long": -80.57830373798453,
"alt": 451.42083740234375,
"min": 14.511,
"avg": 14.808,
"max": 15.148,
"std": 0.261
},
{
"lat": 37.196975482010856,
"long": -80.5783041758092,
"alt": 451.412841796875,
"min": 14.751,
"avg": 14.833,
"max": 14.88,
"std": 0.058
}
],
"05:30_2022-01-10": [
{
"lat": 37.19697425178656,
"long": -80.5783028373804,
"alt": 451.4086608886719,
"min": 15.143,
"avg": 36.555,
"max": 64.276,
"std": 20.548
},
{
"lat": 37.19697439192393,
"long": -80.5783021073303,
"alt": 451.4195861816406,
"min": 18.344,
"avg": 30.016,
"max": 44.63,
"std": 10.93
},
{
"lat": 37.19697381759779,
"long": -80.57830181409399,
"alt": 451.4179992675781,
"min": 13.693,
"avg": 17.304,
"max": 23.811,
"std": 4.61
},
{
"lat": 37.19697462049233,
"long": -80.57830301008524,
"alt": 451.43072509765625,
"min": 16.823,
"avg": 44.05,
"max": 62.353,
"std": 19.629
}
],
"20:48_2022-06-03": [
{
"lat": 37.197028976602034,
......
{
"192.168.111.200": {
"15:17_2022-05-29": [
{
"min": 14.019,
"avg": 25.007,
"max": 46.818,
"std": 15.422
},
{
"min": 14.195,
"avg": 18.927,
"max": 27.236,
"std": 5.894
},
{
"min": 12.568,
"avg": 13.834,
"max": 14.585,
"std": 0.9
}
],
"15:18_2022-05-29": [
{
"min": 13.465,
"avg": 124.664,
"max": 218.968,
"std": 84.742
},
{
"min": 13.566,
"avg": 13.816,
"max": 14.133,
"std": 0.236
},
{
"min": 13.581,
"avg": 13.776,
"max": 14.167,
"std": 0.276
}
],
"15:19_2022-05-29": [
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 15.273,
"avg": 125.15,
"max": 235.027,
"std": 109.877
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.945,
"avg": 14.194,
"max": 14.352,
"std": 0.178
},
{
"lat": 37.19727999999999,
"long": -80.577791,
"alt": 100.0999984741211,
"min": 13.549,
"avg": 17.37,
"max": 24.161,
"std": 4.814
}
],
"14:11_2022-06-03": [
{
"min": 14.017,
......
# api key from gurgle AIzaSyDDFrIPAMv3HS6PXTDcWfiUys8si_-yZ-c
import numpy as np
from gmplot import GoogleMapPlotter
from random import random
import json
from pprint import PrettyPrinter
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.ticker import FormatStrFormatter
import shutil
import requests
from geopy import distance
def getMapImage(bbox=[38.865,-77.072,38.876,-77.001], apiKey="GKvj5HV6DLjqJT8awam4KQL3d26GP1M1", mapType="sat", mapSize=[600,400]):
req = "https://www.mapquestapi.com/staticmap/v5/map?key={}&boundingBox={}&type={}&size={}".format(apiKey,','.join(map(str,bbox)),mapType,','.join(map(str,mapSize)))
response = requests.get(req, stream=True)
with open('mapImg.jpeg', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
def inflateBounds(bbox=[38.865,-77.072,38.876,-77.001], amt=0.001):
return [bbox[0]-amt, bbox[1]-amt, bbox[2]+amt, bbox[3]+amt]
def calculateDistance(pt1, pt2):
# 2D geodesic distance in meters
distance_2d = distance.distance(pt1[:2], pt2[:2]).m
# 3D euclidean distance
distance_3d = np.sqrt(distance_2d**2 + (pt2[2] - pt1[2])**2)
return distance_3d
def rejectOutliers(data, m = 2.):
d = np.abs(data - np.median(data))
mdev = np.median(d)
s = d/mdev if mdev else 0.
# return data[s<m]
return s<m
filenames = ["/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStats.json",
"/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStatsDocker.json",
"/home/llh/ros-kubernetes/plottingTools/pingStats_june_3rd_2022/pingStatsKubernetes.json"]
# filenames = ["/home/llh/ros-kubernetes/plottingTools/pingStats_may_29th_2022/pingStats.json",
# "/home/llh/ros-kubernetes/plottingTools/pingStats_may_29th_2022/pingStatsDocker.json"]
# "/home/llh/ros-kubernetes/plottingTools/pingStats_may_29th_2022/pingStatsKubernetes.json"]
plotColors = ["orange","slateblue","mediumspringgreen"]
# reference point of the base station
anchorPoint = [37.196927, -80.578399, 452.7027587890625]
# potentially the least python-ish way to handle this
for (i, fn) in enumerate(filenames):
with open(fn) as file:
data = json.load(file)
# need to iterate over endpoints as well
endpoint = "192.168.111.200"
# ignore time stamps for now
timelessData = []
for minuteData in data[endpoint].values():
for pt in minuteData:
if ("lat" in pt):
timelessData.append(pt)
dists = np.array([calculateDistance([dataPoint["lat"], dataPoint["long"], dataPoint["alt"]],anchorPoint) for dataPoint in timelessData])
avgLatencies = np.array([dataPoint["avg"] for dataPoint in timelessData])
maskArray = rejectOutliers(avgLatencies, m=2.0)
filteredLatencies = avgLatencies[maskArray]
filteredDistances = dists[maskArray]
print("removed {outliers} outliers from the dataset".format(outliers=np.size(maskArray) - np.count_nonzero(maskArray)))
# calculate best fit line
func = np.poly1d(np.polyfit(filteredDistances, filteredLatencies, 1))
evenDists = np.linspace(np.min(filteredDistances),np.max(filteredDistances),10)
plt.scatter(filteredDistances, filteredLatencies, s=12, c=plotColors[i], label=[f.split('/') for f in filenames][i][-1])
plt.plot(evenDists, func(evenDists), c=plotColors[i], linewidth=1.5)
plt.ticklabel_format(style='plain') # to prevent scientific notation
plt.ticklabel_format(useOffset=False)
plt.title('Network Latency vs Distance')
plt.xlabel("Distance")
plt.ylabel("Latency")
plt.legend()
# plt.show()
plt.savefig("scatterPlot.jpeg", dpi=400)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment