Wednesday, March 20, 2019

Telemetry and units for altitude and speed

A pilot contacted me the other day to ask this:

Using the exact same GPX file generated from Bad Elf. If I create a flight from it on the iPhone app, by sharing it from the Bad Elf app, or as a file from Files app, the Altitude of meters and Speed of m/s both get converted properly to feet and knots when viewed on the web site. Using the exact same file on the web page will not cause the conversion to feet and knots to take place, and we get altitudes that are 1/3 the correct, and speeds about 1/2 correct. What is going on?


For the most part, Telemetry on MyFlightbook is unitless.  This helps in some areas but can be a bit  confusing in others.

Here is where it is important to distinguish a format from a schema.  A format is simply the way that data is represented in a file.  CSV and XML are both formats (and both text-file based).  CSV is a simple table with each line of text represents a row in a table, and columns within a row are separated by a comma (hence "Comma Separated Values", or CSV).  XML uses start and end tags (e.g., "<altitude>48.3</altitude>") to delimit data.  But note that while a format tells you how to read the data, it doesn't say anything about how the data should be interpreted.  It could be literally anything, as long as it's correctly formatted.

A schema is a convention for how data is interpreted.  E.g., declaring that an altitude is labeled "altitude" and is represented in meters.  GPX and KML are two common ways to represent telemetry, and these are both XML-based schemas.  That is, their format is XML, but the data is arranged in a specified manner that allows you to interpret it correctly.

GPX and KML use meters for altitude and meters/second for speed, and MyFlightbook (both web and iOS/Android) knows this when importing; it can thus infer reasonable speeds to use for takeoff or for landing.

CSV is a significantly more compact and extensible format than XML, but there is no "CSV Schema"; the data can be whatever you want in whatever units you want.  Because it is compact and can include MyFlightbook specific data (such as noting when a takeoff or landing occurs), the MyFlightbook mobile apps generate CSV.  And, since feet and knots are generally what aviators around the world are familiar with, those are the units that MyFlightbook uses in its CSV file. 

But since you can upload CSV from any number of sources (engine monitors, GPS logs, etc.), MyFlightbook can’t make any assumption about the units used; I just have a dictionary of column headings that have some semantic meaning to me (“Heading”, “Altitude”, “Speed”, “Oil Temp”), where I can at least determine the type of the data (number, date, time, latitude/longitude, etc.), but I can’t assume units. (OK, I suppose “Heading” is only in degrees, but my other examples here are inherently ambiguous).  Any data with a column heading that is not in the dictionary is simply ignored.

You may notice that when viewing telemetry on MyFlightbook, units are not displayed, and this is why.  It is also why MyFlightbook's default units in the CSV it generates are feet and kts; that way the numbers “look right” (even in the metric world, where people can work with altitudes in meters just fine, most people don’t think in terms of meters/second).

Both the iOS and Android apps can import GPX/KML (or even NMEA, on iOS, which is yet another schema) and create a flight from it.  So why do the units convert to ft/kts when doing this?

The iOS/Android apps import by treating the data that as an alternative GPS source.  So they're not directly attaching the data to the flight. Instead, the architecture is more like this:
I.e., the system for detecting takeoffs/landings receives data in real-time from the physical GPS (typical) OR from a fake GPS data stream that derives from a file; it doesn’t (in fact, can’t) distinguish the source.  Since the input file has a schema, the system knows which units to use and can convert as appropriate to determine takeoffs/landings/etc. 

As it is fed the data and detecting the flight, it is also optionally recording the flight, which as I described above, it does using CSV and using feet and knots; this is what is submitted up to the server when the flight is saved.  

So the original GPX/KML/NMEA used for import is lost; it’s a data source, but think of it not as a data source for your flight, but rather as a data source for the GPS emulator. 

On the web, the process is similar, but there are three key differences: 
  • There isn't an actual GPS (it’s always from a file)
  • You’re always attaching the file and optionally detecting, which is the reverse of the mobile apps (which always detect and only optionally recording the result)
  • You can attach/autofill from CSV
This has a couple of implications.  One is that the web does not generate a telemetry file and instead attaches what you submit directly and with no translation.  

And while the input units for GPX/KML are specified, that's not true for CSV.  MyFlightbook's graphing system (which is web only) needs to work with all of these formats, so it has a layer of abstraction built in which converts whatever underlying the data format is into a simple table (rows/columns) of data, where each column has a label (e.g., “Speed”, “Oil Temperature”) and a data type (“number”, “timestamp”, etc.).  The graphing system at that point has no idea about semantics or units; it just graphs the raw data.  So a GPX file will graph in meters and meters/second, while a CSV file would (probably) graph in feet and knots, but the only way you'd be able to distinguish is to look at the values: if you see "35,000" in the altitude, it's probably feet.

(I have had a request to allow you to apply a conversion factor at display time, so that if you know the data is in metric you can convert to ft/kts at display time, but I haven’t gotten around to that.)

This works just fine until you go to download the data from the website.  Downloading in the original format is easy: no translation is required; if it was GPX, it is still GPX.  

But what if you want a KML version of your data (to display in Google Earth, for example) and the original data was CSV?  The problem is that KML has to be in meters and meters/second, but the CSV may have been feet and knots.  For this reason, when you download your data in a format that has a schema, you are asked to declare the units for speed/altitude in the original data. It will then load the data into a table (as described above), apply the conversions, and then render into the correct output. 

So, for example, if you initialized a flight on your iPhone from Bad Elf data and saved it, that should have saved in CSV format with ft/kts (which you can verify this by downloading in original format).  If you want a GPX version of that flight, you would download GPX and declare that the original units were knots and feet; that tells the system which conversion factor to apply to the CSV data to produce valid GPX.

Tuesday, January 22, 2019

Printing from an electronic logbook and traditional "paper" logbooks

A few months ago, I had a blog post about printing from MyFlightbook.

I had a Facebook conversation with a pilot today about why sometimes the per-page subtotals spill onto an additional page, consuming extra paper and occasionally leaving swaths of blank space on a page.

The question he asked was twofold: (a) why do I have the extra clutter of having additional category/class rows in the per-page subtotals, and (b) why can't I reliably keep a page's flights the subtotals for that page actually on a single printed page?  Specifically: "is the challenge regarding the coding of it?"

It's a perfectly legitimate question, and I realize my earlier post may not have sufficiently or clearly explained that, so I decided to dive in and answer in a bit more depth, which I'm reproducing below (lightly edited for clarity, to remove typos, and to translate from Facebook format):

First: why do my per-page subtotals subdivide by category/class?

Paper logbooks put each category/class into their own columns. This makes sense for exactly one reason - allowing you to compute category/class totals by hand. You can't do (easy) hand summation if category/classes are co-mingled in a single column. (Of course, computers don't care, that works just fine).

But there are two really bad tradeoffs for doing this: one is that columns don't scale well at all. So if you've got some ASEL time, some ASES time, some AMEL time, some glider time, some balloon time, some helicopter time, ...well, now when you go to print you have a 2-dimensional problem: each flight of your logbook needs to spill over across two horizontal pages (Or, columns need to narrow, which means everything needs to grow vertically and becomes really hard to read!!!).

The other really bad tradeoff is that it effectively means you need to limit the number of category/classes you support. This is why most paper logbooks are focused on JUST airplanes, or JUST gliders, and might have only one column for "other".

Those are bad - but necessary - tradeoffs in the paper world. But in the electronic world, these are simply terrible tradeoffs, especially since the exact problem that they're trying to solve (aiding human computation of totals) doesn't exist once computers are can do the math.

So if you did this in the electronic world, you'd get all the downside with none of the upside. That seems utterly ridiculous.

For this reason, I striped the per-page subtotals by category/class because adding rows works great (stays within the flow of reading from page to page) but adding columns doesn't.

So - why can't I do a better job of keeping things on a page, from occasionally spilling on a page?

I'll back up for a moment to another problem with paper: the form in the paper world is sized and printed before any content is added. I.e., the layout is fixed. So you have three choices when you fill in oversized data:
  • You can "spill over", with one flight spanning more than one row of the paper page;
  • You can "clip" your data - stopping when you hit the boundary of the flight's row and discarding what didn't fit;
  • Or you can "shrink to fit", making the text smaller and smaller until it fits the allotted space.
All of those are truly terrible solutions, but with paper, they are the only options; you can only choose the least evil.

In the electronic world, however, that ridiculous constraint is removed: the row can shrink or grow to accommodate the data. i.e., each row can be a unique height that is appropriate for the data contained therein.

So...your question was "is the challenge regarding the coding of it." At one level, the answer is "no, it's not complicated".

What you would do in this scenario is add a flight to the page, compute the subtotals for the page,  add those subtotals to the page as well, and see if it fits. Then repeat for the next flight. If the flight you add causes the subtotals to spill to the next page, then back up to where you were just prior to adding the flight, finish off that page, then start a new page with the new flight. There are a few other issues, but at the core, that's the process and it's straightforward.

Here we get to an architectural issue. MyFlightbook uses an abstract layout methodology (HTML). So I say "here's a row of a table; it has these cells and each cell contains this text." MyFlightbook doesn't know anything about fonts, font sizes, pixels, word wrapping, page margins, page dimensions, screen or printer resolutions, or a whole slew of other things that are required in order to figure out what to draw on a page. That is all handled on the web by the browser (which takes the HTML and converts it into stuff on a screen), or by the PDF generator that I use, which does the exact same thing as a browser, except that instead of drawing on the screen it draws into a PDF file.

So I can't implement the algorithm I described above (add a row, see if it fits, if not, start a new page). That is, I have to render the entire page in HTML, and THEN either send it to you so that your browser can render it to the screen, or send it to the PDF generator so that I can send you a PDF file. There's no ability to have the back-and-forth interaction that such an algorithm requires.

The ONLY way to solve that is to build an entire rendering engine - something that DOES know how to measure things, lay them out on the screen, perform word wrapping, make tables fit their contents (itself actually a really hard problem). I.e., I would quite literally need to re-implement most of what a browser does.

But I think about the herculean effort that represents (much bigger than all of MyFlightbook combined - and MyFlightbook actually isn't a small piece of code!), and I step back and ask "what problem would this solve?"

The answer is simple: per-page subtotals. That's it. No other purpose whatsoever is served.

And what makes per-page subtotals so important? Paper tradition. Per page subtotals serve exactly one purpose: if you're doing manual computation, you don't want to go back to the start of your logbook every time you want to compute your totals; that's ridiculous with a pen and paper. But in the electronic world, computers don't complain about doing that. So per-page sub-totals are an insane holdover from paper-and-pencil human arithmetic. Why on earth let an artifact of the 14th century drive such a massive software undertaking?

So in summary, the correct answer to the question "is the challenge regarding the coding of it", the answer is "yes. It would require literally thousands of man years of effort to actually solve an obsolete problem."

My suggestion? Turn off per-page subtotals. They are truly utterly pointless. "Continuous" mode will make much more efficient use of your paper and will still get the math right because computers don't make math mistakes. And your pagination will work great.

Update: since writing this blog post, I have added a hack to allow for better pagination.  If you have, say, 10 flights per page and on one page the 9th and 10th flights are "spilling over" onto a new page, you can edit the 8th flight on that page to include "///---" at the end of the comments.  The "///" and everything after is not included in the print layout, but it will force a new page after that flight, so what had been the 9th and 10th flight alone on a new page in this example would now be the 1st and 2nd flight on a new 10-flight page.

Declutter your life and your logbook



Marie Kondo is a surprise hit on Netflix, with her advice about getting rid of things in your life that no longer bring you joy.

Why not declutter your logbook in the same way?

After a few years of flying, you may find that your totals or currency get filled with all sorts of data that you have accumulated but about which you no longer need to be reminded on a continual basis.

MyFlightbook has options that can help.  Interestingly, MyFlightbook has no preconceived list of possible items to include in totals or in currency.  Instead, the system computes totals of all things that can be totaled and computes all currencies that could apply to your flying.  As a first stage of decluttering, the system then prunes away any total that is 0 and any currency that was never achieved.  But that can still leave a lot of "noise" values.

There are multiple options on the site that can further reduce clutter; most can be found in "Preferences" under the "Profile" tab.

Probably the easiest clutter to remove is expired currencies.  If you're an active pilot, you obviously want to know when your currency expires for any of the flying that you do on a regular basis.  But suppose that (like me) you once took a single lesson in a helicopter, in which you did 3 takeoffs/landings.  That was enough to make you current per 61.57(a), but you never pursued your rating nor do you intend to.  That expired currency is just clutter - remove it.

You can specify how long expired currency should show as follows:

And thus that meaningless expired currency will no longer crowd out your more meaningful ones.

Next on the list of clutter to remove is properties that can contribute to totals, but which aren't terribly meaningful.  By default, any property that can be counted (e.g., number of ILS approaches) or that is a time (e.g., safety pilot time) is included in totals.  But a good example of properties you might not care to track is maneuvers that you might have logged while training for a rating, but which you otherwise don't perform any more.
All of the properties you have ever used on a flight are in one of the two boxes above.  You can drag-and-drop from one to the other.  Properties on the left are "active" - ones that you use on a regular basis.  The ones on the right are inactive; by designating them as such you get two clutter-reducing benefits: 
  • These properties are not shown by default on the screen for entering new flights (but they are still available for you to use if the need arises)
  • Sums of these (such as the number of 180-degree power off accuracy landings or NDB approaches, in my example above) will not be included in your totals
One of the questions I am most frequently asked is how to log complex time.  The answer, of course, is that you don't: this is computed for you automatically, and displayed in totals.  There are actually a fair number of such totals that can show up in this manner: Turbine, Tailwheel, Complex, High Performance, and Retract (that isn't complex), and for each of these, there is total time, PIC time, and SIC time.  While any of these that are zero are pruned automatically, that's potentially 15 different items showing up in your totals!

You can turn these off under "Currency/Totals":

There's one more item that can reduce clutter in totals, and this starts to bleed over into reducing clutter in your overall logbook display.  MyFlightbook can record hobbs start/stop, engine start/stop, and flight start/stop automatically.  (You can also do tach time and block time, but these can't be detected by the mobile apps and are in the list of additional flight properties, whereas hobbs/flight/engine are "baked in" to the core flight).  

If a flight has both ends of hobbs, flight, or engine defined, and they are in the correct order (i.e., hobbs end is larger than hobbs start), then the elapsed hobbs/flight/engine time for that flight will accrue to a total elapsed hobbs/flight/engine time in your totals.

This is off by default (so is pre-de-cluttered?), but you can control it under flight entry:
This has three clutter-controlling aspects: 
  • It controls whether or not totals include total elapsed hobbs/flight/engine time;
  • It controls whether the "times and telemetry" section of the New Flight form is expanded by default; and
  • It controls whether hobbs/engine/flight times are displayed by default in your list of flights
There are two other options above - CFI time and SIC time.  These are two additional "baked in" attributes of a flight (since they are available in just about every paper logbook...ever), and they're fields that a large percentage of pilots will use, but which any individual pilot either uses frequently or never uses.  For this reason you can turn these off/on as well.  This impacts whether the CFI and SIC fields show for new flights, and whether or not columns for them are shown by default in the list of your flights.  It does not affect the display of any non-zero CFI or SIC totals.

This leads naturally to some clutter-reducing tips for the display of your flights.

You may have noticed that next to the count of your flights is a drop-arrow.  If you click that, you can see some options for controlling the display:

Showing in pages vs. all of your flights isn't about clutter as much as it is about scrolling and performance (both network and browser), but it can be a nice option if you don't want to go page-by-page through your logbook.

But the compact view and the option to show images in-line are both great ways to control clutter in your display.

The compact view simply collapses each flight to a single line, consisting of date/route/comments.  You can click to expand the flight to see more details.

Images are, by default, decluttered, in that you have to hover your mouse over a camera icon to view them.  But if you prefer to have them show without moving the mouse, you can turn on this option to see the images directly.

Finally, I'll leave you with a clutter-reducing tip for your aircraft.  If you look next to each aircraft in your aircraft list, you'll see a drop-arrow there.  Click it, and you can designate the aircraft as active or inactive:


(You can also designate an aircraft as active/inactive using the Android or iOS app; tap the aircraft and you'll see the option; don't forget to update the aircraft to save your change!)

Active aircraft show up in the list of aircraft available for new flights, and show up on the search form; inactive aircraft do not.  If you've flown a lot of aircraft over the years but are currently flying just a few, this can greatly simplify your life.

So whether or not you follow Kondo's advice in your life on the ground, I hope you can reduce the clutter in your logbook!

Sunday, December 23, 2018

Ratings progress - why can't I click?



Numerous times, I've been asked for the ability to click on an item in MyFlightbook's Ratings Progress so that you can see the flights that contributed towards the progress.

The reason I haven't done this is that it's really hard to do in a way that is meaningful. 

I already do it for experience requirements that match a specific flight (e.g., long cross-country, but even that could have potentially have multiple matches). 

But for most of the remaining items, it's either silly to implement, or there are reasons why it won't work the way you might hope.  For example:
  • Many of the requirements for a given rating are quite trivial.  E.g., "500 hours of total time", or “50 hours of solo time in airplanes”.  These can be viewed directly from your basic totals (which are already clickable), so adding it in ratings progress doesn't really add much value.
  • More difficult are the experience requirements that can be met via multiple different subsets of flights due to alternative criteria or allowed substitutions, so the “matching flights” won’t’ tell you anything.  For example, 61.159(a)(2) (ATP rating) requires 100 hours of night flight, but 61.159(b) allows each night takeoff/landing in excess of 20 to count towards one of those hours, up to a maximum of 25 hours.  That is to say, you can meet this requirement with only 75 hours of night flight but 45 night takeoffs/landings.  If I link to a search that shows only flights with night and you only have 75 hours of night flight, it will be hard to reconcile why this item shows as met.  Or, conversely, if you have more than 100 hours of night flight and more than 45 night takeoffs/landings, which ones are the ones that contributed and which ones were disallowed because you had hit the maximum 25 substituted hours?  It’s like money: asking which flights met the criteria can be like asking which dollars from your paycheck bought a given bag of potato chips.
  • Sometimes, though,  the query needs to be more precise than I could actually do as a search, such that even if I showed you all of the flights that contributed to a particular rating requirement you wouldn't be able to at-a-glance see how much each flight contributed.    A good example of this is things like night instruction.  Suppose a given flight is 3 hours long, of which you logged 2 hours of instruction and 0.8 hours of night flight.  That flight would contribute MIN(Dual, Night), or 0.8 hours of night flight towards the requirement.  But if you took all the flights with dual and night, the total of dual and the total of night would read more than you can count towards this; this is actually why this isn't done in the database - I get all of your flights and examine each one in turn doing computations that can get pretty arcane and specific because the rules can get pretty arcane and specific.
So it turns out that very few of the milestones actually would have interesting associated queries that you could get useful results from and which would actually save you any meaningful clicks/taps.

By the way, this is also why in your currency, you can click on custom currencies and due dates, but most of the regulatory ones like 61.57(a/b/c) are not clickable.  The custom currencies follow very regular rules, but the regulatory ones have two many different paths to completion.