source: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/load/ResourceLoadCalendar.java @ 1608

Revision 1608, 4.6 KB checked in by wojtekp, 8 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing.profiles.load;
2
3import java.util.LinkedList;
4
5import org.joda.time.DateTimeUtilsExt;
6
7import schemas.LoadCalendar;
8import schemas.LoadDistribution;
9import schemas.LoadSchedule;
10
11
12public class ResourceLoadCalendar {
13       
14        //private Day[] week;
15        private LinkedList<TimestampUtilization> loadDistribution;
16       
17        public ResourceLoadCalendar(LoadCalendar loadCalendar){
18                /*week = new Day[7];
19                for(int i = 0; i < 7; i++){
20                        week[i] = new Day();
21                }*/
22               
23                loadDistribution = new LinkedList<TimestampUtilization>();
24               
25                for(int i = 0; i < loadCalendar.getLoadScheduleCount(); i++){
26                        LoadSchedule loadSched = loadCalendar.getLoadSchedule(i);
27                        for(int j = 0; j < loadSched.getLoadDistributionCount(); j++){
28                                LoadDistribution ld = loadSched.getLoadDistribution(j);
29                                TimestampUtilization tu = new TimestampUtilization(ld.getFromTime(), ld.getToTime(), ld.getLoadLevel());
30                                loadDistribution.add(tu);
31                        }
32                }
33               
34                /*for(int i = 0; i < loadCalendar.getWeekDayCount(); i++){
35                        WeekDay weekDay = loadCalendar.getWeekDay(i);
36                        if(weekDay.getType().equals(DayType.VALUE_0)){
37                                WeekDayTypeChoice wdc = weekDay.getWeekDayTypeChoice();
38                                for(int j = 0; j < 7; j++){
39                                        if(wdc.hasLoadLevel()){
40                                                TimeUtilization tu = new TimeUtilization (new LocalTime(0, 0), new LocalTime(23, 59), wdc.getLoadLevel());
41                                                week[j].add(tu);
42                                        } else {
43                                                for(int k = 0; k < wdc.getTimePeriodCount(); k++){
44                                                        TimePeriod tp = wdc.getTimePeriod(k);
45                                                        TimeUtilization tu = new TimeUtilization (new LocalTime(tp.getFromTime().getHour(), tp.getFromTime().getMinute()), new LocalTime(tp.getToTime().getHour(), tp.getToTime().getMinute()), tp.getLoadLevel());
46                                                        week[j].add(tu);
47                                                }
48                                        }
49                                }
50                        } else {
51                                WeekDayTypeChoice wdc = weekDay.getWeekDayTypeChoice();
52                                if(wdc.hasLoadLevel()){
53                                        TimeUtilization tu = new TimeUtilization (new LocalTime(0, 0), new LocalTime(23, 59), wdc.getLoadLevel());
54                                        week[weekDay.getType().ordinal() - 1].add(tu);
55                                } else {
56                                        for(int k = 0; k < wdc.getTimePeriodCount(); k++){
57                                                TimePeriod tp = wdc.getTimePeriod(k);
58                                                TimeUtilization tu = new TimeUtilization (new LocalTime(tp.getFromTime().getHour(), tp.getFromTime().getMinute()), new LocalTime(tp.getToTime().getHour(), tp.getToTime().getMinute()), tp.getLoadLevel());
59                                                week[weekDay.getType().ordinal() - 1].add(tu);
60                                        }
61                                }
62                        }       
63                }*/
64        }
65       
66        public ResourceLoadCalendar(){
67                loadDistribution = new LinkedList<TimestampUtilization>();
68        }
69       
70        /*public double getLoad(DateTime dateTime){
71                int dayType = dateTime.getDayOfWeek();
72                int timeOfDay = dateTime.getMillisOfDay();
73                Day day = week[dayType];
74                for(TimeUtilization tu: day){
75                        if(tu.getStartTime().getMillisOfDay() <= timeOfDay && tu.getEndTime().getMillisOfDay() > timeOfDay)
76                                return tu.getUtlization();
77                }
78                return 0;
79        }*/
80       
81        public double getCurrentLoad(){
82                long simStartTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis();
83                long currentTime = DateTimeUtilsExt.currentTimeMillis();
84                long runTime = (currentTime-simStartTime) / 1000;
85
86                for(int i = 0; i < loadDistribution.size(); i++){
87                        TimestampUtilization tu = loadDistribution.get(i);
88                        if(tu.getStartTime() == runTime) {
89                                return loadDistribution.get(i).getUtlization();
90                        } else if(tu.getStartTime() > runTime && i != 0) {
91                                return loadDistribution.get(i-1).getUtlization();
92                        }
93                }
94                return 0;
95        }
96
97        public void setLoadDistribution(LinkedList<TimestampUtilization> loadDistribution) {
98                this.loadDistribution = loadDistribution;
99        }
100        public LinkedList<TimestampUtilization> getLoadDistribution() {
101                return loadDistribution;
102        }
103}
104
105/*class Day extends ArrayList<TimeUtilization> {
106
107        private static final long serialVersionUID = -1788266677275361001L;
108}
109
110class TimeUtilization implements Comparable<TimeUtilization>{
111
112        LocalTime startTime;
113        LocalTime endTime;
114        double utlization;
115
116        TimeUtilization(LocalTime startTime, LocalTime endTime, double utlization) {
117                super();
118                this.startTime = startTime;
119                this.endTime = endTime;
120                this.utlization = utlization;
121        }
122
123        public double getUtlization() {
124                return utlization;
125        }
126        public void setUtlization(double utlization) {
127                this.utlization = utlization;
128        }
129
130        @Override
131        public int compareTo(TimeUtilization arg0) {
132                if(this.getStartTime().getMillisOfDay() < arg0.getStartTime().getMillisOfDay() )
133                        return 1;
134                else if (this.getStartTime().getMillisOfDay() > arg0.getStartTime().getMillisOfDay() )
135                        return -1;
136                else
137                        return 0;
138        }
139        public LocalTime getStartTime() {
140                return startTime;
141        }
142        public void setStartTime(LocalTime startTime) {
143                this.startTime = startTime;
144        }
145        public LocalTime getEndTime() {
146                return endTime;
147        }
148        public void setEndTime(LocalTime endTime) {
149                this.endTime = endTime;
150        }
151}
152*/
153
Note: See TracBrowser for help on using the repository browser.