- Timestamp:
- May 4, 2020, 8:34:21 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 82eff76
- Parents:
- 97efbbf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gnuboat/deviceservice_impl/controllers/DeviceController.py
r97efbbf r9b8dd22 20 20 import rrdtool 21 21 import os 22 import datetime 22 23 23 24 import gnuboat.common.device.rrdschema as rrdschema 24 25 from gnuboat.common.webservice.HttpErrors import ( 25 GnuboatBadRequest, GnuboatUnauthorized,26 26 GnuboatNotFound, GnuboatInternalServerError 27 27 ) … … 33 33 result = rrdtool.lastupdate(rrdfile) 34 34 except Exception as e: 35 raise GnuboatInternalServerError(detail='Could not query rrd database. Error: {}'.format(repr(e))) 35 raise GnuboatInternalServerError( 36 detail='Could not query rrd database. Error: {}'.format(repr(e))) 36 37 if 'ds' not in result: 37 38 raise GnuboatNotFound(detail='No databset found') 39 if (datetime.datetime.now() - result['date']).total_seconds() > 10: 40 raise GnuboatNotFound(detail='Last entry is older than 10s') 38 41 return { 39 42 'speedThroughWater': result['ds']['speedthroughwater'], … … 49 52 def track_get(): 50 53 rrdfile = _rrdfile_get() 51 54 52 55 track = {} 53 56 for archive in rrdschema.archives: 54 result = _rrd_fetch(rrdfile, archive.resolution, '{}s'.format(archive.duration)) 57 result = _rrd_fetch(rrdfile, archive.resolution, 58 '{}s'.format(archive.duration)) 55 59 56 60 start, end, interval = result[0] … … 64 68 watertemperature = keys.index('watertemperature') 65 69 gpsfix = keys.index('gpsfix') 66 70 67 71 i = 0 68 72 for dataset in result[2]: … … 79 83 } 80 84 i += 1 81 85 82 86 return track 83 87 … … 111 115 def _rrd_fetch(rrdfile, interval, period): 112 116 try: 113 return rrdtool.fetch(rrdfile, 'AVERAGE', '--resolution', str(interval), '--start', '-{}'.format(period), '--align-start') 117 return rrdtool.fetch( 118 rrdfile, 'AVERAGE', '--resolution', str(interval), 119 '--start', '-{}'.format(period), '--align-start' 120 ) 114 121 except Exception as e: 115 raise GnuboatInternalServerError(detail='Could not fetch from rrd database. Error: {}'.format(repr(e))) 116 122 raise GnuboatInternalServerError( 123 detail=('Could not fetch from rrd database. ' 124 'Error: {}').format(repr(e))) 125 117 126 118 127 def gpsfix_to_enum(gpsfix): 119 128 if gpsfix == 2: 120 return "2D" ;129 return "2D" 121 130 elif gpsfix == 3: 122 return "3D" ;131 return "3D" 123 132 else: 124 return "-" ;133 return "-"
Note:
See TracChangeset
for help on using the changeset viewer.
