Adding new events in the script.
authorrtrimana <rtrimana@uci.edu>
Tue, 30 Jul 2019 00:52:24 +0000 (17:52 -0700)
committerrtrimana <rtrimana@uci.edu>
Tue, 30 Jul 2019 00:52:24 +0000 (17:52 -0700)
Extractor/ExtractorScript.py

index 5bd867a..51f753e 100644 (file)
@@ -158,10 +158,19 @@ def ExtractEvents(extractedEvents):
        for i in range(len(eventList)):
                extractedEvents.write("\t\tcase %d:\n" % i)
                if eventList[i] == "lock":
-                       event = open("eventSimulator/lockEvent.groovy", "r")
+                       #Write two events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/lockLockedEvent.groovy", "r")                      
                        for line in event:
-                               extractedEvents.write(line)
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/lockUnlockedEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
                        event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventList[i] == "unlock":
                        event = open("eventSimulator/unlockEvent.groovy", "r")
                        for line in event:
@@ -201,16 +210,44 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventList[i] == "presence":
+               elif eventList[i] == "water":
                        #Write two events subsequently
                        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")                 
+                       event = open("eventSimulator/waterDryEvent.groovy", "r")                        
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/presenceLeftEvent.groovy", "r")
+                       event = open("eventSimulator/waterWetEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "presence":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+                       #Write three events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       if capability == "capability.presenceSensor":
+                               event = open("eventSimulator/presencePresentEvent.groovy", "r")
+                       elif capability == "capability.beacon":
+                               event = open("eventSimulator/beaconPresentEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
+                       if capability == "capability.presenceSensor":
+                               event = open("eventSimulator/presenceLeftEvent.groovy", "r")
+                       elif capability == "capability.beacon":
+                               event = open("eventSimulator/beaconLeftEvent.groovy", "r")
+                       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()
@@ -266,7 +303,6 @@ def ExtractEvents(extractedEvents):
                        #Check which capability
                        variable = eventVarMap[eventList[i]]
                        capability = capabilityMap[variable]
-
                        #Write three events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")                      
@@ -295,7 +331,13 @@ def ExtractEvents(extractedEvents):
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
                elif eventList[i] == "battery":
-                       event = open("eventSimulator/batteryChargeEvent.groovy", "r")
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+                       if capability == "capability.smokeDetector":
+                               event = open("eventSimulator/smokeDetectorBatteryEvent.groovy", "r")
+                       elif capability == "capability.battery":
+                               event = open("eventSimulator/batteryBatteryEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
@@ -328,16 +370,87 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "thermostatFanMode":
+                       #Write five events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,4)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/thermostatAutoFanModeEvent.groovy", "r")                   
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
+                       event = open("eventSimulator/thermostatFanCirculateFanModeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 2) {\n")
+                       event = open("eventSimulator/thermostatCirculateFanModeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 3) {\n")
+                       event = open("eventSimulator/thermostatFanOnFanModeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/thermostatOnFanModeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "thermostatOperatingState":
+                       #Write five events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,4)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/thermostatOperatingStateAutoEvent.groovy", "r")                    
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
+                       event = open("eventSimulator/thermostatOperatingStateCoolEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 2) {\n")
+                       event = open("eventSimulator/thermostatOperatingStateOffEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 3) {\n")
+                       event = open("eventSimulator/thermostatOperatingStateEmergencyHeatEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/thermostatOperatingStateHeatEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
                elif eventList[i] == "switch":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
                        #Write two events subsequently
                        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")                        
+                       if capability == "capability.switch":
+                               event = open("eventSimulator/switchOnEvent.groovy", "r")
+                       elif capability == "capability.switchLevel":
+                               event = open("eventSimulator/switchLevelOnEvent.groovy", "r")
+                       elif capability == "capability.relaySwitch":
+                               event = open("eventSimulator/relaySwitchOnEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/switchOffEvent.groovy", "r")
+                       if capability == "capability.switch":
+                               event = open("eventSimulator/switchOffEvent.groovy", "r")
+                       elif capability == "capability.switchLevel":
+                               event = open("eventSimulator/switchLevelOffEvent.groovy", "r")
+                       elif capability == "capability.relaySwitch":
+                               event = open("eventSimulator/relaySwitchOffEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
@@ -375,36 +488,193 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
-               elif eventList[i] == "beacon":
+               elif eventList[i] == "sleeping":
                        #Write two events subsequently
                        extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
                        extractedEvents.write("\t\t\tif (event == 0) {\n")
-                       event = open("eventSimulator/beaconPresenceEvent.groovy", "r")                  
+                       event = open("eventSimulator/sleepSleepingEvent.groovy", "r")                   
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t} else {\n")
-                       event = open("eventSimulator/beaconLeftEvent.groovy", "r")
+                       event = open("eventSimulator/sleepNotSleepingEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write("\t\t" + line)
                        event.close()
                        extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "goal":
+                       event = open("eventSimulator/stepGoalEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "steps":
+                       event = open("eventSimulator/stepStepsEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
                elif eventList[i] == "color":
-                       event = open("eventSimulator/colorChangeEvent.groovy", "r")
+                       event = open("eventSimulator/colorChangedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "hue":
-                       event = open("eventSimulator/hueChangeEvent.groovy", "r")
+                       event = open("eventSimulator/hueChangedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "saturation":
-                       event = open("eventSimulator/saturationChangeEvent.groovy", "r")
+                       event = open("eventSimulator/saturationChangedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
-
+               elif eventList[i] == "energy":
+                       event = open("eventSimulator/energyMeterEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "power":
+                       event = open("eventSimulator/powerMeterEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "illuminance":
+                       event = open("eventSimulator/illuminanceMeasurementEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "humidity":
+                       event = open("eventSimulator/humidityMeasurementEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "alarm":
+                       #Write four events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,3)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/alarmBothEvent.groovy", "r")                       
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
+                       event = open("eventSimulator/alarmSirenEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 2) {\n")
+                       event = open("eventSimulator/alarmStrobeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/alarmOffEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "contact":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+                       #Write two events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       if capability == "capability.contactSensor":
+                               event = open("eventSimulator/contactDefaultClosedEvent.groovy", "r")
+                       elif capability == "capability.valve":
+                               event = open("eventSimulator/valveClosedEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       if capability == "capability.contactSensor":
+                               event = open("eventSimulator/contactDefaultOpenEvent.groovy", "r")
+                       elif capability == "capability.valve":
+                               event = open("eventSimulator/valveOpenEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "status":
+                       #Write three events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,2)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/musicPlayerPlayingEvent.groovy", "r")                      
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else if (event == 1) {\n")
+                       event = open("eventSimulator/musicPlayerStoppedEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/musicPlayerPausedEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "level":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+                       if capability == "capability.musicPlayer":
+                               event = open("eventSimulator/musicPlayerLevelEvent.groovy", "r")
+                       elif capability == "capability.switchLevel":
+                               event = open("eventSimulator/switchLevelEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "trackDescription":
+                       event = open("eventSimulator/musicPlayerTrackDescriptionEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "trackData":
+                       event = open("eventSimulator/musicPlayerTrackDataEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "mute":
+                       #Write two events subsequently
+                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
+                       extractedEvents.write("\t\t\tif (event == 0) {\n")
+                       event = open("eventSimulator/musicPlayerUnmutedEvent.groovy", "r")                      
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t} else {\n")
+                       event = open("eventSimulator/musicPlayerMutedEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write("\t\t" + line)
+                       event.close()
+                       extractedEvents.write("\t\t\t}\n")
+               elif eventList[i] == "temperature":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       capability = capabilityMap[variable]
+                       if capability == "capability.thermostat":
+                               event = open("eventSimulator/temperatureEvent.groovy", "r")
+                       elif capability == "capability.temperatureMeasurement":
+                               event = open("eventSimulator/temperatureMeasurementEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "heatingSetpoint":
+                       event = open("eventSimulator/heatingSetpointEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "coolingSetpoint":
+                       event = open("eventSimulator/coolingSetpointEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "thermostatSetpoint":
+                       event = open("eventSimulator/thermostatSetpointEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+                       
                ###TODO: Add more events later
                extractedEvents.write("\t\t\tbreak\n")
        extractedEvents.write("\t}\n")
@@ -418,6 +688,10 @@ def CheckIfOnlyTouchEvents():
                if item != "nfcTouch" and item != "app":
                        onlyTouchEvents = False
        if onlyTouchEvents is True and app1Subscribe is True and app2Subscribe is True:
+               # Write error log file
+               extractError = open("appCreationError.log", "w+")
+               extractError.write("Direct-Direct Interaction detected: we are skipping this pair...\n")
+               extractError.close()
                raise Exception("\n\nDirect-Direct Interaction detected: we are skipping this pair...\n\n")