diff --git a/library/experiments/power-degradation-distance.clj b/library/experiments/power-degradation-distance.clj index 5b257e7..a669154 100644 --- a/library/experiments/power-degradation-distance.clj +++ b/library/experiments/power-degradation-distance.clj @@ -60,13 +60,15 @@ (def transmitter (new-node - {:device "phone-1" - :location {:x 250 :y 10}} ; start at very top + {:name "transmitter" + :device "phone-1" + :location {:x 250 :y 50}} ; start at very top )) (def receiver (new-node - {:device "phone-1" - :location {:x 250 :y 11}} + {:name "receiver" + :device "phone-1" + :location {:x 250 :y 51}} )) ; start at distance 1 away from transmitter (def power-loss-time (atom ())) @@ -123,16 +125,23 @@ (get-battery-capacity receiver) ) ;(println (get-battery-capacity receiver)) - (swap! power-loss-time conj - (:power-received + ( let [power-received (:power-received (get-message-network-attrs (send-network-message "test" transmitter receiver {:time (get-current-time)}) - ))) - (node-viewer-update-nodes {:text "Test"}) - )) + ))] + (swap! power-loss-time conj + power-received ) + (node-viewer-update-nodes {:text + (format + "Distance:%f\nPower Received: %f\nBattery Capacity:%f" + (get-distance-between-nodes transmitter receiver) + power-received + (get-battery-capacity receiver) ) + }) + ))) (simulation-run) diff --git a/src/thor/lang.clj b/src/thor/lang.clj index 0a028a7..1152175 100644 --- a/src/thor/lang.clj +++ b/src/thor/lang.clj @@ -314,7 +314,7 @@ :or { time (get-current-time) text ""}}] - (thor.ui.node-viewer/add-nodes time {:text "" + (thor.ui.node-viewer/add-nodes time {:text text :nodes (deref-all @*nodelist*)}) diff --git a/src/thor/node.clj b/src/thor/node.clj index 7d864e1..202e5e9 100644 --- a/src/thor/node.clj +++ b/src/thor/node.clj @@ -19,7 +19,8 @@ (defrecord Node - [id + [id + name memory location ; x y coordinate in graph pos type speed @@ -33,9 +34,10 @@ ) (defn create-node "create a node based on given info" - [{:keys [id location memory-size device-attrs network-attrs ] :or {:device-attrs {} :network-attrs {}}} ] + [{:keys [id name location memory-size device-attrs network-attrs ] :or { :device-attrs {} :network-attrs {}}} ] (Node. id + name (create-memory memory-size) location 0 diff --git a/src/thor/ui/node_viewer.clj b/src/thor/ui/node_viewer.clj index f64a8c4..198a14c 100644 --- a/src/thor/ui/node_viewer.clj +++ b/src/thor/ui/node_viewer.clj @@ -1,6 +1,6 @@ (ns thor.ui.node-viewer - (:import [javax.swing JFrame JList JButton BoxLayout JPanel DefaultListModel BoxLayout ListSelectionModel JScrollPane ScrollPaneConstants ] + (:import [javax.swing JFrame JList JButton BoxLayout JPanel DefaultListModel BoxLayout ListSelectionModel JScrollPane JViewport JLabel ScrollPaneConstants ] [java.awt Dimension GridBagLayout BorderLayout] [javax.swing.event ListSelectionListener] @@ -10,7 +10,7 @@ (def frame (doto (JFrame. "Project Thor") (.setDefaultCloseOperation (JFrame/EXIT_ON_CLOSE)) - (.setSize (Dimension. 500 500)) + (.setSize (Dimension. 700 500)) )) (def radius 100) @@ -29,11 +29,20 @@ ) ) (def statesListScrollPane + (let [header + (doto + (JViewport. ) + (.setView + (JLabel. "Time")) + )] + (doto (JScrollPane. stateList ScrollPaneConstants/VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants/HORIZONTAL_SCROLLBAR_AS_NEEDED - )) + ) + (.setColumnHeader header) + ))) (defn add-states-to-list [model elements] (doseq [elem elements] @@ -70,8 +79,12 @@ (fill 64 187 128 100) ;(println loc) (ellipse (:x loc) (:y loc) radius radius) - (fill 0) - (text (format "(%d, %d)" (:x loc) (:y loc)) (:x loc) (:y loc)) + (fill 250 79 45) + (text (if (nil? (:name n)) + (format "Node %d" (:id n)) + (:name n) + ) (:x loc) (:y loc)) + ;(text (format "(%d, %d)" (:x loc) (:y loc)) (:x loc) (:y loc)) ;(text (format "Node %d" (:id n)) (:x loc) (:y loc)) ))