1 | package dk.deepthought.sidious.rules; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | |
6 | import org.apache.commons.logging.Log; |
7 | import org.apache.commons.logging.LogFactory; |
8 | |
9 | import dk.deepthought.sidious.goalhandler.Goal; |
10 | import dk.deepthought.sidious.greenhouse.ClimaticState; |
11 | import dk.deepthought.sidious.greenhouse.SensorInput; |
12 | import dk.deepthought.sidious.supportsystem.Adjustable; |
13 | import dk.deepthought.sidious.supportsystem.State; |
14 | import dk.deepthought.sidious.supportsystem.Step; |
15 | import dk.deepthought.sidious.supportsystem.SystemSettings; |
16 | |
17 | /** |
18 | * Class simulates the heat expenses. |
19 | * <p> |
20 | * This simple simulation is done by checking whether the heater is active or |
21 | * not. The higher the activity of the heater the higher the desire value. |
22 | * |
23 | * @author Deepthought |
24 | * |
25 | */ |
26 | public class HeatExpensesRule extends Rule { |
27 | |
28 | //FIXME flyt værdier ud i property fil! |
29 | |
30 | /** |
31 | * Logger for this class |
32 | */ |
33 | private static final Log logger = LogFactory.getLog(HeatExpensesRule.class); |
34 | |
35 | /* |
36 | * (non-Javadoc) |
37 | * |
38 | * @see dk.deepthought.sidious.rules.Rule#desire(dk.deepthought.sidious.supportsystem.State, |
39 | * dk.deepthought.sidious.supportsystem.State, |
40 | * dk.deepthought.sidious.supportsystem.Step) |
41 | */ |
42 | public double desire(State currentState, State newState, Step step) { |
43 | if (logger.isDebugEnabled()) { |
44 | logger.debug("desire(State currentState=" + currentState |
45 | + ", State newState=" + newState + ", Step step=" + step |
46 | + ") - start"); |
47 | } |
48 | |
49 | ArrayList<Adjustable> adjs = new ArrayList<Adjustable>(step |
50 | .getAdjustables()); |
51 | Adjustable heater = null; |
52 | for (Adjustable adjustable : adjs) { |
53 | if (adjustable.getID().equals(SystemSettings.getHeaterSetPointID())) { |
54 | heater = adjustable; |
55 | } |
56 | } |
57 | SensorInput temperature = null; |
58 | if (currentState instanceof ClimaticState) { |
59 | ClimaticState currentClima = (ClimaticState) currentState; |
60 | for (SensorInput input : currentClima.getSensors()) { |
61 | if (input.getID().equals(SystemSettings.getTemperatureID())) { |
62 | temperature = input; |
63 | } |
64 | } |
65 | } |
66 | double returndouble = 0; |
67 | double diff = 0; |
68 | if (heater != null && temperature != null) { |
69 | diff = heater.getSetting() - temperature.getValue(); |
70 | } |
71 | if (diff < 0) { |
72 | returndouble = 0; |
73 | } else if (diff < 5) { |
74 | returndouble = (diff / 5); |
75 | } else { |
76 | returndouble = 1; |
77 | } |
78 | if (logger.isDebugEnabled()) { |
79 | logger.debug("desire(State currentState=" + currentState |
80 | + ", State newState=" + newState + ", Step step=" + step |
81 | + ") - end - return value=" + returndouble); |
82 | } |
83 | return returndouble; |
84 | } |
85 | |
86 | /* |
87 | * (non-Javadoc) |
88 | * |
89 | * @see dk.deepthought.sidious.rules.Rule#getGoals() |
90 | */ |
91 | public Collection<Goal> getGoals() { |
92 | if (logger.isDebugEnabled()) { |
93 | logger.debug("getGoals() - start"); |
94 | } |
95 | // Is not goal oriented |
96 | Collection<Goal> returnCollection = new ArrayList<Goal>(); |
97 | if (logger.isDebugEnabled()) { |
98 | logger.debug("getGoals() - end - return value=" + returnCollection); |
99 | } |
100 | return returnCollection; |
101 | } |
102 | |
103 | } |