# HG changeset patch # User drewp # Date 1555840896 25200 # Node ID b686b989cf61b08087bd777aea3a03e00a6a653c # Parent f97e060d860c43a1ebf908f9c52fb253a5e621f4 rm old pi kiosk thing that displayed calendars and stuff. maybe a thermostat knob. py server; knockout web page. Ignore-this: 30d76ed408ccc9bfd2acefdd351fe8f9 darcs-hash:f834c3bfabf6513abac14742b3cbfb86faaec2bf diff -r f97e060d860c -r b686b989cf61 service/wallscreen/gui.js --- a/service/wallscreen/gui.js Sun Apr 21 02:57:17 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -var reloadData; -$(function () { - - setTimeout(function () { - window.resizeTo(702,480); - }, 10000); - - var model = { - requestedF: ko.observable(), - tasks: ko.observableArray([]), - events: ko.observableArray([]), - isToday: function (ev) { - var today = moment().format("YYYY-MM-DD"); - return ev.date == today; - }, - mapPersonData: ko.observable(), - }; - reloadData = function() { - $.getJSON("content", function (data) { - model.tasks(data.tasks); - model.events(data.events); - }); - } - setInterval(reloadData, 30*60*1000); - reloadData(); - - reloadMap = function () { - $.getJSON("content/map", function (data) { - var personData = []; - data.pts.forEach(function (pt) { - // this is in another config but not yet in the graph - var initial = pt.who.split("#")[1].substr(0, 1).toUpperCase(); - pt.initial = initial; - pt.topFrac = initial == 'K' ? 0 : .5; - personData.push(pt); - }); - model.mapPersonData(personData); - }); - }; - setInterval(reloadMap, 2*60*1000); - reloadMap(); - - function onMessage(d) { - if (d.tempF) { - model.requestedF(d.tempF); - } - } - reconnectingWebSocket("ws://bang.bigasterisk.com:9102/live", onMessage); - - ko.applyBindings(model); - - if (navigator.userAgent == "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/18.0 Firefox/18.0") { - $(".rot").removeClass("rot"); - } - - function updateClock() { - var now = moment(); - var s = (new Date()).toLocaleTimeString(); - $("#clock").html( - "
"+now.format("dddd")+"
"+ - "
"+now.format("MMM Do")+"
"+ - "
"+now.format("HH:mm")+"
" - ) - } - setInterval(updateClock, 20000) - updateClock(); -}); diff -r f97e060d860c -r b686b989cf61 service/wallscreen/index.html --- a/service/wallscreen/index.html Sun Apr 21 02:57:17 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,202 +0,0 @@ - - - - - wallscreen - - - - - -
-
..:..
- -
-

Todo list:

-
    -
  • - -
  • -
-
- -
-

Calendar:

-
    -
  • -

    - - -

    -
      - -
    • - - -
    • - -
    -
  • -
-
-
- - - - -
-
- Thermostat at . Use knob to adjust. -
-
- -
- - - - - - - - - diff -r f97e060d860c -r b686b989cf61 service/wallscreen/pydeps --- a/service/wallscreen/pydeps Sun Apr 21 02:57:17 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -Automat==0.7.0 -cffi==1.11.5 -cyclone==1.0rc15 -enum34==1.1.6 -html5lib==1.0b3 -http-parser==0.8.3 -hyperlink==18.0.0 -idna==2.7 -incremental==17.5.0 -ipaddress==1.0.22 -isodate==0.4.9 -pycparser==2.18 -PyHamcrest==1.9.0 -pyOpenSSL==18.0.0 -pyparsing==1.5.7 -python-dateutil==2.1 -rdflib==4.0.1 -requests==2.9.1 -restkit==4.2.2 -SPARQLWrapper==1.5.2 -treq==15.1.0 -Twisted==18.7.0 - diff -r f97e060d860c -r b686b989cf61 service/wallscreen/wallscreen.py --- a/service/wallscreen/wallscreen.py Sun Apr 21 02:57:17 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -""" -for raspberry pi screen. - B2G_HOMESCREEN=http://10.1.0.1:9102 b2g/b2g --screen=700x480 -and then fix the window with this: - echo "window.resizeTo(702,480)" | nc localhost 9999 -""" -import json, sys, time -from dateutil.parser import parse -from twisted.internet import reactor, task -from twisted.internet.defer import inlineCallbacks -import cyclone.web, cyclone.httpclient, cyclone.websocket -from rdflib import Graph, ConjunctiveGraph, URIRef, Namespace, Literal, RDF - -sys.path.append("../../lib") -from logsetup import log -from cycloneerr import PrettyErrorHandler - -sys.path.append("../reasoning") -from rdflibtrig import addTrig - -CV = Namespace("http://bigasterisk.com/checkvist/v1#") -EV = Namespace("http://bigasterisk.com/event#") -MAP = Namespace("http://bigasterisk.com/map#") - -class Content(PrettyErrorHandler, cyclone.web.RequestHandler): - def get(self): - out = [] - if 1: - g = Graph() - g.parse("http://bang:9103/graph", format="n3") - - tasks = [] # (pos, task) - for t in g.subjects(RDF.type, CV.OpenTask): - if (None, CV.child, t) in g: - continue - tasks.append((g.value(t, CV.position), t)) - tasks.sort() - - def appendTree(t, depth): - out.append(dict( - uri=t, - depth=depth, - mark=g.value(t, CV.mark), - content=g.value(t, CV.content), - )) - for sub in g.objects(t, CV.child): - if (sub, RDF.type, CV.OpenTask) not in g: - continue - appendTree(sub, depth+1) - - for pos, t in tasks[:10]: - appendTree(t, depth=0) - - events = [] # [{'date':'yyyy-mm-dd', 'dayEvents':[], 'timeEvents':[]}] - g = Graph() - g.parse("http://bang:9105/events?days=3", format='n3') - byDay = {} - for ev in g.subjects(RDF.type, EV.Event): - start = g.value(ev, EV['start']) - s = parse(start) - d = s.date().isoformat() - byDay.setdefault(d, {'dayEvents':[], - 'timeEvents':[]})[ - 'timeEvents' if 'T' in start else 'dayEvents'].append({ - 'title' : g.value(ev, EV['title']), - 'start' : start, - 'date' : s.date().isoformat(), - 'time' : s.time().isoformat()[:-3], - }) - for k,v in sorted(byDay.items(), key=lambda (k,v): k): - d = {'date':k, 'weekdayName':parse(k).strftime("%A")} - d.update(v) - d['dayEvents'].sort(key=lambda ev: ev['title']) - d['timeEvents'].sort(key=lambda ev: ev['start']) - events.append(d) - - self.write(json.dumps({'tasks':out, 'events' : events})) - -class ContentMap(PrettyErrorHandler, cyclone.web.RequestHandler): - def get(self): - g = ConjunctiveGraph() - addTrig(g, "http://bang:9099/graph") - maxMeters = 65000 - pts = [] - print "loaded", len(g) - for s,p,o in g.triples((None, MAP['distanceToHomeM'], None)): - pts.append(dict(who=s, - frac=float(o) / maxMeters, - distanceToHomeM=o, - displayMilesDistance="%.1f miles" % - (float(o) * 0.000621371))) - self.write(json.dumps({'pts': pts})) - -@inlineCallbacks -def pushThermostat(): - f = json.loads((yield cyclone.httpclient.fetch("http://bang:10001/requestedTemperature")).body) - [c.sendMessage(f) for c in liveClients] - -class RefreshTemperature(PrettyErrorHandler, cyclone.web.RequestHandler): - def post(self): - return pushThermostat() - -liveClients = set() - -class Live(cyclone.websocket.WebSocketHandler): - def connectionMade(self, *args, **kwargs): - log.info("websocket opened") - liveClients.add(self) - - def connectionLost(self, reason): - log.info("websocket closed") - liveClients.remove(self) - - def messageReceived(self, message): - log.info("got message %s" % message) - self.sendMessage(message) - -if __name__ == '__main__': - from twisted.python import log as twlog - #twlog.startLogging(sys.stdout) - - task.LoopingCall(pushThermostat).start(1) - - port = 9102 - reactor.listenTCP(port, cyclone.web.Application(handlers=[ - (r'/content', Content), - (r'/content/map', ContentMap), - (r'/live', Live), - (r'/refreshTemperature', RefreshTemperature), - (r'/(.*)', cyclone.web.StaticFileHandler, - {"path" : ".", # security hole- serves this dir too - "default_filename" : "index.html"}), - ])) - log.info("serving on %s" % port) - reactor.run() diff -r f97e060d860c -r b686b989cf61 service/wallscreen/websocket.js --- a/service/wallscreen/websocket.js Sun Apr 21 02:57:17 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -// from the light9/rdfdb one - -function reconnectingWebSocket(url, onMessage) { - var pong = 0; - function connect() { - var ws = new WebSocket(url); - - ws.onopen = function() { $("#status").text(""); }; - ws.onerror = function(e) { $("#status").text("error: "+e); }; - ws.onclose = function() { - pong = 1 - pong; - $("#status").text("disconnected (retrying "+(pong ? "😼":"😺")+")"); - setTimeout(connect, 2000); - }; - ws.onmessage = function (evt) { - onMessage(JSON.parse(evt.data)); - }; - } - connect(); -}