Hardcoding options for enum.
authorrtrimana <rtrimana@uci.edu>
Wed, 24 Jul 2019 18:46:35 +0000 (11:46 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 24 Jul 2019 18:46:35 +0000 (11:46 -0700)
Extractor/Extractor.groovy
Extractor/ExtractorScript.py

index 65dcafa..e3cb88a 100644 (file)
@@ -828,8 +828,11 @@ def input(LinkedHashMap metaData) {
                        break
                case "enum":
                        def randomVariable = Math.abs(new Random().nextInt() % 2)
-                       def modes = ["Yes", "No"]
-                       def userInput = modes[randomVariable]
+                       //def modes = ["Yes", "No"]
+                       //def userInput = modes[randomVariable]
+                       // TODO: We 
+                       def modes = metaData['options']
+                       def userInput = modes[0]
        
                        if (enumVariables == 0) {
                                enum0 = metaData['name']
index 4e51bec..50bc843 100644 (file)
@@ -41,10 +41,8 @@ def ExtractFunctions(F, appName):
        while (Temp != "EOF"):
                if (Temp == "def" or Temp == "private"):
                        Temp = GetToken(F)
-                       if (Temp == "def" or Temp == "private"):
-                               Temp = GetToken(F)
                        NameofFunc = Temp
-                       if (GetToken(F) == "("): #We have a function to create object for
+                       if (GetToken(F) != "="): #We have a function to create object for
                                if (appName == "App1"):
                                        extractedFunctionsApp1.write("//Global Object for functions in subscribe method!\n")    
                                        extractedFunctionsApp1.write("def %s = this.&" % NameofFunc)
@@ -53,17 +51,13 @@ def ExtractFunctions(F, appName):
                                        extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n")    
                                        extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
                                        extractedFunctionsApp2.write("%s\n" % NameofFunc)
-
+               
                #Check subscribed events
                if (Temp == "subscribe"):
-                       counter = 0
-                       while (counter < 5 and Temp != "\""):
+                       while (Temp != "\"" and Temp != "app" and Temp != "location"):
+                               Temp = GetToken(F)
+                       if Temp == "\"":
                                Temp = GetToken(F)
-                               counter = counter + 1
-                       Temp = GetToken(F)
-                       #If counter >= 5 that means it is not found, so it must be appTouch
-                       if (counter >= 5):
-                               Temp = "Touched"
                        if Temp not in eventMap:
                                eventMap.append(Temp)
 
@@ -71,11 +65,12 @@ def ExtractFunctions(F, appName):
                AnalyzeCapabilities(Temp, appName)
 
                Temp = GetToken(F)
-
+       
        #Warn if there is a potential for physical interaction
        AnalyzePhysicalInteraction(app1Capabilities, app2Capabilities)
        AnalyzePhysicalInteraction(app2Capabilities, app1Capabilities)
 
+               
 
 def AnalyzeCapabilities(Temp, appName):
                        #Illuminance related
@@ -116,149 +111,11 @@ def AnalyzePhysicalInteraction(app1Capab, app2Capab):
 
 def ExtractEvents(extractedEvents):
        global eventMap
-       extractedEvents.write("Random random = new Random(42)\n")
-       extractedEvents.write("counter = 1000\n")
-       extractedEvents.write("while(counter > 0) {\n")
-       extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1))
-       extractedEvents.write("\tswitch(eventNumber) {\n")
-       eventCounter = 0;
-       for i in range(len(eventMap)):
-               extractedEvents.write("\t\tcase %d:\n" % eventCounter)
-               if eventMap[i] == "lock":
-                       event = open("eventSimulator/lockEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "unlock":
-                       event = open("eventSimulator/unlockEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "contact.open":
-                       event = open("eventSimulator/contactOpenEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "contact.closed":
-                       event = open("eventSimulator/contactClosedEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "switch.on":
-                       event = open("eventSimulator/switchOnEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "switch.off":
-                       event = open("eventSimulator/switchOffEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "nfcTouch":
-                       event = open("eventSimulator/nfcTouchEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "Touched":
-                       event = open("eventSimulator/appTouchEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "button":
-                       #Write two events subsequently
-                       event = open("eventSimulator/buttonPushedEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
-                       event = open("eventSimulator/buttonHeldEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "presence":
-                       #Write two events subsequently
-                       event = open("eventSimulator/presencePresentEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
-                       event = open("eventSimulator/presenceLeftEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               elif eventMap[i] == "doorState":
-                       #Write two events subsequently
-                       event = open("eventSimulator/doorOpenEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
-                       event = open("eventSimulator/doorClosedEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
-               eventCounter = eventCounter + 1
-
-               ###TODO: Add more events later
-               extractedEvents.write("\n\t\t\tbreak\n")
-       extractedEvents.write("\t}\n")
-       extractedEvents.write("\tcounter--\n")
-       extractedEvents.write("}\n")
-
-
-def AnalyzeCapabilities(Temp, appName):
-                       #Illuminance related
-       if (Temp == "capability.switch" or
-                       Temp == "capability.switchLevel" or
-                       Temp == "capability.illuminanceMeasurement" or
-                       #Motion related
-                       Temp == "capability.motionSensor" or
-                       #Water related
-                       Temp == "capability.valve" or
-                       Temp == "capability.waterSensor" or
-                       #Sound related
-                       Temp == "capability.musicPlayer" or
-                       Temp == "capability.alarm" or
-                       Temp == "capability.speechSynthesis" or
-                       Temp == "capability.soundSensor"):
-               if (appName == "App1"):
-                       app1Capabilities.append(Temp)
-               else:
-                       app2Capabilities.append(Temp)
-                       
-def AnalyzePhysicalInteraction(app1Capab, app2Capab):
-       #Light
-       if ("capability.illuminanceMeasurement" in app1Capab) and ("capability.switch" in app2Capab or 
-                       "capability.switchLevel" in app2Capab):
-               print ("\nWARNING: Potential PHYSICAL CONFLICT (light) detected between App1 and App2!\n")
-       #Motion
-       if ("capability.motionSensor" in app1Capab):
-               print ("\nWARNING: Potential PHYSICAL CONFLICT (motion) detected between App1 and App2!\n")             
-       #Water
-       if ("capability.waterSensor" in app1Capab) and ("capability.valve" in app2Capab or 
-                       "capability.switch" in app2Capab):
-               print ("\nWARNING: Potential PHYSICAL CONFLICT (water) detected between App1 and App2!\n")
-       #Sound
-       if ("capability.soundSensor" in app1Capab) and ("capability.musicPlayer" in app2Capab or 
-                       "capability.alarm" in app2Capab or "capability.speechSynthesis" in app2Capab):
-               print ("\nWARNING: Potential PHYSICAL CONFLICT (sound) detected between App1 and App2!\n")
-
-def ExtractEvents(extractedEvents):
-       global eventMap
-       extractedEvents.write("Random random = new Random(42)\n")
-       extractedEvents.write("counter = 1000\n")
-       extractedEvents.write("while(counter > 0) {\n")
-       extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1))
+       extractedEvents.write("while(true) {\n")
+       extractedEvents.write("\tdef eventNumber = Verify.getInt(0,%d)\n" % (len(eventMap) - 1))
        extractedEvents.write("\tswitch(eventNumber) {\n")
-       eventCounter = 0;
        for i in range(len(eventMap)):
-               extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+               extractedEvents.write("\t\tcase %d:\n" % i)
                if eventMap[i] == "lock":
                        event = open("eventSimulator/lockEvent.groovy", "r")
                        for line in event:
@@ -284,103 +141,105 @@ def ExtractEvents(extractedEvents):
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-               elif eventMap[i] == "Touched":
+               elif eventMap[i] == "app": #Case for Touched event
                        event = open("eventSimulator/appTouchEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                elif eventMap[i] == "button":
                        #Write two events subsequently
-                       event = open("eventSimulator/buttonPushedEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/buttonPushedEvent.groovy", "r")                    
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/buttonHeldEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "presence":
                        #Write two events subsequently
-                       event = open("eventSimulator/presencePresentEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/presencePresentEvent.groovy", "r")                 
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/presenceLeftEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "doorState":
                        #Write two events subsequently
-                       event = open("eventSimulator/doorOpenEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/doorOpenEvent.groovy", "r")                        
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/doorClosedEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "motion":
                        #Write two events subsequently
-                       event = open("eventSimulator/motionActiveEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/motionActiveEvent.groovy", "r")                    
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/motionInactiveEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "smoke":
                        #Write three events subsequently
-                       event = open("eventSimulator/smokeClearEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/smokeClearEvent.groovy", "r")                      
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
                        event = open("eventSimulator/smokeDetectedEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/smokeTestedEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "carbonMonoxide":
                        #Write three events subsequently
-                       event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/carbonMonoxideClearEvent.groovy", "r")                     
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
                        event = open("eventSimulator/carbonMonoxideDetectedEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/carbonMonoxideTestedEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "battery":
                        event = open("eventSimulator/batteryChargeEvent.groovy", "r")
                        for line in event:
@@ -388,77 +247,71 @@ def ExtractEvents(extractedEvents):
                        event.close()
                elif eventMap[i] == "thermostatMode":
                        #Write five events subsequently
-                       event = open("eventSimulator/thermostatAutoModeEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,4)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/thermostatAutoModeEvent.groovy", "r")                      
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
                        event = open("eventSimulator/thermostatCoolModeEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 2) {\n")
                        event = open("eventSimulator/thermostatEmergencyHeatModeEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 3) {\n")
                        event = open("eventSimulator/thermostatHeatModeEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/thermostatOffModeEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventMap[i] == "switch":
                        #Write two events subsequently
-                       event = open("eventSimulator/switchOnEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/switchOnEvent.groovy", "r")                        
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/switchOffEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-               elif eventMap[i] == "Location":
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventMap[i] == "location": #Case for Location event
                        #Write three events subsequently
-                       event = open("eventSimulator/locationHomeEvent.groovy", "r")
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/locationHomeEvent.groovy", "r")                    
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
                        event = open("eventSimulator/locationAwayEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-                       extractedEvents.write("\t\t\tbreak\n")
-                       eventCounter = eventCounter + 1
-                       extractedEvents.write("\t\tcase %d:\n" % eventCounter)
+                       extractedEvents.write("\t\t\t} else {\n")
                        event = open("eventSimulator/locationNightEvent.groovy", "r")
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
                        event.close()
-               eventCounter = eventCounter + 1
+                       extractedEvents.write("\t\t\t}\n")
 
                ###TODO: Add more events later
-               extractedEvents.write("\n\t\t\tbreak\n")
+               extractedEvents.write("\t\t\tbreak\n")
        extractedEvents.write("\t}\n")
-       extractedEvents.write("\tcounter--\n")
+       #extractedEvents.write("\tcounter--\n")
        extractedEvents.write("}\n")
                
 #Extract objects to call functions from App1