2 * ResourceList.h - TaskJuggler
4 * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
13 #ifndef _ResourceList_h_
14 #define _ResourceList_h_
20 #include "VacationList.h"
21 #include "CoreAttributes.h"
22 #include "ShiftList.h"
29 * @short Booking information for a time slot of the resource.
30 * @author Chris Schlaeger <cs@suse.de>
35 SbBooking(Task* t, QString a = "", QString i = "")
36 : task(t), account(a), projectId(i) { }
39 Task* getTask() const { return task; }
41 void setAccount(const QString a) { account = a; }
42 const QString& getAccount() const { return account; }
44 void setProjectId(const QString i) { projectId = i; }
45 const QString& getProjectId() const { return projectId; }
48 /// A pointer to the task that caused the booking
50 /// String identifying the KoTrus account the effort is credited to.
57 * @short Booking information for an interval of the resource.
58 * @author Chris Schlaeger <cs@suse.de>
60 class Booking : public SbBooking
63 Booking(const Interval& iv, Task* t, QString a = "",
65 : SbBooking(t, a, i), interval(iv) { }
66 Booking(const Interval& iv, SbBooking* sb) : SbBooking(*sb),
70 time_t getStart() const { return interval.getStart(); }
71 time_t getEnd() const { return interval.getEnd(); }
72 time_t getDuration() const { return interval.getDuration(); }
73 Interval& getInterval() { return interval; }
75 void setLockTS( const QString& ts ) { lockTS = ts; }
76 const QString& getLockTS() const { return lockTS; }
78 void setLockerId( const QString& id ) { lockerId = id; }
79 const QString& getLockerId() const { return lockerId; }
82 /// The booked time period.
84 /// The database lock timestamp
92 * @short A list of bookings.
93 * @author Chris Schlaeger <cs@suse.de>
95 class BookingList : public QPtrList<Booking>
102 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
105 typedef QPtrListIterator<Booking> BookingListIterator;
110 * @short A list of resources.
111 * @author Chris Schlaeger <cs@suse.de>
113 class ResourceList : public CoreAttributesList
119 Resource* first() { return (Resource*) CoreAttributesList::first(); }
120 Resource* next() { return (Resource*) CoreAttributesList::next(); }
122 Resource* getResource(const QString& id);
124 static bool isSupportedSortingCriteria(int sc);
126 virtual int compareItemsLevel(Resource* r1, Resource* r2, int level);
129 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
136 * @short Stores all information about a resource.
137 * @author Chris Schlaeger <cs@suse.de>
139 class Resource : public CoreAttributes
141 friend int ResourceList::compareItemsLevel(Resource* r1, Resource* r2,
144 Resource(Project* p, const QString& i, const QString& n, Resource* p);
147 virtual const char* getType() { return "Resource"; }
149 Resource* getParent() const { return (Resource*) parent; }
151 bool isGroup() const { return !sub.isEmpty(); }
152 void getSubResourceList(ResourceList& rl);
154 Resource* subResourcesFirst();
155 Resource* subResourcesNext();
157 void setMinEffort(double e) { minEffort = e; }
158 double getMinEffort() const { return minEffort; }
160 void setMaxEffort(double e) { maxEffort = e; }
161 double getMaxEffort() const { return maxEffort; }
163 void setEfficiency(double e) { efficiency = e; }
164 double getEfficiency() const { return efficiency; }
166 void setRate(double r) { rate = r; }
167 double getRate() const { return rate; }
169 void addVacation(Interval* i) { vacations.append(i); }
170 bool hasVacationDay(time_t day);
172 bool isOnShift(const Interval& slot);
174 void setWorkingHours(int day, QPtrList<Interval>* l)
176 if (day < 0 || day > 6)
177 qFatal("day out of range");
178 delete workingHours[day];
179 workingHours[day] = l;
182 bool addShift(const Interval& i, Shift* s)
184 return shifts.insert(new ShiftSelection(i, s));
187 bool isAvailable(time_t day, time_t duration, int loadFactor, Task* t);
189 bool book(Booking* b);
191 bool bookSlot(uint idx, SbBooking* nb);
192 bool bookInterval(Booking* b);
193 bool addBooking(int sc, Booking* b);
195 double getCurrentLoad(const Interval& i, Task* task = 0);
197 long getCurrentLoadSub(uint startIdx, uint endIdx, Task* task);
199 double getLoad(int sc, const Interval& i, Task* task = 0);
201 long getLoadSub(int sc, uint startIdx, uint endIdx, Task* task);
203 double getCredits(int sc, const Interval& i, Task* task = 0);
205 QString getProjectIDs(int sc, const Interval& i, Task* task = 0);
207 bool isAllocated(int sc, const Interval& i, const QString& prjId);
209 BookingList getJobs(int sc);
211 void setKotrusId(const QString k) { kotrusId = k; }
212 const QString& getKotrusId() const { return kotrusId; }
214 bool dbLoadBookings(const QString& kotrusID,
215 const QStringList& skipProjectIDs);
217 QDomElement xmlIDElement( QDomDocument& doc ) const;
219 void prepareScenario(int sc);
220 void finishScenario(int sc);
223 Resource* subFirst() { return (Resource*) sub.first(); }
224 Resource* subNext() { return (Resource*) sub.next(); }
226 void getPIDs(int sc, const Interval& period, Task* task, QStringList& pids);
228 void initScoreboard();
229 uint sbIndex(time_t date) const;
231 time_t index2start(uint idx) const;
232 time_t index2end(uint idx) const;
234 /// Pointer used by subResourceFirst() and subResourceNext().
237 /// The minimum effort (in man days) the resource should be used per day.
240 /// The maximum effort (in man days) the resource should be used per day.
244 * The efficiency of the resource. A team of five should have an
245 * efficiency of 5.0 */
248 /// The daily costs of this resource.
251 /// KoTrus ID, ID by which the resource is known to KoTrus.
254 /// The list of standard working or opening hours for the resource.
255 QList<Interval>* workingHours[7];
258 * In addition to the standard working hours a set of shifts can be
259 * defined. This is useful when the working hours change over time.
260 * A shift is only active in a defined interval. If no interval is
261 * defined for a period of time the standard working hours of the
264 ShiftSelectionList shifts;
266 /// List of all intervals the resource is not available.
267 QList<Interval> vacations;
270 * For each time slot (of length scheduling granularity) we store a
271 * pointer to a booking, a '1' if slot is off-hours, a '2' if slot is
272 * during a vacation or 0 if resource is available. */
273 SbBooking** scoreboard;
274 /// The number of time slots in the project.
277 SbBooking** scoreboards[2];