add main/start, edit main.dot

This commit is contained in:
anonymous 2024-11-03 22:18:49 +00:00
parent e8aae58303
commit 922da9c056
2 changed files with 97 additions and 30 deletions

View File

@ -1,15 +1,15 @@
graph {
bgcolor="linen"
bgcolor="white"
fan_one [shape=circle, style=filled, fillcolor=FAN_ONE,label="",color=FAN_ONE_GESTURE,penwidth=5]
fan_two [shape=circle, style=filled, fillcolor=FAN_TWO,label="",color=FAN_TWO_GESTURE,penwidth=5]
radio_one [shape=invtrapezium,style=filled,fillcolor=RADIO_ONE,label="",color=RADIO_ONE_GESTURE,penwidth=5]
lamp_one [shape=cylinder,style=filled,fillcolor=LAMP_ONE,label="",color=LAMP_ONE_GESTURE,penwidth=5]
lamp_two [shape=cylinder,style=filled,fillcolor=LAMP_TWO,label="",color=LAMP_TWO_GESTURE,penwidth=5]
printer_one [shape=box,style=filled,fillcolor=PRINTER_ONE,label="",color=PRINTER_ONE_GESTURE,penwidth=5]
printer_two [shape=box,style=filled,fillcolor=PRINTER_TWO,label="",color=PRINTER_TWO_GESTURE,penwidth=5]
fan_one [shape=circle, style=filled, fillcolor=FAN_ONE,label="",color=FAN_ONE_GESTURE]
fan_two [shape=circle, style=filled, fillcolor=FAN_TWO,label="",color=FAN_TWO_GESTURE]
radio_one [shape=invtrapezium,style=filled,fillcolor=RADIO_ONE,label="",color=RADIO_ONE_GESTURE]
lamp_one [shape=cylinder,style=filled,fillcolor=LAMP_ONE,label="",color=LAMP_ONE_GESTURE]
lamp_two [shape=cylinder,style=filled,fillcolor=LAMP_TWO,label="",color=LAMP_TWO_GESTURE]
printer_one [shape=box,style=filled,fillcolor=PRINTER_ONE,label="",color=PRINTER_ONE_GESTURE]
printer_two [shape=box,style=filled,fillcolor=PRINTER_TWO,label="",color=PRINTER_TWO_GESTURE]
fan_one -- fan_two [color=FAN_ONE_FAN_TWO]
fan_one -- fan_two [color=FAN_ONE_FAN_TWO,]
fan_one -- radio_one [color=FAN_ONE_RADIO_ONE]
fan_one -- lamp_one [color=FAN_ONE_LAMP_ONE]
fan_one -- lamp_two [color=FAN_ONE_LAMP_TWO]

View File

@ -2,7 +2,6 @@
(load-file "~/.emacs.d/elpa/dash-20240510.1327/dash.elc")
(load-file "~/.emacs.d/elpa/mqtt-mode-20180611.1735/mqtt-mode.elc")
(require 'dash)
(require 'mqtt-mode)
(toggle-debug-on-error)
@ -12,6 +11,7 @@
(defconst graphviz-graph-output-format "svg")
(defconst graphviz-graph-output-dir "graphs/")
(defconst graphviz-image-output-dir (concat graphviz-graph-output-format "s/"))
(defconst snapshot-text-output-dir "snapshots/")
(defconst working-directory "~/Applications/listeningdaemon/visualiser/")
(load-file (concat working-directory "secrets.el"))
@ -19,10 +19,11 @@
;; colors
;; (defconst on-color "black" "The default color for objects which are active")
(defconst off-color "invis" "The default color for objects which are not active")
(defvar gesture-color "black" "color to outline objects involved in a gesture")
(defvar colors '("red" "green" "blue" "magenta" "yellow" "orange" "purple" "cyan")
"colors for the nodes and edges to choose from")
;; (defvar colors '("orange" "plum"))
;; "colors for the nodes and edges to choose from")
;; (defvar gesture-color (elt colors (random (length colors))) "color to outline objects involved in a gesture")
(defvar on-color "black")
(defvar transform-color "black")
;;; nodes
;; default colors
@ -74,11 +75,62 @@
(setq snapshot 10000)
(defun clear-graph ()
"Reset the graph to a plain screen"
nil nil
(setq fan-one-color off-color)
(setq fan-two-color off-color)
(setq radio-one-color off-color)
(setq lamp-one-color off-color)
(setq lamp-two-color off-color)
(setq printer-one-color off-color)
(setq printer-two-color off-color)
(setq fan-one-gesture-color fan-one-color)
(setq fan-two-gesture-color fan-two-color)
(setq radio-one-gesture-color radio-one-color)
(setq lamp-one-gesture-color lamp-one-color)
(setq lamp-two-gesture-color lamp-two-color)
(setq printer-one-gesture-color printer-one-color)
(setq printer-two-gesture-color printer-two-color)
;;; edges
;; default colors
(setq fan-one-fan-two-color off-color)
(setq fan-one-radio-one-color off-color)
(setq fan-one-lamp-one-color off-color)
(setq fan-one-lamp-two-color off-color)
(setq fan-one-printer-one-color off-color)
(setq fan-one-printer-two-color off-color)
(setq fan-two-radio-one-color off-color)
(setq fan-two-lamp-one-color off-color)
(setq fan-two-lamp-two-color off-color)
(setq fan-two-printer-one-color off-color)
(setq fan-two-printer-two-color off-color)
(setq radio-one-lamp-one-color off-color)
(setq radio-one-lamp-two-color off-color)
(setq radio-one-printer-one-color off-color)
(setq radio-one-printer-two-color off-color)
(setq lamp-one-lamp-two-color off-color)
(setq lamp-one-printer-one-color off-color)
(setq lamp-one-printer-two-color off-color)
(setq lamp-two-printer-one-color off-color)
(setq lamp-two-printer-two-color off-color)
(setq printer-one-printer-two-color off-color)
(format-graph))
(defun turn-object-on (object)
"Turn an object on"
nil
nil
(setq on-color (elt colors (random (length colors))))
;; (setq on-color (elt colors (random (length colors))))
(cond ((equal object 'fan-one)
(setq fan-one-color on-color)
(format-graph))
@ -209,27 +261,42 @@ and ultimately turn into a .gif"
(forward-line 6)
(kill-region 0 (point) t)
(graph-write-file-quietly)
;; create a backup of the graph, for the .gif
(format-graph-image-numbered)
;; change main.png for displaying in the browser
(format-graph-image-main)
(setq snapshot (+ snapshot 1)))
(defun write-to-log ; (&optional topic payload &rest string)
(string-to-record)
"record changes in the log, for commentary on the gif"
nil
nil
;; (when (and topic payload)
;; (message "Topic: %s. Payload: %s" topic payload))
(switch-to-buffer "*Logfile*")
(insert (concat "frame: " snapshot ":"))
(newline)
(insert string-to-record)
(newline)
(lambda () "write a file quietly" nil
(let ((inhibit-message t))
(write-file
(concat working-directory snapshot-text-output-dir
"snapshot-" snapshot ".txt"))))
)
;; (illuminate-edges '("transform" "printer" "one" "fan" "two") "1")
(defun illuminate-edges (topic payload)
"Function to illuminate the edges of the graph"
nil
nil
(setq on-color (elt colors (random (length colors))))
(let ((payload (string-limit payload 1)))
(let ((from-object (string-join (list (cadr topic) (caddr topic)) "-"))
(to-object (string-join (list (cadddr topic) (car (last topic))) "-")))
(message "From: %s" from-object)
(message "To: %s" to-object)
(when (string-equal payload "1")
(set (intern (concat from-object "-" to-object "-color")) on-color)
(set (intern (concat to-object "-" from-object "-color")) on-color))
(set (intern (concat from-object "-" to-object "-color")) transform-color)
(set (intern (concat to-object "-" from-object "-color")) transform-color))
(when (string-equal payload "0")
(set (intern (concat from-object "-" to-object "-color")) off-color)
(set (intern (concat to-object "-" from-object "-color")) off-color))
@ -241,22 +308,21 @@ and ultimately turn into a .gif"
"Function to illuminate the outlines of nodes on the graph"
nil
nil
(setq on-color (elt colors (random (length colors))))
(let ((payload (string-limit payload 1)))
(let ((gesture-object (string-join (list (elt topic 2) (elt topic 3)) "-")))
(message "Gesturing towards: %s" gesture-object)
;; (write-to-log topic payload)
(if (string-equal payload "0")
(set (intern (concat gesture-object "-gesture-color")) off-color)
(set (intern (concat gesture-object "-gesture-color")) gesture-color))
(set (intern (concat gesture-object "-gesture-color")) off-color)
(set (intern (concat gesture-object "-color")) off-color)
(set (intern (concat gesture-object "-gesture-color")) on-color))
(format-graph))))
(defun illuminate-nodes (topic payload)
"Function to illuminate the nodes on the graph, a decision tree"
nil
nil
(setq on-color (elt colors (random (length colors))))
(let ((payload (string-limit payload 1)))
;;(message "Topic: %s. Payload %s." topic payload)
;; (write-to-log topic payload)
(cond ((and (member "fan" topic) (member "one" topic) (string-equal "1" payload))
(turn-object-on 'fan-one)
(message "Fan one turns on"))
@ -308,9 +374,10 @@ and ultimately turn into a .gif"
(let ((msg-car (car m))
(payload (cdr m)))
(let ((topic (string-split msg-car "/")))
;; (message "Topic: %s. Payload %s" topic payload)
(cond ((member "transform" topic)
(illuminate-edges topic (car payload)))
((and (member "main" topic) (member "start" topic))
(clear-graph))
((and (member "main" topic) (member "gesture" topic))
(illuminate-gesture topic (car payload)))
((member "main" topic)