Knio / pynmea2

Python library for parsing the NMEA 0183 protocol (GPS)
MIT License
635 stars 223 forks source link

Separate NMEASentence values collection #114

Open ptoews opened 4 years ago

ptoews commented 4 years ago

Started to resolve #107. Separated the value collection into two methods, one for named values (by fields) returning a dict and another one without names returning just a list. Also integrated them into __repr__. Here is how they work currently:

msg = pynmea2.parse("$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D")
msg.field_values()
Out[9]: 
{'timestamp': datetime.time(18, 43, 53, 70000),
 'lat': '1929.045',
 'lat_dir': 'S',
 'lon': '02410.506',
 'lon_dir': 'E',
 'gps_qual': 1,
 'num_sats': '04',
 'horizontal_dil': '2.6',
 'altitude': 100.0,
 'altitude_units': 'M',
 'geo_sep': '-33.9',
 'geo_sep_units': 'M',
 'age_gps_data': '',
 'ref_station_id': '0000'}
msg.unnamed_values()
Out[10]: []
repr(msg)
Out[11]: "<GGA(timestamp=datetime.time(18, 43, 53, 70000), lat='1929.045', lat_dir='S', lon='02410.506', lon_dir='E', gps_qual=1, num_sats='04', horizontal_dil='2.6', altitude=100.0, altitude_units='M', geo_sep='-33.9', geo_sep_units='M', age_gps_data='', ref_station_id='0000')>"

Some points to consider:

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-1.0%) to 97.106% when pulling 69d1a9cf7585c7dccf2b26278e1a53fce59699aa on ptoews:fields_extraction into 4527cf47d45624764727311327d7863d30a86766 on Knio:master.

xOneca commented 4 years ago

Could have been used keys() and values() (and items()?), like dicts do.

xOneca commented 4 years ago

My comment was on named_values() only. Also consider collections.namedtuple's _asdict().

ptoews commented 4 years ago

Are you referring to the names of the new methods? I agree there might be better alternatives. But it's not that simple: There are fixed fields per Sentence class, which are named in fields, but there might also be additional values in data without any name. So a single items() or asdict() would be misleading, since not all the values are named and therefore are not suitable for a dict, and otherwise not all information would be included in the extracted data container.

xOneca commented 4 years ago

Just give them a name like _extra (or something like that) and let it be the extra data as a list, or add each one as _extra1, etc. Or fieldN.

ptoews commented 4 years ago

Thanks for your suggestion, I think this is indeed a better solution.

ptoews commented 4 years ago

Unit tests are now done as well. Anything else to do?

howroyd commented 10 months ago

Unit tests are now done as well. Anything else to do?

Awesome work.

Would be good for the readme to show an example.

ptoews commented 7 months ago

Done, let me know if there is anything else