Skip to content

Instantly share code, notes, and snippets.

@danriti danriti/
Last active Aug 29, 2015

What would you like to do?
PHP Average Latency By Week
from datetime import datetime
import matplotlib.pyplot as plt
import traceview
def main():
tv = traceview.TraceView(API_KEY)
results = tv.server.latency_by_layer('Default', time_window='week')
# get the php layer
php = next((x for x in results if x.get('layer') == 'PHP'), None)
# convert timestamps to datetime objects
dates = [datetime.utcfromtimestamp(i[0]) for i in php['timeseries']['items']]
# calculate average latency (total_latency / volume) and convert to
# milliseconds
average_latency = [((i[2] / i[1]) / 1000) for i in php['timeseries']['items']]
# create a matplotlib plot
plt.figure(figsize=(12, 5), dpi=80)
plt.stackplot(dates, average_latency, colors=['#1dacd6'])
plt.title('PHP Average Latency (ms) - by Week')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.