Browse Source

Fixed plotter such that is able to handle FSA as well (I think)

Yentl Van Tendeloo 6 years ago
parent
commit
e78cc39605
2 changed files with 23 additions and 5 deletions
  1. 16 1
      interface/simple_plot/main.py
  2. 7 4
      models/fsa_simulate.alc

+ 16 - 1
interface/simple_plot/main.py

@@ -26,6 +26,7 @@ maps = {}
 if time <= old_time:
     # Overwrites current values, so flush
     d = {}
+    plt.legend()
 else:
     for key in d:
         maps[key], = plt.plot(d[key][0], d[key][1])
@@ -48,7 +49,12 @@ while 1:
         continue
     time, key, value = l.split(" ")
     time = float(time)
-    value = float(value)
+    try:
+        value = float(value)
+    except:
+        # Value is not a number, so we work with discrete states, just ignore!
+        pass
+        value = value.strip()
 
     if key not in maps:
         maps[key], = plt.plot([], [])
@@ -60,6 +66,15 @@ while 1:
 
     d[key][0].append(time)
     d[key][1].append(value)
+
+    if isinstance(value, str) and value not in d[key][1][:-1]:
+        for key in d:
+            prev_color = maps[key].get_color()
+            maps[key].remove()
+            maps[key], = plt.plot(d[key][0], d[key][1], c=prev_color)
+            maps[key].set_label(key)
+        plt.legend()
+
     maps[key].set_xdata(d[key][0])
     maps[key].set_ydata(d[key][1])
     plt.gca().set_xlim([min(d[key][0]), max(d[key][0])])

+ 7 - 4
models/fsa_simulate.alc

@@ -36,18 +36,21 @@ Boolean function main(model : Element):
 			if (input_value == "__EXIT__"):
 				break!
 
+			log(cast_value(time() - start_time) + " input " + input_value)
+			output(cast_value(time() - start_time) + " input " + input_value)
+
 			transitions = allOutgoingAssociationInstances(model, current_state, "FullRuntime/Transition")
 			while (set_len(transitions) > 0):
 				transition = set_pop(transitions)
 				if (cast_string(read_attribute(model, transition, "trigger")) == input_value):
 					if (element_neq(read_attribute(model, transition, "raise"), read_root())):
-						log(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
-						output(cast_value(time() - start_time) + " ! " + cast_string(read_attribute(model, transition, "raise")))
+						log(cast_value(time() - start_time) + " output " + cast_string(read_attribute(model, transition, "raise")))
+						output(cast_value(time() - start_time) + " output " + cast_string(read_attribute(model, transition, "raise")))
 					current_state = readAssociationDestination(model, transition)
 					break!
 
-		log(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
-		output(cast_value(time() - start_time) + " : " + cast_string(read_attribute(model, current_state, "name")))
+		log(cast_value(time() - start_time) + " state " + cast_string(read_attribute(model, current_state, "name")))
+		output(cast_value(time() - start_time) + " state " + cast_string(read_attribute(model, current_state, "name")))
 		sleep(0.2)
 
 	log("CLOSE")