1 | package schedframe.resources.computing.profiles.energy.airthroughput; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import org.joda.time.DateTimeUtils; |
---|
7 | |
---|
8 | import schedframe.Parameters; |
---|
9 | import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirflowEstimationPlugin; |
---|
10 | |
---|
11 | public class AirflowProfile { |
---|
12 | |
---|
13 | protected List<AirflowValue> airflowHistory; |
---|
14 | |
---|
15 | protected AirflowEstimationPlugin airflowEstimationPlugin; |
---|
16 | protected List <AirflowState> airflowStates; |
---|
17 | protected Parameters parameters; |
---|
18 | |
---|
19 | public AirflowProfile(AirflowEstimationPlugin airflowEstimationPlugin, List<AirflowState> airflowStates) { |
---|
20 | super(); |
---|
21 | this.airflowEstimationPlugin = airflowEstimationPlugin; |
---|
22 | this.airflowStates = airflowStates; |
---|
23 | this.airflowHistory = new ArrayList<AirflowValue>(); |
---|
24 | } |
---|
25 | |
---|
26 | public List<AirflowState> getAirflowStates() { |
---|
27 | return airflowStates; |
---|
28 | } |
---|
29 | |
---|
30 | public void addToAirFlowHistory(double airflow) { |
---|
31 | |
---|
32 | if (airflowHistory.size() == 0) { |
---|
33 | AirflowValue usage = new AirflowValue(DateTimeUtils.currentTimeMillis(), airflow); |
---|
34 | airflowHistory.add(usage); |
---|
35 | return; |
---|
36 | } |
---|
37 | |
---|
38 | int lastIdx = airflowHistory.size() - 1; |
---|
39 | double lastAirflow = airflowHistory.get(lastIdx).getValue(); |
---|
40 | if (lastAirflow != airflow) { |
---|
41 | AirflowValue usage = airflowHistory.get(lastIdx); |
---|
42 | long currentTime = DateTimeUtils.currentTimeMillis(); |
---|
43 | if (usage.getTimestamp() == currentTime) { |
---|
44 | usage.setValue(airflow); |
---|
45 | if(lastIdx > 0 && airflowHistory.get(lastIdx - 1).getValue() == airflow) |
---|
46 | airflowHistory.remove(usage); |
---|
47 | } else { |
---|
48 | usage = new AirflowValue(DateTimeUtils.currentTimeMillis(), airflow); |
---|
49 | airflowHistory.add(usage); |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | public List<AirflowValue> getAirflowHistory() { |
---|
55 | return airflowHistory; |
---|
56 | } |
---|
57 | |
---|
58 | public void init(Parameters params){ |
---|
59 | this.parameters = params; |
---|
60 | } |
---|
61 | |
---|
62 | public Parameters getParameters() { |
---|
63 | return parameters; |
---|
64 | } |
---|
65 | } |
---|