def ouput_pattern(sequences, location_sequences, u, membership, k=3): print("Output patterns on map...") time_zone = timezone('America/New_York') output = [] for c in range(u.shape[0]): indices = [i for i, x in enumerate(membership) if x == c] if len(indices) is not 0: sorted_u = sorted(u[c, indices], reverse=True) sorted_indices = sorted(indices, key=lambda x: u[c, x]) sorted_indices = sorted_indices[::-1] if k is not None and len(sorted_indices) > k: top_k = sorted_u[k - 1] sorted_indices = [ i for i in sorted_indices if u[c, i] >= top_k ] for ti, i in enumerate(sorted_indices): output.append([ (location_sequences[i][li].lat, location_sequences[i][li].lng, "C" + str(membership[i]) + "-" + str(ti) + "(" + str(li) + "/" + str(len(sequences[i]) - 1) + ")>>" + datetime.datetime.fromtimestamp(int( x.time), tz=time_zone).strftime('%Y-%m-%d %H:%M') + " " + x.lname) for li, x in enumerate(sequences[i]) ]) cpygmaps.output_patterns(output, membership, u.shape[0], OUTPUT_MAP + "_all.html")
def output_each_pattern(sequences, location_sequences, u, membership, k=None): #u_threshold = 0.15 time_zone = timezone('America/New_York') for c in range(u.shape[0]): indices = [i for i, x in enumerate(membership) if x == c] if len(indices) is not 0: sorted_u = sorted(u[c, indices], reverse=True) sorted_indices = sorted(indices, key=lambda x: u[c, x]) sorted_indices = sorted_indices[::-1] if k is not None and len(sorted_indices) > k: top_k = sorted_u[k - 1] sorted_indices = [ i for i in sorted_indices if u[c, i] >= top_k ] output = [] for ti, i in enumerate(sorted_indices): output.append([ (location_sequences[i][li].lat, location_sequences[i][li].lng, str(ti) + "(" + str(li) + "/" + str(len(sequences[i]) - 1) + ")>>" + datetime.datetime.fromtimestamp(int( x.time), tz=time_zone).strftime('%Y-%m-%d %H:%M') + " " + x.lname) for li, x in enumerate(sequences[i]) ]) color = range(len(sorted_indices)) if len(sorted_indices) > 0: cpygmaps.output_patterns(output, color, len(output), OUTPUT_MAP + "_" + str(c) + ".html")
def output_each_pattern(sequences, location_sequences, u, membership, k = None): #u_threshold = 0.15 time_zone = timezone('America/New_York') for c in range(u.shape[0]): #for c in [26]: indices = [i for i, x in enumerate(membership) if x == c] if len(indices) is not 0: sorted_u = sorted(u[c, indices], reverse = True) sorted_indices = sorted(indices, key = lambda x:u[c, x]) sorted_indices = sorted_indices[::-1] if k is not None and len(sorted_indices) > k: top_k = sorted_u[k - 1] sorted_indices = [i for i in sorted_indices if u[c, i] >= top_k] output = [] number = 0 for ti, i in enumerate(sorted_indices): a_trajectory = [(location_sequences[i][li].lat, location_sequences[i][li].lng, str(number) + "(" + str(li) + "/" + str(len(sequences[i]) - 1) + ")>>" + datetime.datetime.fromtimestamp(int(x.time), tz=time_zone).strftime('%Y-%m-%d %H:%M') + " " + x.lname) for li, x in enumerate(sequences[i]) ]#\ #if (float(location_sequences[i][li].lng) > -74.021868 and float(location_sequences[i][li].lng) < -73.984895 and float(location_sequences[i][li].lat) > 40.691014 and float(location_sequences[i][li].lat) < 40.717370) or "Liberty" in location_sequences[i][li].lname] if len(a_trajectory) > 0: output.append(a_trajectory) number += 1 color = range(len(sorted_indices)) if len(sorted_indices) > 0: cpygmaps.output_patterns(output, color, len(output), OUTPUT_MAP + "_" + str(c) + ".html")
def ouput_pattern(sequences, location_sequences, u, membership, k = 3): print("Output patterns on map...") time_zone = timezone('America/New_York') output = [] for c in range(u.shape[0]): indices = [i for i, x in enumerate(membership) if x == c] if len(indices) is not 0: sorted_u = sorted(u[c, indices], reverse = True) sorted_indices = sorted(indices, key = lambda x:u[c, x]) sorted_indices = sorted_indices[::-1] if k is not None and len(sorted_indices) > k: top_k = sorted_u[k - 1] sorted_indices = [i for i in sorted_indices if u[c, i] >= top_k] for ti, i in enumerate(sorted_indices): output.append([(location_sequences[i][li].lat, location_sequences[i][li].lng, "C" + str(membership[i]) + "-" + str(ti) + "(" + str(li) + "/" + str(len(sequences[i]) - 1) + ")>>" + datetime.datetime.fromtimestamp(int(x.time), tz=time_zone).strftime('%Y-%m-%d %H:%M') + " " + x.lname) for li, x in enumerate(sequences[i])]) cpygmaps.output_patterns(output, membership, u.shape[0], OUTPUT_MAP + "_all.html")
def output_specify_pattern(sequences, location_sequences, u, membership, c_list, k = None): #u_threshold = 0.15 time_zone = timezone('America/New_York') for c in c_list: indices = [i for i, x in enumerate(membership) if x == c] if len(indices) is not 0: sorted_u = sorted(u[c, indices], reverse = True) sorted_indices = sorted(indices, key = lambda x:u[c, x]) sorted_indices = sorted_indices[::-1] if k is not None and len(sorted_indices) > k: top_k = sorted_u[k - 1] sorted_indices = [i for i in sorted_indices if u[c, i] >= top_k] output = [] for ti, i in enumerate(sorted_indices): output.append([(location_sequences[i][li].lat, location_sequences[i][li].lng, str(ti) + "(" + str(li) + "/" + str(len(sequences[i]) - 1) + ")>>" + datetime.datetime.fromtimestamp(int(x.time), tz=time_zone).strftime('%Y-%m-%d %H:%M') + " " + x.lname) for li, x in enumerate(sequences[i])]) color = range(len(sorted_indices)) if len(sorted_indices) > 0: cpygmaps.output_patterns(output, color, len(output), OUTPUT_MAP + "_" + str(c) + ".html")