@@ -0,0 +1,2546 @@
+import collections%0Aimport datetime%0Aimport logging%0Aimport struct%0Aimport sys%0A%0Afrom google.cloud import bigtable%0A%0AInternetData = collections.namedtuple(%0A    'InternetData',%0A    %5B'key', 'time', 'upload', 'download', 'rtt', 'samples'%5D)%0A%0Adef read_asn(key_no_date):%0A    start_day = datetime.date(2009, 1, 1)%0A    key = '%25s%7C%2504d-%2502d-%2502d' %25 (key_no_date.ljust(10), start_day.year, start_day.month, start_day.day)%0A    response = table.read_rows(start_key=key)%0A    data = %5B%5D%0A    try:%0A        key_part = key_no_date%0A        while key_part == key_no_date:%0A            response.consume_next()%0A            for key in sorted(response.rows):%0A                row = response.rows%5Bkey%5D.to_dict()%0A                key_part, date = key.rsplit('%7C', 1)%0A                key_part = key_part.strip()%0A                if key_part != key_no_date:%0A                    break%0A                if 'data:download_speed_mbps_median' in row: %0A                    download = row%5B'data:download_speed_mbps_median'%5D%5B0%5D.value%0A                    download = struct.unpack('%3Ed', download)%5B0%5D%0A                else:%0A                    logging.warning('no download data for %25s', key)%0A                    continue%0A                if 'data:upload_speed_mbps_median' in row: %0A                    upload = row%5B'data:upload_speed_mbps_median'%5D%5B0%5D.value%0A                    upload = struct.unpack('%3Ed', upload)%5B0%5D%0A                else:%0A                    logging.warning('no upload data for %25s', key)%0A                    continue%0A                if 'data:rtt_avg' in row:%0A                    rtt = row%5B'data:rtt_avg'%5D%5B0%5D.value%0A                    rtt = struct.unpack('%3Ed', rtt)%5B0%5D%0A                else:%0A                    logging.warning('no rtt data for %25s', key)%0A                    continue%0A                if 'data:count' in row:%0A                    samples = row%5B'data:count'%5D%5B0%5D.value%0A                else:%0A                    logging.warning('no sample count data for %25s', key)%0A                    continue%0A                data.append(InternetData(key=key_part, time=date, download=download, upload=upload, rtt=rtt, samples=samples))%0A            response.rows.clear()%0A    except StopIteration:%0A        pass%0A    return data%0A%0A%0Adef main(args):%0A    global table%0A    # Read an AS's data%0A    client = bigtable.Client(project='mlab-oti', admin=False)%0A    instance = client.instance('mlab-data-viz-prod')  # Seems like I shouldn't be allowed to do this?%0A    table = instance.table('client_asn_by_day')%0A    data = read_asn('AS13367x')%0A    print data%0A%0A%0Aif __name__ == '__main__':%0A    main(sys.argv)%0A

Read from BT