Fixing a bug where we can have two events with different objects/classes, e.g., beaco...
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Aug 2019 01:08:08 +0000 (18:08 -0700)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Aug 2019 01:08:08 +0000 (18:08 -0700)
Extractor/ExtractorScript.py

index fc06799..6121052 100644 (file)
@@ -3,7 +3,9 @@ readyToReturn = 0
 ToReturn = ""
 eventList = []
 eventVarMap = {}
+eventVarCounterMap = {}
 capabilityMap = {}
+capabilityList = []
 app1Capabilities = []
 app2Capabilities = []
 app1Subscribe = False
@@ -86,10 +88,17 @@ def ExtractFunctions(F, appName):
                                Temp = GetToken(F)
                        if Temp == "\"":
                                Temp = GetToken(F)
-                       if Temp not in eventList:
+                       if capabilityMap[variable] not in capabilityList:
+                               # We do not repeat the same capability twice
+                               capability = capabilityMap[variable]
+                               capabilityList.append(capability)
                                eventList.append(Temp)
-                               eventVarMap[Temp] = variable
-
+                               if Temp in eventVarMap.keys():
+                                       listOfEvents = eventVarMap[Temp]
+                                       listOfEvents.append(variable)
+                               else:
+                                       eventVarMap[Temp] = [variable]
+                                       
                #Check and analyze capabilities for physical interaction
                AnalyzeCapabilities(Temp, appName, F)
 
@@ -153,6 +162,7 @@ def ExtractEvents(extractedEvents):
        global eventList
        global eventVarMap
        global capabilityMap
+       global eventVarCounterMap
        extractedEvents.write("while(true) {\n")
        extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventList) - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
@@ -228,9 +238,18 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "presence":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        #Write three events subsequently
-                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       if capability == "capability.presenceSensor":
+                               extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       elif capability == "capability.beacon":
+                               extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
                        if capability == "capability.presenceSensor":
                                event = open("eventSimulator/presencePresentEvent.groovy", "r")
@@ -247,11 +266,12 @@ def ExtractEvents(extractedEvents):
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/presencePresencePresentEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write("\t\t" + line)
-                       event.close()
+                       if capability == "capability.presenceSensor":
+                               extractedEvents.write("\t\t\t} else {\n")
+                               event = open("eventSimulator/presencePresencePresentEvent.groovy", "r")
+                               for line in event:
+                                       extractedEvents.write("\t\t" + line)
+                               event.close()
                        extractedEvents.write("\t\t\t}\n")
                elif eventList[i] == "doorState":
                        #Write two events subsequently
@@ -303,7 +323,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "carbonMonoxide":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")                      
@@ -334,7 +360,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "battery":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        if capability == "capability.smokeDetector":
                                event = open("eventSimulator/smokeDetectorBatteryEvent.groovy", "r")
                        elif capability == "capability.battery":
@@ -432,7 +464,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "switch":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -575,7 +613,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "contact":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
@@ -617,7 +661,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "level":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        if capability == "capability.musicPlayer":
                                event = open("eventSimulator/musicPlayerLevelEvent.groovy", "r")
                        elif capability == "capability.switchLevel":
@@ -652,7 +702,13 @@ def ExtractEvents(extractedEvents):
                elif eventList[i] == "temperature":
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
-                       capability = capabilityMap[variable]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        if capability == "capability.thermostat":
                                event = open("eventSimulator/temperatureEvent.groovy", "r")
                        elif capability == "capability.temperatureMeasurement":