def graticule(spacing, color, secondsBehindGMT, labelHeight): separation = self.xscale(spacing) - self.xscale(0) if separation <= 5 : # Enough space for line? return 0 print "Doing grating on the time axis ", spacing, "seconds, i.e. pixels: ", separation tl = minLocal - minLocal % spacing; while tl < maxLocal: t = tl + secondsBehindGMT; self.vertical(t, color, 0.8); # print "Notch at ", t if self.xscale(spacing) - self.xscale(0) > 10 : # Enough width for label? was 10 if tl < maxLocal - (spacing/10): # tl < maxLocal - spacing: ts = isodate.fullString(t) if spacing == 1 or spacing == 10 : lab = ts[17:19] elif spacing == 60 or spacing == 600 : lab = ts[14:16] elif spacing == 3600: lab = ts[11:13] else: lab = ts[8:10] self.opLine("<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale(t) + 2, (self.viewHeight * .1) - labelHeight, self.axisStyle + ("fill: %s;" % (color)), # was + "text-align:center;", str(int(lab)))); tl += spacing; if separation > 10 : # Enough width for label? return 2 return 1
def graticule(spacing, color, secondsBehindGMT, labelHeight): separation = self.xscale(spacing) - self.xscale(0) if separation <= 5: # Enough space for line? return 0 print "Doing grating on the time axis ", spacing, "seconds, i.e. pixels: ", separation tl = minLocal - minLocal % spacing while tl < maxLocal: t = tl + secondsBehindGMT self.vertical(t, color, 0.8) # print "Notch at ", t if self.xscale(spacing) - self.xscale( 0) > 10: # Enough width for label? was 10 if tl < maxLocal - (spacing / 10): # tl < maxLocal - spacing: ts = isodate.fullString(t) if spacing == 1 or spacing == 10: lab = ts[17:19] elif spacing == 60 or spacing == 600: lab = ts[14:16] elif spacing == 3600: lab = ts[11:13] else: lab = ts[8:10] self.opLine( "<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale(t) + 2, (self.viewHeight * .1) - labelHeight, self.axisStyle + ("fill: %s;" % (color)), # was + "text-align:center;", str(int(lab)))) tl += spacing if separation > 10: # Enough width for label? return 2 return 1
def timeArgument(s): """Allow a relative datetime like -1w3d2h3s""" units = { 's': 1, 'm': 60,'h': 3600, 'd': 86400, 'w': 604800 } if s[0] in '+-': # ([+-][0-9]+[smhdw])+ ) i = 1 val = 0; while i < len(s): j = i; while s[j:j+1] in '0123456789': j += 1; if s[j:j+1] in units.keys(): val += int(s[i:j]) * units[s[j]] i = j + 1; isonow= datetime.isoformat(datetime.now()) + 'Z'; now = isodate.parse(isonow); if s[0] == '-': val = - val; print "That must be ", isodate.fullString(now + val); return now + val; else: return isodate.parse(s);
def timeArgument(s): """Allow a relative datetime like -1w3d2h3s""" units = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400, 'w': 604800} if s[0] in '+-': # ([+-][0-9]+[smhdw])+ ) i = 1 val = 0 while i < len(s): j = i while s[j:j + 1] in '0123456789': j += 1 if s[j:j + 1] in units.keys(): val += int(s[i:j]) * units[s[j]] i = j + 1 isonow = datetime.isoformat(datetime.now()) + 'Z' now = isodate.parse(isonow) if s[0] == '-': val = -val print "That must be ", isodate.fullString(now + val) return now + val else: return isodate.parse(s)
def timeAxis(self, secondsBehindGMT): minLocal, maxLocal = self.minx - secondsBehindGMT , self.maxx - secondsBehindGMT print "Time axis raw: ", self.minx, ' -> ', self.maxx, ' i.e. ', self.maxx - self.minx print "Time axis range: ", isodate.fullString(self.minx), ' - ', isodate.fullString(self.maxx) print "Time axis (local time): ", isodate.fullString(minLocal), ' - ', isodate.fullString(maxLocal) duration = self.maxx - self.minx; # Seconds ym1, ym2 = gmtime(minLocal), gmtime(maxLocal) monthname = ["January", "February", "March", "April", "May", "June", "July", "August", "Spetember", "October", "November", "December"]; # @@ I18N labelHeight = 5 def graticule(spacing, color, secondsBehindGMT, labelHeight): separation = self.xscale(spacing) - self.xscale(0) if separation <= 5 : # Enough space for line? return 0 print "Doing grating on the time axis ", spacing, "seconds, i.e. pixels: ", separation tl = minLocal - minLocal % spacing; while tl < maxLocal: t = tl + secondsBehindGMT; self.vertical(t, color, 0.8); # print "Notch at ", t if self.xscale(spacing) - self.xscale(0) > 10 : # Enough width for label? was 10 if tl < maxLocal - (spacing/10): # tl < maxLocal - spacing: ts = isodate.fullString(t) if spacing == 1 or spacing == 10 : lab = ts[17:19] elif spacing == 60 or spacing == 600 : lab = ts[14:16] elif spacing == 3600: lab = ts[11:13] else: lab = ts[8:10] self.opLine("<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale(t) + 2, (self.viewHeight * .1) - labelHeight, self.axisStyle + ("fill: %s;" % (color)), # was + "text-align:center;", str(int(lab)))); tl += spacing; if separation > 10 : # Enough width for label? return 2 return 1 timeunits = [ 1, 10, 60, 600, 3600, 86400 ]; colours = [ '#eef', '#ddf', '#ccf' ]; col = 0; for u in range(len(timeunits)): spacing = timeunits[u]; res = graticule(spacing, colours[col], secondsBehindGMT, labelHeight); if res > 0: col += 1 if res == 2: # included label labelHeight += 12; if spacing == 1 or spacing == 60: col += 1 # Skip 10 or 600 if col >= len(colours): break; if duration > 86400: months = (ym2[0] - ym1[0]) * 12 + (ym2[1] - ym1[1]) if months > 0: print "Doing months on the axis." ym = (ym1[0], ym1[1], 1, 0, 0, 0, 0, 0, 0); for m in range(months+1): if ym[1] % 12 == 1: col = '#44f'; else: if ym[1] % 3 == 1: col = '#aaf' else: col = '#ddf'; self.vertical(mktime(ym), col); if self.xscale(86400 * 28) - self.xscale(0) > 50 : label = monthname[ym[1]-1] else: label = ym[1]; self.opLine("<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale( mktime(ym)) + 10, (self.viewHeight * .1) + 10, self.axisStyle +"fill: #77f;", # was + "text-align:center;", label)); if ym[1] ==1: self.opLine( "<text x='%d' y='%d' style='%s'>%s</text>" % ( self.xscale( mktime(ym)) + 10, (self.viewHeight * .9) + 25, self.axisStyle +"fill: #77f;", # was + "text-align:center;", str(ym[0]))); ym = (ym[0]+ym[1]/12, ym[1] % 12 + 1, 1, 0, 0, 0, 0, 0, 0);
def doCommand(serialDevice=None, outputURI=None, doTracks=1, doWaypoints=1, verbose=0): if os.name == 'nt': if not serialDevice: serialDevice = "com1" phys = Win32SerialLink(serialDevice) else: if not serialDevice: serialDevice = "/dev/ttyS0" # serialDevice = "/dev/cu.USA19H191P1.1" phys = UnixSerialLink(serialDevice) gps = Garmin(phys) print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \ (gps.prod_id, gps.prod_descs, gps.soft_ver) f = formula() # Empty store of RDF data base = uripath.base() record = f.newBlankNode() f.add(record, RDF.type, GPS.Record) if doWaypoints: # show waypoints if verbose: print "Getting waypoints" wpts = gps.getWaypoints() for w in wpts: if verbose: progress(`w`) wpt = symbol(uripath.join(base, w.ident)) f.add(record, GPS.waypoint, wpt) f.add(wpt, WGS.lat, obj=intern(degrees(w.slat))) f.add(wpt, WGS.long, obj=intern(degrees(w.slon))) if doTracks: # show track if verbose: print "Getting tracks" tracks = gps.getTracks() for t in tracks: track = f.newBlankNode() f.add(record, GPS.track, track) for p in t: if isinstance(p, TrackHdr): if verbose: progress(`p`) f.add(track, GPS.disp, intern(p.dspl)) f.add(track, GPS.color, intern(p.color)) f.add(track, GPS.trk_ident, intern(p.trk_ident)) else: if verbose: progress(`p`) point = f.newBlankNode() f.add(track, GPS.trackpoint, point) f.add(point, WGS.lat, obj=intern(degrees(p.slat))) f.add(point, WGS.long, obj=intern(degrees(p.slon))) # if verbose: progress(" time=", p.time) # progress('p.time='+`p.time`) # @@ if p.time == 0 or p.time == 0xffffffffL: if verbose: progress("time=%8x, ignoring" % p.time) else: f.add(point, WGS.time, obj=intern(isodate.fullString(TimeEpoch+p.time))) phys.f.close() # Should really be done by the del() below, but isn't del(phys) # close serial link (?) f = f.close() if verbose: progress("Beginning output. You can disconnect the GPS now.") s = f.n3String(base=base, flags="d") # Flag - no default prefix, preserve gps: prefix hint if outputURI != None: op = open(outputURI, "w") op.write(s) op.close() else: print s
def doCommand(serialDevice=None, outputURI=None, doTracks=1, doWaypoints=1, verbose=0): if os.name == 'nt': if not serialDevice: serialDevice = "com1" phys = Win32SerialLink(serialDevice) else: if not serialDevice: serialDevice = "/dev/ttyS0" # serialDevice = "/dev/cu.USA19H191P1.1" phys = UnixSerialLink(serialDevice) gps = Garmin(phys) print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \ (gps.prod_id, gps.prod_descs, gps.soft_ver) f = formula() # Empty store of RDF data base = uripath.base() record = f.newBlankNode() f.add(record, RDF.type, GPS.Record) if doWaypoints: # show waypoints if verbose: print "Getting waypoints" wpts = gps.getWaypoints() for w in wpts: if verbose: progress( ` w `) wpt = symbol(uripath.join(base, w.ident)) f.add(record, GPS.waypoint, wpt) f.add(wpt, WGS.lat, obj=intern(degrees(w.slat))) f.add(wpt, WGS.long, obj=intern(degrees(w.slon))) if doTracks: # show track if verbose: print "Getting tracks" tracks = gps.getTracks() for t in tracks: track = f.newBlankNode() f.add(record, GPS.track, track) for p in t: if isinstance(p, TrackHdr): if verbose: progress( ` p `) f.add(track, GPS.disp, intern(p.dspl)) f.add(track, GPS.color, intern(p.color)) f.add(track, GPS.trk_ident, intern(p.trk_ident)) else: if verbose: progress( ` p `) point = f.newBlankNode() f.add(track, GPS.trackpoint, point) f.add(point, WGS.lat, obj=intern(degrees(p.slat))) f.add(point, WGS.long, obj=intern(degrees(p.slon))) # if verbose: progress(" time=", p.time) # progress('p.time='+`p.time`) # @@ if p.time == 0 or p.time == 0xffffffffL: if verbose: progress("time=%8x, ignoring" % p.time) else: f.add(point, WGS.time, obj=intern(isodate.fullString(TimeEpoch + p.time))) phys.f.close() # Should really be done by the del() below, but isn't del (phys) # close serial link (?) f = f.close() if verbose: progress("Beginning output. You can disconnect the GPS now.") s = f.n3String( base=base, flags="d") # Flag - no default prefix, preserve gps: prefix hint if outputURI != None: op = open(outputURI, "w") op.write(s) op.close() else: print s
def timeAxis(self, secondsBehindGMT): minLocal, maxLocal = self.minx - secondsBehindGMT, self.maxx - secondsBehindGMT print "Time axis raw: ", self.minx, ' -> ', self.maxx, ' i.e. ', self.maxx - self.minx print "Time axis range: ", isodate.fullString( self.minx), ' - ', isodate.fullString(self.maxx) print "Time axis (local time): ", isodate.fullString( minLocal), ' - ', isodate.fullString(maxLocal) duration = self.maxx - self.minx # Seconds ym1, ym2 = gmtime(minLocal), gmtime(maxLocal) monthname = [ "January", "February", "March", "April", "May", "June", "July", "August", "Spetember", "October", "November", "December" ] # @@ I18N labelHeight = 5 def graticule(spacing, color, secondsBehindGMT, labelHeight): separation = self.xscale(spacing) - self.xscale(0) if separation <= 5: # Enough space for line? return 0 print "Doing grating on the time axis ", spacing, "seconds, i.e. pixels: ", separation tl = minLocal - minLocal % spacing while tl < maxLocal: t = tl + secondsBehindGMT self.vertical(t, color, 0.8) # print "Notch at ", t if self.xscale(spacing) - self.xscale( 0) > 10: # Enough width for label? was 10 if tl < maxLocal - (spacing / 10): # tl < maxLocal - spacing: ts = isodate.fullString(t) if spacing == 1 or spacing == 10: lab = ts[17:19] elif spacing == 60 or spacing == 600: lab = ts[14:16] elif spacing == 3600: lab = ts[11:13] else: lab = ts[8:10] self.opLine( "<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale(t) + 2, (self.viewHeight * .1) - labelHeight, self.axisStyle + ("fill: %s;" % (color)), # was + "text-align:center;", str(int(lab)))) tl += spacing if separation > 10: # Enough width for label? return 2 return 1 timeunits = [1, 10, 60, 600, 3600, 86400] colours = ['#eef', '#ddf', '#ccf'] col = 0 for u in range(len(timeunits)): spacing = timeunits[u] res = graticule(spacing, colours[col], secondsBehindGMT, labelHeight) if res > 0: col += 1 if res == 2: # included label labelHeight += 12 if spacing == 1 or spacing == 60: col += 1 # Skip 10 or 600 if col >= len(colours): break if duration > 86400: months = (ym2[0] - ym1[0]) * 12 + (ym2[1] - ym1[1]) if months > 0: print "Doing months on the axis." ym = (ym1[0], ym1[1], 1, 0, 0, 0, 0, 0, 0) for m in range(months + 1): if ym[1] % 12 == 1: col = '#44f' else: if ym[1] % 3 == 1: col = '#aaf' else: col = '#ddf' self.vertical(mktime(ym), col) if self.xscale(86400 * 28) - self.xscale(0) > 50: label = monthname[ym[1] - 1] else: label = ym[1] self.opLine( "<text x='%d' y='%d' style='%s'>%s</text>\n" % ( self.xscale(mktime(ym)) + 10, (self.viewHeight * .1) + 10, self.axisStyle + "fill: #77f;", # was + "text-align:center;", label)) if ym[1] == 1: self.opLine( "<text x='%d' y='%d' style='%s'>%s</text>" % ( self.xscale(mktime(ym)) + 10, (self.viewHeight * .9) + 25, self.axisStyle + "fill: #77f;", # was + "text-align:center;", str(ym[0]))) ym = (ym[0] + ym[1] / 12, ym[1] % 12 + 1, 1, 0, 0, 0, 0, 0, 0)