root/watcher/trunk/reader.py

Revision 56 (checked in by cbc, 12 years ago)

Add a reader process to watcher.

Line 
1 import sys
2 import re
3 import time
4 import datetime
5
6 pattern = re.compile(r"^GPS Location:\s+(\S+)\s+\S\s+(\S+)"
7                      r"\s+\S\s+\S+\s+(\S+)\s+")
8 bad_coordinate = "69696969.000"
9 bad_freshness = "1e+308"
10 stale = 900.0  # position must not be older than this many seconds
11 timeout = datetime.timedelta(0,300)  # wait up to this many seconds fo log to be appended
12
13 glider = sys.argv[1]
14 log    = sys.argv[2]
15
16 handle = open(log)
17
18 content = []
19 timer = datetime.datetime.now()
20 while True:
21     line = handle.readline()
22     if line:
23         timer = datetime.datetime.now()
24         content.append(line)
25         match = pattern.search(line)
26         if match:
27             lat, lon, fresh = match.groups()
28             if lat == bad_coordinate:
29                 continue
30             if lon == bad_coordinate:
31                 continue
32             if fresh == bad_freshness:
33                 continue
34             if float(fresh) >= stale:
35                 print "\nStale GPS fix for %s: %.2f seconds old in %s." % (glider, float(fresh), log),
36                 sys.stdout.flush()
37                 continue
38             print "\nFresh GPS fix for %s: %.3f %.3f." % (glider, float(lat), float(lon)),
39             sys.stdout.flush()
40             break
41     else:
42         if datetime.datetime.now() - timer > timeout:
43             print "\nTimeout reading %s log %s." % (glider, log)
44             break
45         time.sleep(5)
46
47 handle.close()
Note: See TracBrowser for help on using the browser.