def get(self): p = self.settings.poller g = StateGraph(ROOM.environment) g.add((SHUTTLEPRO['shuttle'], ROOM['angle'], Literal(p.currentShuttleAngle))) g.add((SHUTTLEPRO['dial'], ROOM['totalDialMovement'], Literal(p.totalDialMovement))) self.set_header('Content-type', 'application/x-trig') self.write(g.asTrig())
def graph(): host = socket.gethostname() g = StateGraph(ctx=DEV['dpms/%s' % host]) g.add((URIRef("http://bigasterisk.com/host/%s/monitor" % host), ROOM['powerStateMeasured'], ROOM[getMonitorState()])) response.set_header('Content-type', 'application/x-trig') return g.asTrig()
def get(self): self.set_header("Content-Type", "application/x-trig") g = StateGraph(ROOM['garageArduino']) self.settings.poller.assertIsCurrent() g.add((DEV['frontDoorMotion'], ROOM['state'], ROOM['motion'] if self.settings.poller.lastValues['motion'] else ROOM['noMotion'])) g.add((ROOM['house'], ROOM['usingPower'], Literal(self.settings.poller.lastWatts, datatype=ROOM["#watts"]))) self.write(g.asTrig())
def get(self): self.set_header("Content-type", "application/x-trig") g = StateGraph(ctx=DEV["xidle/%s" % host]) ms = xss.get_info().idle subj = URIRef("http://bigasterisk.com/host/%s/xidle" % host) g.add((subj, ROOM["idleTimeMs"], Literal(ms))) g.add((subj, ROOM["idleTimeMinutes"], Literal(ms / 1000 / 60))) self.write(g.asTrig())
def get(self): self.set_header("Content-Type", "application/x-trig") g = StateGraph(ROOM["bedroomArduino"]) self.settings.poller.assertIsCurrent() g.add( ( DEV["bedroomMotion"], ROOM["state"], ROOM["motion"] if self.settings.poller.lastValues["motion"] else ROOM["noMotion"], ) ) self.write(g.asTrig())
def getGraph(request): g = StateGraph(ROOM.busybox) g.add((ROOM.busybox, ROOM.localHour, Literal('x'))) for attr in ['slider1', 'slider2', 'slider3', 'slider4']: # needs: smoothing, exp curve correction g.add((ROOM['busybox/%s' % attr], ROOM.value, Literal(round(poller.last[attr] / 1021, 3)))) g.add((ROOM['busybox/motion'], ROOM.value, Literal(poller.last['motion']))) request.setHeader('Content-type', 'application/x-trig') return g.asTrig()
def get(self): g = StateGraph(ctx=DEV['frontDoorArduino']) board = self.settings.board g.add((DEV['frontDoorOpen'], ROOM['state'], ROOM['open'] if board.getDoor() == 'open' else ROOM['closed'])) g.add((DEV['frontYardLight'], ROOM['state'], ROOM['on'] if board.getYardLight() else ROOM['off'])) g.add((DEV['frontDoorLcd'], ROOM['text'], Literal(board.getLcd()))) g.add((DEV['frontDoorLcd'], ROOM['brightness'], Literal(board.getLcdBrightness()))) # not temperature yet because it's slow and should be cached from # the last poll self.set_header('Content-type', 'application/x-trig') self.write(g.asTrig())
def get(self): g = StateGraph(ctx=DEV['houseSensors']) frontDoorDefer = getPage("http://slash:9080/door", timeout=2) # head start? doorOpen = int((yield getPage("http://bang:9056/pin/d9", timeout=1))) g.add((DEV['theaterDoorOpen'], ROOM['state'], ROOM['open'] if doorOpen else ROOM['closed'])) for s in self.motionStatements( currentMotion=int((yield getPage("http://bang:9056/pin/d10", timeout=1)))): g.add(s) try: for s in (yield self.getBedroomStatements()): g.add(s) except ConnectError, e: g.add((ROOM['bedroomStatementFetch'], ROOM['error'], Literal("getBedroomStatements: %s" % e)))
def get(self): log.debug("start graph") g = StateGraph(URIRef("http://bigasterisk.com/map")) for user in [URIRef("http://bigasterisk.com/foaf.rdf#drewp"), URIRef("http://bigasterisk.com/kelsi/foaf.rdf#kelsi"), ]: log.debug("find points for %s", user) pt = list(mongo.find({'user':user}, sort=[TIME_SORT], limit=1)) if not pt: continue pt = pt[0] t = datetime.datetime.fromtimestamp( pt_sec(pt), tzutc()).astimezone(tzlocal()) g.add((user, MAP['lastSeen'], Literal(t))) ago = int(time.time() - pt_sec(pt)) g.add((user, MAP['lastSeenAgoSec'], Literal(ago))) g.add((user, MAP['lastSeenAgo'], Literal( "%s seconds" % ago if ago < 60 else ("%.1f minutes" % (ago / 60) if ago < 3600 else ("%.1f hours" % (ago / 3600)))))) log.debug("describeLocationFull") desc, targetUri, targetName, dist = describeLocationFull( config, pt['longitude'], pt['latitude'], pt.get('horizAccuracy', pt.get('accuracy', 0)), str(user)) g.add((user, MAP['lastNear'], targetUri)) g.add((targetUri, RDFS.label, Literal(targetName))) g.add((user, MAP['lastDesc'], Literal(desc))) g.add((user, MAP['distanceToHomeM'], Literal(metersFromHome( config, user, pt['longitude'], pt['latitude'])))) if ago < 60*15: g.add((user, MAP['recentlyNear'], targetUri)) log.debug("added %s", user) self.set_header("content-type", 'application/x-trig') ret = g.asTrig() log.debug("return graph") self.write(ret)
try: infos = serv.supervisor.getAllProcessInfo() except Exception, e: pass else: break else: raise e graph = StateGraph(ctx=CL['supervisors']) for p in infos: # this uri design is not very good yet. should just be # host->supinstance->processid processUri = URIRef("http://bigasterisk.com/magma/sup/%s/%s" % (addr, p['name'])) graph.add((processUri, RDF.type, URIRef("http://bigasterisk.com/ns/command/v1#Process"))) if p['name'].startswith("cmd_"): graph.add( (processUri, RDF.type, URIRef( "http://bigasterisk.com/ns/command/v1#CommandProcess") )) graph.add((processUri, RDFS.label, Literal(p['name']))) state = URIRef('http://supervisord.org/config#%s' % p['statename']) graph.add((processUri, CL.state, state)) graph.add((state, RDFS.label, Literal(p['statename']))) # return status and some log tail self.set_header('Content-Type', 'application/x-trig') self.write(graph.asTrig())
try: infos = serv.supervisor.getAllProcessInfo() except Exception, e: pass else: break else: raise e graph = StateGraph(ctx=CL['supervisors']) for p in infos: # this uri design is not very good yet. should just be # host->supinstance->processid processUri = URIRef("http://bigasterisk.com/magma/sup/%s/%s" % (addr, p['name'])) graph.add((processUri, RDF.type, URIRef("http://bigasterisk.com/ns/command/v1#Process"))) if p['name'].startswith("cmd_"): graph.add((processUri, RDF.type, URIRef("http://bigasterisk.com/ns/command/v1#CommandProcess"))) graph.add((processUri, RDFS.label, Literal(p['name']))) state = URIRef('http://supervisord.org/config#%s' % p['statename']) graph.add((processUri, CL.state, state)) graph.add((state, RDFS.label, Literal(p['statename']))) # return status and some log tail self.set_header('Content-Type', 'application/x-trig') self.write(graph.asTrig()) class Application(cyclone.web.Application): def __init__(self, args):
def get(self): g = StateGraph(ctx=DEV['wifi']) # someday i may also record specific AP and their strength, # for positioning. But many users just want to know that the # device is connected to some bigasterisk AP. aps = URIRef("http://bigasterisk.com/wifiAccessPoints") age = time.time() - self.settings.poller.lastPollTime if age > 10: raise ValueError("poll data is stale. age=%s" % age) for dev in self.settings.poller.lastAddrs: if not dev.get('connected'): continue uri = URIRef("http://bigasterisk.com/mac/%s" % dev['mac'].lower()) g.add((uri, ROOM['macAddress'], Literal(dev['mac'].lower()))) g.add((uri, ROOM['connected'], aps)) if 'clientHostname' in dev: g.add((uri, ROOM['wifiNetworkName'], Literal(dev['clientHostname']))) if 'name' in dev: g.add((uri, ROOM['deviceName'], Literal(dev['name']))) if 'signal' in dev: g.add((uri, ROOM['signalStrength'], Literal(dev['signal']))) try: conn = whenConnected(self.settings.mongo, dev['mac']) except ValueError: pass else: g.add((uri, ROOM['connectedAgo'], Literal(connectedAgoString(conn)))) g.add((uri, ROOM['connected'], Literal(conn))) self.set_header('Content-type', 'application/x-trig') self.write(g.asTrig())
def get(self): pruneExpired = bool(self.get_argument('pruneExpired', '')) g = StateGraph(ctx=DEV['dhcp']) now = datetime.datetime.now() for mac, lease in IscDhcpLeases('/var/lib/dhcp/dhcpd.leases' ).get_current().items(): if pruneExpired and lease.end < now: continue uri = URIRef("http://bigasterisk.com/dhcpLease/%s" % lease.ethernet) g.add((uri, RDF.type, ROOM['DhcpLease'])) g.add((uri, ROOM['leaseStartTime'], timeLiteral(lease.start))) g.add((uri, ROOM['leaseEndTime'], timeLiteral(lease.end))) ip = URIRef("http://bigasterisk.com/localNet/%s/" % lease.ip) g.add((uri, ROOM['assignedIp'], ip)) g.add((ip, RDFS.label, Literal(lease.ip))) mac = URIRef("http://bigasterisk.com/mac/%s" % lease.ethernet) g.add((uri, ROOM['ethernetAddress'], mac)) g.add((mac, ROOM['macAddress'], Literal(lease.ethernet))) if lease.hostname: g.add((mac, ROOM['dhcpHostname'], Literal(lease.hostname))) self.set_header('Content-Type', 'application/x-trig') self.write(g.asTrig())