def plotSegments(jason, name="", labels=False): # read delimeters for each stop delims = readDelims() stopAdds = [getStopSet(jason["packets"], stop) for stop in delims] intersectBins = [set() for stop in delims] combobs = combinations(range(len(delims)), 2) for combob in combobs: curSect = stopAdds[combob[0]].intersection(stopAdds[combob[1]]) for i in range(combob[0], combob[1]): intersectBins[i+1].update(curSect) probably_junk = stopAdds[0].intersection(stopAdds[-1]) y = [len(bin - probably_junk) + 2 for bin in intersectBins] y[0] = y[1] # For labelling purposes x = [stop['start'] for stop in delims] realy = [stop['actual'] for stop in delims] plot.xlabel('Seconds since '+jason["initial_time"]) plot.ylabel('Number of bus occupants (predicted)') plot.xlim(0, delims[-1]['end']) plot.title(name) plot.step(x, y) plot.step(x, realy, color="purple", where="post") if(labels): for stop in delims: annotate(stop["code"], stop["start"], stop["actual"], 10, 10) makeWidePlot("bus", "segments") plot.show()
def plotVectors(json, coincidence=0, name="", minTime=30, maxTime=1700, labels=False): delims = readDelims() macAddresses = {} json["packets"].apply(lambda row: addPacket(row, macAddresses), axis=1) sum = np.zeros(json["last"], dtype=np.int) for val in macAddresses.values(): diff = val[1] - val[0] if ((diff > minTime) and (diff < maxTime) and (val[2] >= coincidence)): sum[val[0]: val[1]] += 1 plot.xlabel('Seconds since start') plot.ylabel('Devices', color='b') plot.step(range(int(json["last"])), sum.tolist()) actual = [stop['actual'] for stop in delims] stopx = [stop['start'] for stop in delims] ax2 = plot.twinx() ax2.step(stopx, actual, 'r', where="post") (t1.set_color for t1 in ax2.get_yticklabels()) ax2.set_ylabel('Riders', color='r') plot.ylim(0, 30) plot.xlim(0, json["last"]) if(labels): for stop in delims: annotate(stop["code"], stop["start"], stop["actual"], 10, 10) makeWidePlot("bus", "vectors") plot.show()