Пример #1
0
def single_location_kml(request, ident):
    """
    Return a KMZ file representing a single location. Passed in is the ident.
    (as opposed to the pk). No routes!
    """

    l = Location.goof(identifier=ident, loc_class=1)
                     
    f = AirportFolder(name=ident, qs=[l])

    return folders_to_kmz_response([f], add_icon=True)
Пример #2
0
    def search_airport(self, ident, date):
        hi = HistoricalIdent.objects.filter(identifier=ident)
        ex = Location.goon(loc_class=1, identifier=ident)

        valid_hi = None
        invalid_hi = None
        airport_ident = None
        airport = None

        if hi.count() > 0:
            try:
                valid_hi = hi.get(start__lte=date, end__gte=date)
                invalid_hi = None
            except HistoricalIdent.DoesNotExist:
                valid_hi = None
                invalid_hi = hi.latest('end')
        elif ex:
            return ex

        ##############

        if invalid_hi and not valid_hi and not ex:
            #we dont have anything but an expired HI, just use it
            return invalid_hi.current_location

        elif invalid_hi and not valid_hi and ex:
            # an ex trumps an invalid HI
            return ex

        elif valid_hi:
            # we have a valid HI, use it no matter what!
            return valid_hi.current_location

        elif not valid_hi and not invalid_hi and not ex:
            #we have nothing :(
            return None

        else:
            assert False, "Some weird corner case"
Пример #3
0
 def search_airport(self, ident, date):
     hi = HistoricalIdent.objects.filter(identifier=ident)
     ex = Location.goon(loc_class=1, identifier=ident)
     
     valid_hi = None
     invalid_hi = None
     airport_ident = None
     airport = None
     
     if hi.count() > 0:
         try:
             valid_hi = hi.get(start__lte=date, end__gte=date)
             invalid_hi = None
         except HistoricalIdent.DoesNotExist:
             valid_hi = None
             invalid_hi = hi.latest('end')
     elif ex:
         return ex
     
     ##############
     
     if invalid_hi and not valid_hi and not ex:
         #we dont have anything but an expired HI, just use it
         return invalid_hi.current_location
     
     elif invalid_hi and not valid_hi and ex:
         # an ex trumps an invalid HI
         return ex
         
     elif valid_hi:
         # we have a valid HI, use it no matter what!
         return valid_hi.current_location
     
     elif not valid_hi and not invalid_hi and not ex:
         #we have nothing :(
         return None
         
     else:
         assert False, "Some weird corner case"
Пример #4
0
def routes_location_kml(request, ident, type):
    """
    Returns a KMZ of all routes flown to the passed location identifier,
    also adds a point over the passed identifier
    """
    
    if type == 'airport':
        lc=1
    elif type == 'navaid':
        lc=2
    else:
        lc=1
        
    #raises 404 if no location is found
    l = Location.goof(identifier=ident, loc_class=lc)
    
    qs = Route.objects\
              .filter(routebase__location__identifier=ident.upper())\
              .values('kml_rendered', 'simple_rendered')\
              .distinct()
    
    name = l.identifier
    
    return qs_to_time_kmz(qs, points=(name, [l]))
Пример #5
0
def airports():   #import airport
    """
    id	 ident	type	name	latitude_deg	longitude_deg	elevation_ft	
    continent	iso_country	iso_region	municipality	scheduled_service
    gps_code	iata_code	local_code	home_link	wikipedia_link	keywords
    """
    
    path = os.path.join(PROJECT_ROOT, 'airport', 'csv', 'airports_new.csv')
    f = open(path, 'rb')
    reader = csv.reader(f, "excel")
    titles = reader.next()
    reader = csv.DictReader(f, titles)

    # a list of idents that have changed, and therefore get HistoricalIdents
    hists = []

    for count, line in enumerate(reader):
        
        redo_after_save = False
        
        ##########################

        point =  line["point"]
        elev =   line["elev"]
        type_ =  line["type"]
        
        ident =  line['ident']
        local =  line["local"]
        icao =   line["icao"]
        iata =   line["iata"]
        
        country= line["country"]
        region = int(line["region"])
        
        city =   line["city"].decode('utf-8')
        name =   line["name"].decode('utf-8')
        
        idd =    int(line['id'])        
        
        if elev == "":
            elev = None    

        ##########################
        
        if idd not in BANNED:
            l,created = Location.objects.get_or_create(pk=idd,
                                             user=ALL_USER,
                                             loc_class=1)
        else:
            l = Location(id=idd)
        
        if created:
            print "new airport:", ident
        
        elif idd in BANNED:
            print "BANNED: %s" % ident
            
        else:
            if not l.identifier == ident:
                a =  [colored(l.identifier, 'red'), colored(ident, 'green')]
                print u"changed ident!: {0} -> {1}".format(*a)
                hists.append(make_historical_ident(l, ident))
                redo_after_save = True
            
            elif not l.name == name:
                a = [ident, colored(l.name, 'red'), colored(name, 'green')]
                print u"changed name!:  {0} {1} -> {2}".format(*a)
                redo_after_save = True
            
            elif not l.municipality == city:
                a = [ident, colored(l.municipality, 'red'), colored(city, 'green')]
                print u"changed city!:  {0} {1} -> {2}".format(*a)
                redo_after_save = True
        
        l.municipality = city
        l.country = Country(pk=country)
        l.elevation = elev
        l.location = point
        l.loc_type = type_
        l.name = name
        l.region = Region(pk=region)
        
        l.identifier = ident
        l.icao_identifier = icao
        l.iata_identifier = iata
        l.local_identifier = local
        
        try:
            if l.id not in BANNED:
                l.save()
            
            if redo_after_save:
                ## iff the ident has changed, we need to wait until the new
                ## location is saved before we re-render
                Flight.render_airport(ident)
                
            
        except Exception, e:
            print ident, e
            
        if (count % 1000) == 0:
            #update user on status
            print colored("\n{0}\n".format(count), 'cyan')