# HG changeset patch # User drewp@bigasterisk.com # Date 1555603946 25200 # Node ID 6304b03704918457d0c685d38d6f2618bf851cf1 # Parent 124c921ad52dd53fcc2fa4fd149f15522b33c266 environment graph service standardization Ignore-this: 3aeb86c03902af984a871c9c2d2dd7cd diff -r 124c921ad52d -r 6304b0370491 service/environment/Dockerfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/Dockerfile Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,17 @@ +FROM bang6:5000/base_x86 + +WORKDIR /opt + +COPY requirements.txt ./ +RUN pip install -r requirements.txt + +# upstream this +RUN apt-get install -y tzdata + +COPY twisted_sse_demo ./twisted_sse_demo +COPY *.py req* *.n3 *.html ./ + + +EXPOSE 9075 + +CMD [ "python", "environment.py" ] diff -r 124c921ad52d -r 6304b0370491 service/environment/docs.n3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/docs.n3 Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,3 @@ +@prefix rdfs: . + + rdfs:comment "facts related to the calendar" . \ No newline at end of file diff -r 124c921ad52d -r 6304b0370491 service/environment/environment.py --- a/service/environment/environment.py Mon Apr 15 00:17:04 2019 -0700 +++ b/service/environment/environment.py Thu Apr 18 09:12:26 2019 -0700 @@ -4,20 +4,28 @@ daytime/night, overall modes like 'maintenance mode', etc """ -import sys, datetime, cyclone.web -from twisted.internet import reactor, task +import sys, datetime, cyclone.web, logging +from docopt import docopt +from twisted.internet import reactor, task, defer from dateutil.tz import tzlocal from dateutil.relativedelta import relativedelta, FR from rdflib import Namespace, Literal -sys.path.append("/my/proj/homeauto/lib") +from greplin import scales +from greplin.scales.cyclonehandler import StatsHandler from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler from twilight import isWithinTwilight +from logsetup import log, enableTwistedLog from rdfdoc import Doc ROOM = Namespace("http://projects.bigasterisk.com/room/") DEV = Namespace("http://projects.bigasterisk.com/device/") +STATS = scales.collection('/root', + scales.PmfStat('update'), +) + +@STATS.update.time() def update(masterGraph): stmt = lambda s, p, o: masterGraph.patchObject(ROOM.environment, s, p, o) @@ -47,8 +55,17 @@ def main(): - from twisted.python import log as twlog - twlog.startLogging(sys.stderr) + arg = docopt(""" + Usage: environment.py [options] + + -v Verbose + """) + log.setLevel(logging.INFO) + if arg['-v']: + enableTwistedLog() + log.setLevel(logging.DEBUG) + defer.setDebugging(True) + masterGraph = PatchableGraph() class Application(cyclone.web.Application): @@ -62,6 +79,7 @@ (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}), (r'/doc', Doc), # to be shared + (r'/stats/(.*)', StatsHandler, {'serverName': 'environment'}), ] cyclone.web.Application.__init__(self, handlers, masterGraph=masterGraph) diff -r 124c921ad52d -r 6304b0370491 service/environment/index.html --- a/service/environment/index.html Mon Apr 15 00:17:04 2019 -0700 +++ b/service/environment/index.html Thu Apr 18 09:12:26 2019 -0700 @@ -1,22 +1,41 @@ - - + + + environment + + + + + - - + + -

env

-