mrjackwills / adsbdb

public api for aircraft, airlines, & flightroutes
https://adsbdb.com
MIT License
109 stars 6 forks source link

[NEW FEATURE] Return IATA callsign for flight #6

Open amorris13 opened 1 year ago

amorris13 commented 1 year ago

Would it be possible to return the IATA callsign for a flight for a /callsign request. E.g., for https://api.adsbdb.com/v0/callsign/QFA409, could it return QF409? For many flights this is straightforward (just change that airline ICAO code its IATA code, e.g. QFA to QF), but for some it is trickier, e.g., QLK10 is QF2010.

Additional context: I've been building a split flap display (using https://github.com/scottbez1/splitflap) to show the planes flying overhead (what I've built: https://photos.app.goo.gl/SUe6HfQkHJN3Eo6X9). I've got an ADS-B receiver set up to get the callsign then use this API in order to get the route (thankyou!). But I'd also like to display the flight callsign in the form that people are more familiar with (and so that it will always fit on my 6 character display!).

mrjackwills commented 1 year ago

Ah, yeah, should probably include that. I think I have a lot of the data already, so would just need to do a few database migrations to load it up (I do not have this data, so a re-think needed), and then also make sure that when it scrapes unknown routes it includes the IATA code as well.

Should probably change the response to

"callsign_icao": "QFA409",
"callsign_iata": "QF409",

But that would be a breaking change (probably have a few other breaking changes that I could implement), so maybe if/when it goes to v1, in the meantime could just return

"callsign": "QFA409",
"callsign_iata": "QF409",

EDIT: realised that adsbdb is storing flightroute data inefficiently, this might take a little longer to fix and implement

ladewig commented 1 year ago

You probably have sources lined up, but just as an FYI, some links for the codes:

https://www.iata.org/en/publications/directories/code-search https://www.flugzeuginfo.net/table_airlinecodes_airline_en.php https://airlinecodes.info/ https://www.orbtickets.com/airlines/airline-codes http://arg-intl.com/resources/iata-icao-airline-codes/ https://www.bts.gov/topics/airlines-and-airports/airline-codes

mrjackwills commented 1 year ago

Would it be possible to return the IATA callsign for a flight for a /callsign request. E.g., for https://api.adsbdb.com/v0/callsign/QFA409, could it return QF409? For many flights this is straightforward (just change that airline ICAO code its IATA code, e.g. QFA to QF), but for some it is trickier, e.g., QLK10 is QF2010.

Additional context: I've been building a split flap display (using https://github.com/scottbez1/splitflap) to show the planes flying overhead (what I've built: https://photos.app.goo.gl/SUe6HfQkHJN3Eo6X9). I've got an ADS-B receiver set up to get the callsign then use this API in order to get the route (thankyou!). But I'd also like to display the flight callsign in the form that people are more familiar with (and so that it will always fit on my 6 character display!).

I have a beta version online at the moment, at api.adsbdb.com/beta/ instead of api.adbsbdb.com/v0/ Any chance you could give it a go?

One can now search an airline by either the ICAO or IATA callsign.

The returned responses are slightly different, now include an Airline object, or null, as well as callsign_iata and callsign_icao keys.

I haven't documented all this yet, but the response's should be pretty straight forward

amorris13 commented 1 year ago

I've given it a go - seems to work (at last better than my hacky s/QFA/QF/ approach). However, there are a few that it hasn't picked up so far:

mrjackwills commented 1 year ago

Thanks for the feedback,

At the moment, the beta version isn't scraping for unknown callsigns, if/when it gets merged into main, it will do this, and so in that situation it would hopefully pick up the VOZ65 callsign (assuming that the VOZairline is in the database, which I think it should be).

As for QLK10, I basically went over all 100k callsigns that I have in the database, and compared them to a known list (aka I scraped against the entire adsbdb database), and then created ICAO & IATA callsigns, if both could be found in the scraped data. In this case, it looks like it couldn't find both an ICAO and IATA callsign, and so just inserted it as "other".

But, what I could do, is that in this situation, do a best guess based upon the given callsign, which in this query would return Qantas Link, and then it could return an Airline object, but have icao_callsign and iata_callsign as null. The beta code isn't up on github yet, but it refactors the way that callsigns are handled in the application & database, which should make all of this a lot easier.

ladewig commented 1 year ago

If you include in the repository the file containing your index of ICAO airline codes and their matching IATA codes (or null where none exist) that you use to generate the IATA flight number when updating your DB, folks could submit PRs for codes you're currently missing such as QLK > QF, QJE > QF, and VOZ > VA.

mrjackwills commented 1 year ago

If you include in the repository the file containing your index of ICAO airline codes and their matching IATA codes (or null where none exist) that you use to generate the IATA flight number when updating your DB, folks could submit PRs for codes you're currently missing such as QLK > QF, QJE > QF, and VOZ > VA.

This is the csv that I have loaded into the beta database. Every entry has a unique ICAO code, but there are a few clashes in the IATA codes, so need to work out how to handle that

https://gist.github.com/mrjackwills/c8d74694ff4f095c81967df875352840

ladewig commented 1 year ago

What do you mean by clash? The same company may use the same IATA code for flights that use different ICAO codes, like Qantas does. Or are you referring to something else?

From a style perspective, since ICAO is going to be the unique value used for lookups, I'd make that the first column rather than the IATA code, but it's just a visual thing for me.

mrjackwills commented 1 year ago

It's not yet on the live beta release, but it now has an endpoint /airline/[airline_code], which will search for an airline based on either the ICAO or IATA short code, and so in this situation one needs to decide, when there are multiple airlines with the same IATA code, whcih one to return.

There is also a query, but I'm not near the code at the moment so I can't check, that, from memory, uses the IATA, or rather assumed IATA, code to find a fully joined flight-route. So, in the case of a clash, I think it selects the one that was inserted in the database first, which probably means by alphabetical order.

ladewig commented 1 year ago

If you have an endpoint that accepts an IATA two letter code and returns a three letter ICAO code and airline info (name, etc.), then it should return all of the matching airlines and their ICAO codes. Up to the requestor to figure out what to do with it.

If you're looking at the routes though... I think you might wind up driving yourself crazy trying to accommodate this scenario the more I look at it. 😉

After digging into the latest flightroute.sqb file with the example @amorris13 provided, I see what you're talking about with the clashes now.

Seems like the only way you could accurately return the correct flights/numbers is if you maintain your own crosswalk for those situations where you have QLK flights with a numeric portion that is less than 4 digits. That the flightroute.sqb file has out-of-date routes makes it that much harder. Looks like you can do it programmatically, but it gets complicated. Static mapping would be simpler, but more work to maintain. I don't envy you if you go down this path.

With my bot I've been doing a simple substitution to get the IATA flight number, but thankfully the airlines that fly overhead don't have the convoluted system Qantas has so it's a 1:1 match between the two codes.

As reference, Qantas flight numbers break down as follows according to https://www.australianfrequentflyer.com.au/qantas-flight-numbers/ :

QF1-199 are Qantas-operated international flights QF200-299 are codeshare flights operated by Jetstar QF300-399 are international codeshare flights to/from Australia operated by other Qantas partner airlines QF400-1399 are Qantas domestic flights QF1400-1499 are QantasLink Dash 8 flights (generally between Sydney and VIC/ACT destinations) QF1500-1599 are QantasLink Boeing 717 flights between major Australian cities QF1600-1999 are other QantasLink jet services on regional routes (mainly within WA) QF2000-2899 are QantasLink Dash 8 flights (excluding QF2600-2717) QF2600-2717 are codeshare flights operated by Alliance Airlines, Airnorth or Network Aviation QF3000-4999 are codeshare flights operated by various international partner airlines QF5000-5399 are codeshare flights operated by Jetstar Japan or Jetstar Asia QF8000-8999 are codeshare flights operated by Emirates, Air New Zealand, LATAM Airlines or Cathay Pacific

mrjackwills commented 1 year ago

thanks for the info!

as the for /airline/[code]route, if an IATA code can return an array of Airlines, then all request must also return an array of Airlines (i.e. even when submitting an ICAO code, which will always correlate to a single Airline), as I want all the return types to match. This isn't really a problem I suppose.