Пример #1
0
    def get_nearest_router(self, ip):
        isp = self.get_isp(ip)

        ip_lat, ip_long = self.get_ip_coordinate(ip)

        argmin_router = isp * self.end_router_per_isp
        min_distance = coord_distance(ip_lat, ip_long,
                                      *self.router_coordinates[argmin_router])
        for r in xrange(isp * self.end_router_per_isp + 1,
                        (isp + 1) * self.end_router_per_isp):
            val = coord_distance(ip_lat, ip_long, *self.router_coordinates[r])
            if val < min_distance:
                argmin_router = r
                min_distance = val
        return argmin_router
Пример #2
0
def get_coords():
    lat = request.args.get('lat', None)
    lon = request.args.get('lon', None)
    if lat is None or lon is None:
        return "Parameters not provided", 403

    lat, lon = map(float, (lat, lon))

    consider_accidents = sorted(data, key=_sort_accidents_dist(lat, lon))

    result = []
    for count, accident in enumerate(consider_accidents):
        dist = coord_distance(lat, lon,
                                accident['location']['latitude'],
                                accident['location']['longitude'])
        if dist > HEATMAP_RADIUS and count > HEATMAP_MIN_ACCIDENTS:
            break

        result.append({
            'l': accident['location']['latitude'],
            'L': accident['location']['longitude'],
            'D': accident['damageRating']
            })

    result_actual = {'accidents': result}
    print "sent ", str(len(result)), "accidents"
    return json.dumps(result_actual)
Пример #3
0
 def print_stats(self,ip1,ip2):
     ip1_lat,ip1_long = self.get_ip_coordinate(ip1)
     ip2_lat,ip2_long = self.get_ip_coordinate(ip2)
     
     ip_distance = coord_distance(ip1_lat,ip1_long,ip2_lat,ip2_long)
     
     print "ips %f,%f to %f,%f : %f m" % (ip1_lat,ip1_long,ip2_lat,ip2_long,ip_distance)
     
     r1 = self.get_nearest_router(ip1)
     r2 = self.get_nearest_router(ip2)
     r1_lat,r1_long = self.router_coordinates[r1]
     r2_lat,r2_long = self.router_coordinates[r2]
     
     r_distance = coord_distance(r1_lat,r1_long,r2_lat,r2_long)
     
     print "routers %f,%f to %f,%f  : %f m" % (r1_lat,r1_long,r2_lat,r2_long,r_distance)
     
     print "%f , %f , %f" % (self.get_ip_router_latency(ip1,r1),self.get_router_router_latency(r1,r2),self.get_ip_router_latency(ip2,r2))
Пример #4
0
 def get_nearest_router(self,ip):
     isp = self.get_isp(ip)
     
     ip_lat,ip_long = self.get_ip_coordinate(ip)
     
     argmin_router = isp * self.end_router_per_isp
     min_distance = coord_distance(
             ip_lat,ip_long,
             *self.router_coordinates[argmin_router]
         )
     for r in xrange(isp * self.end_router_per_isp +1,(isp+1) * self.end_router_per_isp):
         val = coord_distance(
             ip_lat,ip_long,
             *self.router_coordinates[r]
         )
         if val < min_distance:
             argmin_router = r
             min_distance = val
     return argmin_router
Пример #5
0
    def print_stats(self, ip1, ip2):
        ip1_lat, ip1_long = self.get_ip_coordinate(ip1)
        ip2_lat, ip2_long = self.get_ip_coordinate(ip2)

        ip_distance = coord_distance(ip1_lat, ip1_long, ip2_lat, ip2_long)

        print "ips %f,%f to %f,%f : %f m" % (ip1_lat, ip1_long, ip2_lat,
                                             ip2_long, ip_distance)

        r1 = self.get_nearest_router(ip1)
        r2 = self.get_nearest_router(ip2)
        r1_lat, r1_long = self.router_coordinates[r1]
        r2_lat, r2_long = self.router_coordinates[r2]

        r_distance = coord_distance(r1_lat, r1_long, r2_lat, r2_long)

        print "routers %f,%f to %f,%f  : %f m" % (r1_lat, r1_long, r2_lat,
                                                  r2_long, r_distance)

        print "%f , %f , %f" % (self.get_ip_router_latency(
            ip1, r1), self.get_router_router_latency(
                r1, r2), self.get_ip_router_latency(ip2, r2))
Пример #6
0
def core_analyse():
    lat = request.args.get('lat', None)
    lon = request.args.get('lon', None)
    if lat is None or lon is None:
        return "Parameters not provided", 403

    lat, lon = map(float, (lat, lon))

    # get all near accidents within PRONE_AREA_DISTANCE_ACCIDENTS_CHECK distance
    near_accidents = consider_accidents = sorted(data, key=_sort_accidents_dist(lat, lon))
    score = 0.0
    for count, accident in enumerate(near_accidents):
        dist = coord_distance(lat, lon, **accident['location'])
        if dist > PRONE_AREA_DISTANCE_ACCIDENTS_CHECK:
            break
        score += accident['damageRating']
    print str(score) + " with %d accidents" % count
    in_accident_prone_area = score > PRONE_AREA_THRESHOLD
    return json.dumps({'in_accident_prone_area': in_accident_prone_area})
Пример #7
0
def nearest_accident():
    lat = request.args.get('lat', None)
    lon = request.args.get('lon', None)
    if lat is None or lon is None:
        return "Parameters not provided", 403

    lat, lon = map(float, (lat, lon))

    nearest_accident = None
    nearest_distance = float("inf")
    for accident in data:
        dist = coord_distance(lat, lon, **accident['location'])
        if dist < nearest_distance:
            nearest_accident = accident
            nearest_distance = dist
    nearest_accident = dict(nearest_accident) # copy the accident
    nearest_accident['latitude'] = nearest_accident['location']['latitude']
    nearest_accident['longitude'] = nearest_accident['location']['longitude']

    return json.dumps(nearest_accident)
Пример #8
0
 def get_noisy_distance(self, ip1, ip2):
     ip1_lat, ip1_long = self.get_noisy_coordinate(ip1)
     ip2_lat, ip2_long = self.get_noisy_coordinate(ip2)
     return coord_distance(ip1_lat, ip1_long, ip2_lat, ip2_long)
Пример #9
0
 def get_ip_router_latency(self, ip, router):
     l1, lg1 = self.get_ip_coordinate(ip)
     l2, lg2 = self.router_coordinates[router]
     return coord_distance(l1, lg1, l2, lg2) / self.peer_router_speed
Пример #10
0
 def get_router_router_latency(self, r1, r2):
     l1, lg1 = self.router_coordinates[r1]
     l2, lg2 = self.router_coordinates[r2]
     return coord_distance(l1, lg1, l2, lg2) / self.router_router_speed
Пример #11
0
 def get_noisy_distance(self,ip1,ip2):
     ip1_lat,ip1_long = self.get_noisy_coordinate(ip1)
     ip2_lat,ip2_long = self.get_noisy_coordinate(ip2)
     return coord_distance(ip1_lat,ip1_long,ip2_lat,ip2_long)
Пример #12
0
 def get_ip_router_latency(self,ip,router):
     l1,lg1 = self.get_ip_coordinate(ip)
     l2,lg2 = self.router_coordinates[router]
     return coord_distance(l1,lg1,l2,lg2)/self.peer_router_speed
Пример #13
0
 def get_router_router_latency(self,r1,r2):
     l1,lg1 = self.router_coordinates[r1]
     l2,lg2 = self.router_coordinates[r2]
     return coord_distance(l1,lg1,l2,lg2)/self.router_router_speed