[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why so many different ways to check valid attributes/values?

From: Gary E. Miller
Subject: Re: why so many different ways to check valid attributes/values?
Date: Sat, 2 Jul 2022 12:22:33 -0700

Yo Beta!

On Sat, 2 Jul 2022 11:20:57 +0200
Beta Tester <> wrote:

> i just wondering if it wouldn't be nicer for gpsd-client
> developer/users to have only one single way to check if attribute
> values are valid or not. at least in python,

We all wish for easier, the trick is how?

For floats, you can always just use isfinite(), but checking one
flag (ECEF_SET) is faster than checking sevearl ECEF values for

And you don't have to check any TPV value if you did not get a TPV
message.  So checking for TPV saves a lot of work.  Important on
a Pi0.

For integers and flags, the out of band *_SET is the only options.

> - if an attribute exists in a dictionary or not. you can handle in
> normal python style e.g., `value_or_default = dict.get(key,
> default=None)`.

Dictionaries in Python are very expensive.  So we don't set values
that have no value.

> - if the `PACKET_SET` flag is set to see if the report you got has
> any kind of valid data at all

Yup, do that 1st.  Save a lot of cycles.

> - if the attribute, you are interested in, is one, that has a
> `..._SET` flag that has to be checked, e.g., 'is_valid = ((gps.valie
> & ..._SET) == ..._SET)'.

Does not always have to be checked.  You don't need to check floats.
But once again a time win.

> - if a float value is a finite value or if it is "NAN" or another
> infinite extreme.

Nitpick.  In POSIX   +Inf and -Inf are NAN, but not in Python!  Then
there are signaling NANs, etc.  Which are also handled differenlyt in
POSIX and Pyton, so always use isfinite().

> that you have to check with `is_valid =
> math.isfinite(value)`.

Yup.  Don't complain to me, complain to POSIX and Python.

> - if `SKY` satellites `el`, `az`, `ss` values are `-999` to see if
> they are invalid.

Yup.  Having a bit for each sat would be a PITA, and -999 is clearly out
of range.  You should also be ragning checking those, so the test is free.

> did i forgot oter checks to list?


> why not just handling the a `dict` or `json` object like: all
> attribute values that exists in the container are valid 

a) those are python specific, which mean two incompatible APIs.

b) Python: dict and JSON are very, very slow.

In the tranmitted gpsd JSON, unknown values are simply ommited.

>- anything
> > else that is missing is not valid. so you simply

Ypu, that is how it works.

> can use in all cases
> the `dict` or `json` object's own `.get(key, default=None)` method to
> cover all different situation above in one way.

Simple, but very slow, and uses much more memory.
> at least under python that would be the most "natural" way to cover
> all checks in a well known way, without the need to study deeply docs
> and source code.

But that would be a new API, that needs new tests and new doc, and be
much slower.

But, since it is Python, you are free to do it however you like.  You
might notice that some of the gpsd clients, like gpscsv, do as you

> or give the gpsd-client developer/user a single method to hand, to do
> the all different checks in one - something like
> `gps.get_value_or_default(key, default=None)` or
> `dictwrapper.get_value_or_default(key, default=None)`.

Adding a new API, does not get us to a single method, just the opposite.
Extra doc, extra tests, extra confusion.

Feel free to do that for yourself if you wish, and your CPU can handle it.

> the situation now is, you have to figure out which attribute you are
> interested in has which set of diffeent checks you have to cover.
> this is very confusing und painful to collect all the informations
> you need.

Welcome to the wonderful world of GNSS!  You just decribe every
gpsd driver.

> i don't know if this suggestion above will apply to the
> C-implementation as well - if there is also the informations
> available as a dictionary or json object that is accessable like a
> dictionary with a nice way to get an key value or a default value,
> when the attribute does not exists.

Sadly, you assume the C code not as it exists.

Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703  Tel:+1 541 382 8588

            Veritas liberabit vos. -- Quid est veritas?
    "If you can't measure it, you can't improve it." - Lord Kelvin

Attachment: pgpaQjWO72Dsi.pgp
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]