fetcher.perform() except pycurl.error as e: print(str(e)) return None page = buf.getvalue() tree = etree.fromstring(page, PARSER) similars = tree.xpath(XPATH_QUERY) if len(similars) == 0: return [] return [c.attrib['data-venueid'] for c in similars[0].iterchildren()] if __name__ == '__main__': client = foursquare.Foursquare(CLIENT_ID, CLIENT_SECRET) import arguments args = arguments.city_parser().parse_args() db = cm.connect_to_db('foursquare', args.host, args.port)[0] checkins = db['checkin'] # print(venue_profile(client, '')) # up = user_profile(client, 2355635) # vids = ['4a2705e6f964a52048891fe3', '4b4ad9dff964a5200b8f26e3', # '40a55d80f964a52020f31ee3', '4b4ad9dff964c5200'] # [client.venues(vid, multi=True) for vid in vids] # answers = list(client.multi()) r = gather_all_entities_id(checkins, city='helsinki', limit=50) for b in r: print(b) # svids = ['4c4787646c379521a121cfb5', '43222200f964a5209a271fe3', # '4b218c2ef964a520a83d24e3'] # gold = [[], ['4bbd0fbb8ec3d13acea01b28', '451d2412f964a5208a3a1fe3'], # ['4d72a2a9ec07548190588cbf', '4a736a23f964a52062dc1fe3',
ppl.plot(centroid[i, :], marker+'-', ms=9, c=ppl.colors.set1[i]) if centroid.shape[1] == 24/chunk: plt.xticks(range(24/chunk), named_ticks('day', offset, chunk)) else: plt.xticks(range(7*3), named_ticks('mix')) def get_distorsion(ak, kl, sval): """Compute the sum of euclidean distance from `sval` to its centroid""" return np.sum(np.linalg.norm(ak[kl, :] - sval, axis=1)) if __name__ == '__main__': # pylint: disable=C0103 import arguments args = arguments.city_parser().parse_args() city = args.city DB, CLIENT = cm.connect_to_db('foursquare', args.host, args.port) # pylint: disable=E1101 do_cluster = lambda val, k: cluster.kmeans2(val, k, 20, minit='points') def getclass(c, kl, visits): """Return {id: time pattern} of the venues in class `c` of `kl`.""" return {v[0]: v[1] for v, k in zip(visits.iteritems(), kl) if k == c} def peek_at_class(c, kl, visits, k=15): """Return a table of `k` randomly chosen venues in class `c` of `kl`.""" sample = r.sample([get_venue(i)