Make a tool to understand how regularly the tracker sent data
#!/usr/bin/python3
# The x-axis uses sent times.
# If there is an horizontal hole it means that no packet for the given sent time was received.
# The bottom line represents whether or not the geolocation was successful.
# The line just above the bottom one represents tracker IP using colors to distinguish multiple IPs.
# Above are the latencies, that are the received times minus the sent times, in seconds.
import matplotlib.pyplot as plt, matplotlib.dates as mdates, datetime
import utils
from random import randint
with open('readible.txt') as f:
lines = f.read().splitlines()
linesLen = len(lines)
ipAddressesSentTimes = {}
latencies = []
sentTimes = []
retrievingLocationResultsSentTimes = {
True: [],
False: []
}
for linesIndex in range(0, linesLen):
line = lines[linesIndex]
lineParts = line.split()
sentTime = ' '.join(lineParts[4:6])
sentTimeSeconds = utils.getTimeFromStr(sentTime)
if sentTimeSeconds >= utils.BEGIN_TIME:
sentDateTime = datetime.datetime.fromtimestamp(sentTimeSeconds)
receivedTime = ' '.join(lineParts[:2])
latency = utils.getTimeFromStr(receivedTime) - sentTimeSeconds
latencies += [2 + latency]
ipAddress = lineParts[2]
retrievingLocationFailed = ' '.join(lineParts[6:]) == 'Retrieving location failed!'
retrievingLocationResultsSentTimes[not retrievingLocationFailed] += [sentDateTime]
if not ipAddress in ipAddressesSentTimes:
ipAddressesSentTimes[ipAddress] = []
ipAddressesSentTimes[ipAddress] += [sentDateTime]
sentTimes += [sentDateTime]
colors = ['#%06X' % randint(0, 0xFFFFFF) for _ in ipAddressesSentTimes]
ax = plt.gca()
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter(utils.TIME_FORMAT))
plt.gca().xaxis.set_major_locator(mdates.HourLocator(interval = 2))
plt.scatter(sentTimes, latencies)
for ipAddress, color in zip(ipAddressesSentTimes, colors):
ipAddressSentTimes = ipAddressesSentTimes[ipAddress]
plt.scatter(ipAddressSentTimes, [1 for _ in ipAddressSentTimes], color=color)
for retrievingLocationResult, color in zip([False, True], ['red', 'blue']):
retrievingLocationResultSentTimes = retrievingLocationResultsSentTimes[retrievingLocationResult]
plt.scatter(retrievingLocationResultSentTimes, [0 for _ in retrievingLocationResultSentTimes], color=color)
plt.show()
plt.gcf().autofmt_xdate()
Edited by Benjamin Loison