def _create_groups(self, vectors): groups = [] for center in self._centers: groups.append([center]) for vector in vectors: group_number, min_distance = 0, utils._distance(vector, self._centers[0]) for (number, center) in enumerate(self._centers): cur_distance = utils._distance(vector, center) if cur_distance < min_distance: group_number = number min_distance = cur_distance groups[group_number].append(vector) return groups
def ping(self, pinger_id, pingee_id): pinger_loc = self.location(pinger_id) pingee_loc = self.location(pingee_id) distance = utils._distance(pinger_loc, pingee_loc) return round(distance)
def _calculate_new_group(self, group_center, threshold_distance): group = [] new_center = [] while not utils._are_equals(group_center, new_center): global group group = [] group_center = new_center for vector in self._vectors: distance_to_center = utils._distance(vector, group_center) if distance_to_center < threshold_distance: group.append(vector) new_center = self._calculate_group_center(group) for vector in group: self._vectors.remove(vector) self._groups.append(group)
from utils import _distance # [200~40.59.36 73.22.36 73.21.40[201~ h1 = 73 m1 = 22 s1 = 36 h2 = 73 m2 = 21 s2 = 40 hh = 40 mm = 59 ss = 36 def conv(h, m, s): return h + m/60.0 + s/3600.0 l1 = (conv(hh, mm, ss), conv(h1, m1, s1)) l2 = (conv(hh, mm, ss), conv(h2, m2, s2)) print _distance(l1, l2)
def process_f(distance_marker_set, i): for m in distance_marker_set.distance_markers: key = "%.1f" % m.distance points.append((key, m.location)) print utils._distance(target.location(), m.location) kml.points(points, "%s-%d" % (time.time(), i))