In this exercise, you will try to improve the configuration of the temperature depending on time and user preferences criteria.
Question 1 – Using moment of the day: Users might prefer a colder temperature during the day than at night. Using the moment of the day component, you have written in the follow-me exercises, try to build different temperature profiles based on the moment of the day.
Your manager will have to register a listener to the MomentOfTheDay service and configure the temperature based on the moment of the day.
The configuration of the temperature will now depends on both the location (room) and the moment of the day.
Question 2 – Tracking users: In the following, we will try to base the reasoning not only on time factors but also on user preferences. The idea is to customized the temperature of a room based to the user that are mostly in a given room.
To do so, you need to collect information on which users will be in a room at a given time. This requires to use to PersonLocation service provided by iCASA to locate users precisely.
Extend the room occupancy service so that you can get the probability of someone to be in a given room at a given time:
package org.example.occupancy; public interface RoomOccupancy { //.. /** * Gets the probability (between 0 and 1) that the given user will be in the given room * at the given moment of the day. * * @param minuteOfTheDay * a specific time in the day in minute (between 0 (=00:00) and * 1439 (=23:59)). * @param room * the room name where the occupancy value is required. * @param user * the given user. * @return the room occupancy is a value between 0 and 1 where 0 indicates * that there the room is always empty and 1 indicates that the room * is always occupied at the given moment of the day. */ public double getRoomOccupancy(double minuteOfTheDay, String room, String user); }
You will have to choose the best accuracy of this service so as not to raise memory issues.
Question 3 – Building a User preference based profile We will now assume that each user is connected to as specific device (smartphone, computer, etc.) when configuring the temperature. Modify the command implementation accordingly:
g! tempTooHigh bathroom Alice g! tempTooLow bathroom Bob
Then modify your manager implementation to support this modification:
package org.example.temperature.manager.administration; /** * This interface allows to configure the temperature manager responsible for * configuring the temperature controller. */ public interface TemperatureManagerAdministration { /** * This method is called every time a user think the temperature is too high * in a given room. * * @param roomName * the room where the temperature should be reconfigured * @param userName * the user who expressed that preference */ public void temperatureIsTooHigh(String roomName, String username); /** * This method is called every time a user think the temperature is too high * in a given room. * * @param roomName * the room where the temperature should be reconfigured * @param userName * the user who expressed that preference */ public void temperatureIsTooLow(String roomName, String username); }
The temperature preference has too be store for each users. We assume that the set of visitor is stable and limited (e.g., a typical family of 4 or 5 users).
Question 4 – Configuring the temperature based on these multiple sources of information Using the room occupancy service and the user based profiles try to configure the temperature to match the best user preferences at a moment of the day.
This problem has many solutions. You will have to deal with state flapping when more that one user is in the room. You should find a give some user more priority than an other (the probability of being in a room is one of the factors to consider).
There is a chance that a temperature might not be perfect for one or more user of a given room. You will probably have to ignore some of their complaints.