Example #1
0
    def getValue(self):
        self.value = self.climate.clock
        self.date = self.climate.date

        d = datetime.datetime.strptime(str(self.date), '%Y%m%d')
        msg  = "{:%d.%m.%Y}".format(d)+"   "+"{:.0f}".format(self.value // 60).zfill(2) + ":" + "{:.0f}".format(int(self.value) % 60).zfill(2)

        if hasattr(eel, "setText"):
            eel.setText(self.id, msg)
        if hasattr(eel, "updateClock"):
            eel.updateClock(msg)
        return self.value
    def receiveMessage(ch, method, properties, k, body):
        resp = body.decode('utf-8')
        if resp == 'True':
            ch.status = True
            ch.setEnvEffect('temperature', 1)
            ch.setEnvEffect('humidity', 6)
            ch.setEnvEffect('co2', -200)

            if (hasattr(eel, "setWindowStatus")):
                eel.setWindowStatus(ch.id, True)
            if (hasattr(eel, "setText")):
                eel.setText(ch.id, "open")

        else:
            ch.status = False
            ch.setEnvEffect('temperature', 0)
            ch.setEnvEffect('humidity', 0)
            ch.setEnvEffect('co2', 0)
            if (hasattr(eel, "setWindowStatus")):
                eel.setWindowStatus(ch.id, False)
            if (hasattr(eel, "setText")):
                eel.setText(ch.id, "closed")
Example #3
0
    def getValue(self):

        if(self.value):
            if(random.random()<0.33):
                self.envEffect['sound_sensor'] = 5
            else:
                self.envEffect['sound_sensor'] = 0
        else:
            self.envEffect['sound_sensor'] = 0

        if(hasattr(eel,"setText")):
            if(self.value):
                eel.setText(self.id, "occupied")
            else:
                eel.setText(self.id, "free")

        #if(not self.override and random.random() < 0.5):
         #   self.value = not self.value
        if hasattr(eel,'setChairStatus'):
            eel.setChairStatus(self.id, self.value)

        return self.value
Example #4
0
    def getMessage(self):
        oldPersonCount = self.personCounter
        self.getValue()

        msg = self.getResponse()
        msg['value'] = str(self.arriving)
        self.msg = json.dumps(msg)
        if (hasattr(eel, "setText")):
            data = {
                'Person Counter': str(oldPersonCount),
                'Arriving now': str(self.arriving),
                'Leaving now': str(self.leaving)
            }
            msg = {'sender': 'motion_sensor', 'data': data}
            eel.setText(self.id, json.dumps(msg))

        for i in range(0, (self.leaving)):
            self.personLeaves()

        self.leaving = 0
        self.arriving = 0
        return self.msg
 def initFrontend(self):
     time.sleep(10)
     if (hasattr(eel, "setWindowStatus")):
         eel.setWindowStatus(self.id, self.status)
     if (hasattr(eel, "setText")):
         eel.setText(self.id, "closed")
Example #6
0
 def getValue(self):
     eel.setText(self.id, self.value)
Example #7
0
 def getValue(self):
     eel.setText('gateway', self.status)
Example #8
0
 def getValue(self):
     if(hasattr(eel,"setText")):
         eel.setText(self.id, str(round(self.value,1)))
    def update_problem(self):
        """
         Updates the string that will be used for the problem file generator using the current context
        :return:
        """
        pw = problem_writer()

        #context_state_copy = copy.deepcopy(self.context_state)
        #context_state_outside_copy = copy.deepcopy(self.context_state_outside)
        context_state_copy = self.context_state
        context_state_outside_copy = self.context_state_outside

        # set objects
        pw.setRooms(len(context_state_copy))
        chairCounter = 1
        nOfChairs = 0
        nOfPersPerRoom = [0, 0, 0]
        tables = []
        for i, room in enumerate(context_state_copy):
            i += 1
            presence = False
            nOfChairs += len(context_state_copy[room]['sensor']['pressure'])
            for c in context_state_copy[room]['sensor']['pressure']:
                if context_state_copy[room]['sensor']['pressure'][c]:
                    nOfPersPerRoom[i - 1] += 1
                    presence = True
                else:
                    pw.setFreeChair(chairCounter, i)
                chairCounter += 1
            if presence:
                pw.setPresence(i)

            roomTemp = list(
                context_state_copy[room]['sensor']['temperature'].values())[0]
            outsideTemp = list(context_state_outside_copy["none.none.none"]
                               ['sensor']['temperatureOut'].values())[0]

            if roomTemp == "low":
                if outsideTemp == ("mid" or "high"):
                    pw.setOutsideTemp("higher", i)
            if roomTemp == "high":
                if outsideTemp == ("mid" or "low"):
                    pw.setOutsideTemp("lower", i)
            if roomTemp == "mid":
                if outsideTemp == "low":
                    pw.setOutsideTemp("lower", i)
                elif outsideTemp == "high":
                    pw.setOutsideTemp("higher", i)

            roomHumidity = list(
                context_state_copy[room]['sensor']['humidity'].values())[0]
            outsideHumidity = list(context_state_outside_copy["none.none.none"]
                                   ['sensor']['humidityOut'].values())[0]

            if roomHumidity == "low":
                if outsideHumidity == ("mid" or "high"):
                    pw.setOutsideHum("higher", i)
            if roomHumidity == "high":
                if outsideHumidity == ("mid" or "low"):
                    pw.setOutsideHum("lower", i)
            if roomHumidity == "mid":
                if outsideHumidity == "low":
                    pw.setOutsideHum("lower", i)
                elif outsideHumidity == "high":
                    pw.setOutsideHum("higher", i)

            pw.setTemp(
                self.getSensorValue('temperature', room, context_state_copy),
                i)
            pw.setHum(
                self.getSensorValue('humidity', room, context_state_copy), i)

            if self.getSensorValue('co2', room, context_state_copy) == 'high':
                pw.setHighCO2(i)

            if self.getSensorValue('light_sensor', room,
                                   context_state_copy) == 'low':
                pw.setLowLight(i)

            for k, v in context_state_copy[room]['sensor'][
                    'sound_level'].items():
                tables.append(
                    context_state_copy[room]['sensor']['sound_level'][k])

            # Actuators
            if self.getActuatorValue('window', room, context_state_copy):
                pw.setWindowOpen(i)

            if self.getActuatorValue('climate_control', room,
                                     context_state_copy):
                pw.setClimateOn(i)
            if self.getActuatorValue('light', room, context_state_copy):
                pw.setLightOn(i)

        pw.setTables(len(tables))
        for i, v in enumerate(tables):
            if v == "high":
                pw.setLoudSound(i + 1)

        lowestNumOfPers = 0
        if nOfPersPerRoom[0] < nOfPersPerRoom[1]:
            if nOfPersPerRoom[0] < nOfPersPerRoom[2]:
                lowestNumOfPers = nOfPersPerRoom[0]
            else:
                lowestNumOfPers = nOfPersPerRoom[2]
        elif nOfPersPerRoom[1] < nOfPersPerRoom[2]:
            lowestNumOfPers = nOfPersPerRoom[1]
        else:
            lowestNumOfPers = nOfPersPerRoom[2]

        nOfPersPerRoom[0] -= lowestNumOfPers
        nOfPersPerRoom[1] -= lowestNumOfPers
        nOfPersPerRoom[2] -= lowestNumOfPers

        i = 0
        while i < len(nOfPersPerRoom):
            if nOfPersPerRoom[i] == 1:
                pw.setOnePersonMoreInRoom(i + 1)
            elif nOfPersPerRoom[i] == 2:
                pw.setTwoPersonMoreInRoom(i + 1)
            elif nOfPersPerRoom[i] == 3:
                pw.setThreePersonMoreInRoom(i + 1)
            i += 1

        self.actPersonCount = self.personCount
        for k in range(1, self.actPersonCount + 1):
            pw.setNewPerson(k)

        if self.actPersonCount != 0:
            pw.setPersons(self.actPersonCount)

        for w, v in context_state_outside_copy["none.none.none"]['sensor'][
                'weatherforcast'].items():
            if v:
                pw.setBadWeather()

        for l, v in context_state_outside_copy["none.none.none"]['sensor'][
                'light_sensor'].items():
            if v == "low":
                pw.setLowLightOutside()
        pw.setChairs(nOfChairs)
        pw.finishObjects()
        pw.finishInit()
        pw.finishGoal()

        if (hasattr(eel, "setText")):
            data = {
                'context_distribution_problem': pw.initDistribution,
                'context_environment_problem': pw.initEnvironment
            }
            msg = {'sender': 'ContextBridge', 'data': data}
            eel.setText("plan", json.dumps(msg))

        return pw, [
            pw.initEnvironment, pw.objectsEnvironment, pw.initDistribution,
            pw.objectsDistribution, pw.goalDistribution
        ]
    def execute_plan(self, plan_name):
        """
         Goes through the new plan and sends the actions for the affected actuators to the gateway
        :param plan_name:
        :return:
        """
        actions = plan_to_list(load_plan(plan_name))
        print(str(actions))
        for action in actions:
            command = action.split()
            method = command[0]

            room = ''
            status = False
            if method == 'climate-on':
                room = command[2]
                status = True
            elif method == 'climate-off':
                room = command[2]
                status = False
            elif method == 'keep-climate-on':
                continue
            elif method == 'window-open':
                room = command[2]
                status = True
            elif method == 'window-close':
                room = command[2]
                status = False
            elif method == 'keep-window-open':
                continue
            elif method == 'light-on':
                room = command[1]
                status = True
            elif method == 'light-off-low':
                room = command[1]
                status = False
            elif method == 'light-off-high':
                room = command[1]
                status = False
            elif method == 'reduce-sound-level':
                table = command[1].replace("t", "")
                status = True
            elif method == 'set-weathersafe':
                continue
            elif method == 'keep-light-off':
                continue
            elif method == 'keep-light-on':
                continue

            if method == 'even-distributed-reset':
                continue
            elif method == 'place-person-on-chair':
                person = command[1]
                room = command[2]
                chair = command[3]
                status = chair.replace("c", "")
            elif method == 'reject-new-person-because-full':
                continue

            actuator = ""
            if 'window' in method:
                actuator = 'window'
            elif 'light' in method:
                actuator = 'light'
            elif 'climate' in method:
                actuator = 'climate'
            elif 'sound' in method:
                actuator = 'sound_level'
            elif 'person' in method:
                actuator = 'place_person'

            if 'sound' in method:
                actuator += "_" + str(int(table) - 1)
            elif room == "":
                actuator = None
            elif 'person' in method:
                actuator += "_" + str(int(status) - 1)
            else:
                room = str(int(room.replace("r", "")) - 1)
                actuator += "_" + room

            if (hasattr(eel, "setText")):
                data = {'actuator': actuator, 'status': status}
                msg = {'sender': 'plan_executioner', 'data': data}
                eel.setText("plan", json.dumps(msg))

            self.send({'actuator': actuator, 'status': status})