Esempio n. 1
0
def output_location_cluster(location_list, cluster_key, output_file):
    sorted_locations = sorted(location_list, key=lambda x:getattr(x, cluster_key))
    groups = {x:list(y) for x, y in itertools.groupby(sorted_locations, lambda x:getattr(x, cluster_key))}

    clocation.output_location_list([], "w", output_file)
    # for each cluster
    for c, a_group in groups.items():
        phase_ste = "Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n"
        clocation.output_location_list(a_group, "a", output_file, phase_ste)
Esempio n. 2
0
def output_location_cluster(locations, output_file):
    sorted_locations = sorted(locations.values(), key=lambda x:x.cluster1)
    groups = {x:list(y) for x, y in itertools.groupby(sorted_locations, lambda x:x.cluster1)}

    clocation.output_location_list([], output_file)
    f = open(output_file, "a")
    # for each cluster
    for c, a_group in groups.items():
        f.write("Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n")
        clocation.output_location_part_list(a_group, f)
    f.close()
Esempio n. 3
0
def output_location_cluster(location_list, cluster_key, output_file):
    sorted_locations = sorted(location_list,
                              key=lambda x: getattr(x, cluster_key))
    groups = {
        x: list(y)
        for x, y in itertools.groupby(sorted_locations,
                                      lambda x: getattr(x, cluster_key))
    }

    clocation.output_location_list([], "w", output_file)
    # for each cluster
    for c, a_group in groups.items():
        phase_ste = "Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n"
        clocation.output_location_list(a_group, "a", output_file, phase_ste)
Esempio n. 4
0
def output_location_cluster(locations, output_file):
    sorted_locations = sorted(locations.values(), key=lambda x: x.cluster1)
    groups = {
        x: list(y)
        for x, y in itertools.groupby(sorted_locations, lambda x: x.cluster1)
    }

    clocation.output_location_list([], output_file)
    f = open(output_file, "a")
    # for each cluster
    for c, a_group in groups.items():
        f.write("Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n")
        clocation.output_location_part_list(a_group, f)
    f.close()
Esempio n. 5
0
def get_locations(slat, slng, elat, elng, output_file, radius = 100):
    locations = clocation.LocationDict()
    radius_degree = radius * 1 / 111600 # assume 1 degree = 111600m
    print("Getting locations..., spaces #=", math.ceil((elat - slat)/radius_degree) * math.ceil((elng - slng)/radius_degree)\
        , "=", math.ceil((elat - slat)/radius_degree), "x", math.ceil((elng - slng)/radius_degree))
    
    for i, lat in enumerate(numpy.arange(slat, elat, radius_degree)):
        for j, lng in enumerate(numpy.arange(slng, elng, radius_degree)):
            url = \
                "https://api.instagram.com/v1/locations/search?"\
                + "lat=" + str(lat) + "&lng=" + str(lng) + "&distance=" + str(radius)\
                + "&access_token=" + _ig_accesstoken() + "&count=50"
            #print(url)
            data = _get_ig_result(url)

            res = data.split("{\"latitude\":")
            for a_location_str in res[1:]:
                a_location = _fit_a_location(a_location_str)
                if a_location.lid not in locations.keys():
                    locations[a_location.lid] = a_location
            print(i, "x", j, "-center at lat:", lat, "\t,lng:", lng, "\tlocations #:", len(locations))
    clocation.output_location_list(locations.values(), "w", output_file)
Esempio n. 6
0
def get_locations(slat, slng, elat, elng, output_file, radius=100):
    locations = clocation.LocationDict()
    radius_degree = radius * 1 / 111600  # assume 1 degree = 111600m
    print("Getting locations..., spaces #=", math.ceil((elat - slat)/radius_degree) * math.ceil((elng - slng)/radius_degree)\
        , "=", math.ceil((elat - slat)/radius_degree), "x", math.ceil((elng - slng)/radius_degree))

    for i, lat in enumerate(numpy.arange(slat, elat, radius_degree)):
        for j, lng in enumerate(numpy.arange(slng, elng, radius_degree)):
            url = \
                "https://api.instagram.com/v1/locations/search?"\
                + "lat=" + str(lat) + "&lng=" + str(lng) + "&distance=" + str(radius)\
                + "&access_token=" + _ig_accesstoken() + "&count=50"
            #print(url)
            data = _get_ig_result(url)

            res = data.split("{\"latitude\":")
            for a_location_str in res[1:]:
                a_location = _fit_a_location(a_location_str)
                if a_location.lid not in locations.keys():
                    locations[a_location.lid] = a_location
            print(i, "x", j, "-center at lat:", lat, "\t,lng:", lng,
                  "\tlocations #:", len(locations))
    clocation.output_location_list(locations.values(), "w", output_file)