fratsloos / fr24_card

Lovelace card for showing Dump1090 data from FR24 in Home Assistant
44 stars 5 forks source link

Enhance the Empty filter for Distance to filter "Unknown" aka "NaN" values #14

Closed BrettEBowman closed 2 years ago

BrettEBowman commented 2 years ago

For some of the flights in my list, the location is apparently "Unknown" or "NaN" in HA terms. The fr24_card calculation for Distance can't calculate it since the location is unknown, so it carries over to the Distance value as "NaN" also.

I would like to NOT display those flights with an unknown distance. I tried using the `hide: empty:

fratsloos commented 2 years ago

@BrettEBowman Can you supply me with the JSON for when you have that result?

BrettEBowman commented 2 years ago

Here's a .json file as well as what the fr24 card displays. (Both from approximately the same time, so they should roughly match up.)

aircraft.zip

fratsloos commented 2 years ago

Thanks, @BrettEBowman. I've tested it with this JSON, and I don't see the NaN. This might be because of the client. What browser or app are you using when you get the NaN?

Can you also give me YAML of the card confirguration?

BrettEBowman commented 2 years ago

I'm using the latest Goolge Chrome on Windows 10 for the browser.

Here's the YAML for the card:

entity: sensor.msp_piaware_flights
columns:
  - flag
  - registration
  - flight
  - icon
  - altitude
  - speed
  - distance
hide:
  empty:
    - distance
popup: true
zone: zone.home
sort: distance

I did look at the .json and it looked like flights that were showing up that way did have lat and long values. So maybe the problem has something to do with the math to determine the distance. The values for my zone.home are latitude: 44.97865681506032, longitude: -93.05218862841296.

Another possible clue that I've noticed is that when I leave that page displayed and it gets updated, the flights often are no longer sorted by distance. When I just opened the page for the very first time today to get the YAML for this post, I noticed that the first time, all of the flights had distance values. But then when it refreshed, a couple had the "NaN". It makes me wonder if there might be a problem with variable reinitialization or something like that.

fratsloos commented 2 years ago

Thanks, that is useful info. I'm looking into it. It might have something to do with the coordinates of the zone. When I used your card config I had no issue. When I added an extra zone with your coordinates I did get a NaN.

BrettEBowman commented 2 years ago

FYI I have another HA server at my other house. And I've seen the NaNs there, too. It's zone info is: latitude: 35.62409358633958, longitude: -82.62928962707521.

fratsloos commented 2 years ago

As mentioned I found the NaN in my test environment when I used your configuration and the first zone you gave. With the second zone I didn't have it. But that might be because of the content of aircraft.json. Same as I didn't get it with my local data.

I used a different method to calculate the distance. This time based on the documentation of Google. With his method I don't see the NaN with your data and configuration.

Before: before

After: after

Are you able to test this branch before I merge it into the code? I didn't see an option to use anything other than master or a version in HACS. So if you want to test it you may have to download it. See the instructions on https://github.com/fratsloos/fr24_card/blob/master/readme/installation.md.

Just saw a typo on that page, will fix that with the next release :)

BrettEBowman commented 2 years ago

Sure, I can manually download and install to test. Should I use the develop branch or that specific bugfix branch?

fratsloos commented 2 years ago

You should use the bugfix branch connected to this issue.

BrettEBowman commented 2 years ago

It's possible that I didn't manually install properly... I copied the files from the dist folder onto my HA server in the folder where the fr24 files were. There weren't .gz versions in the downloaded dist folder, so I created those. I restarted the HA supervisor, opened my Flights dashboard, and did a forced Ctrl-F5 refresh.

At first, it seemed better, but then I started getting the NaNs again. I captured a couple of aircraft.json files and corresponding displays.

aircraft1.zip

BrettEBowman commented 2 years ago

I think I figured out what I did wrong in the installation. I didn't change the Resource mapping, so it still had references to the HACS package. When I redid it, then the page started working OK. And I'm not seeing the NaNs. So, I think the change fixed the problem.

fratsloos commented 2 years ago

Thanks for testing. The compressed files (.gz) are created by HACS. I'll check the new JSON files in the coming days. Just to be sure, were you testing from the first or second zone?

BrettEBowman commented 2 years ago

That testing was from my primary home zone which was the first one.

fratsloos commented 2 years ago

I think I figured out what I did wrong in the installation. I didn't change the Resource mapping, so it still had references to the HACS package. When I redid it, then the page started working OK. And I'm not seeing the NaNs. So, I think the change fixed the problem.

Great! :) Just to be sure I'll test with the new JSON files as well before I release the fix.

Don't forget to switch back to the HACS implementation after testing.

fratsloos commented 2 years ago

The fix is published in the latest release: v0.5.1.