OSDN Git Service

- Added better status reporting functions.
[tjqt4port/tj2qt4.git] / taskjuggler / ResourceList.h
1 /*
2  * ResourceList.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002 by Chris Schlaeger <cs@suse.de>
5  *
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.
9  *
10  * $Id$
11  */
12
13 #ifndef _ResourceList_h_
14 #define _ResourceList_h_
15
16 #include <time.h>
17 #include <qptrlist.h>
18
19 #include "Interval.h"
20 #include "VacationList.h"
21 #include "CoreAttributes.h"
22 #include "ShiftList.h"
23
24 class Project;
25 class Task;
26 class Resource;
27
28 /**
29  * @short Booking information for a time slot of the resource.
30  * @author Chris Schlaeger <cs@suse.de>
31  */
32 class SbBooking
33 {
34 public:
35         SbBooking(Task* t, QString a = "", QString i = "")
36                 : task(t), account(a), projectId(i) { }
37         ~SbBooking() { }
38         
39         Task* getTask() const { return task; }
40
41         void setAccount(const QString a) { account = a; }
42         const QString& getAccount() const { return account; }
43
44         void setProjectId(const QString i) { projectId = i; }
45         const QString& getProjectId() const { return projectId; }
46
47 private:
48         /// A pointer to the task that caused the booking
49         Task* task;
50         /// String identifying the KoTrus account the effort is credited to.
51         QString account;
52         /// The Project ID
53         QString projectId;
54 };
55
56 /**
57  * @short Booking information for an interval of the resource.
58  * @author Chris Schlaeger <cs@suse.de>
59  */
60 class Booking : public SbBooking
61 {
62 public:
63         Booking(const Interval& iv, Task* t, QString a = "",
64                         QString i = "")
65                 : SbBooking(t, a, i), interval(iv) { }
66         Booking(const Interval& iv, SbBooking* sb) : SbBooking(*sb),
67                         interval(iv) { }
68         ~Booking() { }
69
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; }
74
75         void setLockTS( const QString& ts ) { lockTS = ts; }
76         const QString& getLockTS() const { return lockTS; }
77
78         void setLockerId( const QString& id ) { lockerId = id; }
79         const QString& getLockerId() const { return lockerId; }
80
81 private:
82         /// The booked time period.
83         Interval interval;
84         /// The database lock timestamp
85         QString lockTS;
86
87         /// the lockers ID
88         QString lockerId;
89 } ;
90
91 /**
92  * @short A list of bookings.
93  * @author Chris Schlaeger <cs@suse.de>
94  */
95 class BookingList : public QPtrList<Booking>
96 {
97 public:
98         BookingList() { }
99         ~BookingList() { }
100
101 protected:
102         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
103 };
104
105 typedef QPtrListIterator<Booking> BookingListIterator;
106
107 class Resource;
108
109 /**
110  * @short A list of resources.
111  * @author Chris Schlaeger <cs@suse.de>
112  */
113 class ResourceList : public CoreAttributesList
114 {
115 public:
116         ResourceList();
117         ~ResourceList() { }
118
119         Resource* first() { return (Resource*) CoreAttributesList::first(); }
120         Resource* next() { return (Resource*) CoreAttributesList::next(); }
121
122         Resource* getResource(const QString& id);
123
124         static bool isSupportedSortingCriteria(int sc);
125         
126         virtual int compareItemsLevel(Resource* r1, Resource* r2, int level);
127
128 protected:
129         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
130 } ;
131
132 class QDomDocument;
133 class QDomElement;
134
135 /**
136  * @short Stores all information about a resource.
137  * @author Chris Schlaeger <cs@suse.de>
138  */
139 class Resource : public CoreAttributes
140 {
141         friend int ResourceList::compareItemsLevel(Resource* r1, Resource* r2,
142                                                                                            int level);
143 public:
144         Resource(Project* p, const QString& i, const QString& n, Resource* p);
145         virtual ~Resource();
146
147         virtual const char* getType() { return "Resource"; }
148
149         Resource* getParent() const { return (Resource*) parent; }
150
151         bool isGroup() const { return !sub.isEmpty(); }
152         void getSubResourceList(ResourceList& rl);
153
154         Resource* subResourcesFirst();
155         Resource* subResourcesNext();
156
157         void setMinEffort(double e) { minEffort = e; }
158         double getMinEffort() const { return minEffort; }
159
160         void setMaxEffort(double e) { maxEffort = e; }
161         double getMaxEffort() const { return maxEffort; }
162
163         void setEfficiency(double e) { efficiency = e; }
164         double getEfficiency() const { return efficiency; }
165
166         void setRate(double r) { rate = r; }
167         double getRate() const { return rate; }
168
169         void addVacation(Interval* i) { vacations.append(i); }
170         bool hasVacationDay(time_t day);
171
172         bool isOnShift(const Interval& slot);
173
174         void setWorkingHours(int day, QPtrList<Interval>* l)
175         {
176                 if (day < 0 || day > 6)
177                         qFatal("day out of range");
178                 delete workingHours[day];
179                 workingHours[day] = l;
180         }
181
182         bool addShift(const Interval& i, Shift* s)
183         {
184                 return shifts.insert(new ShiftSelection(i, s));
185         }
186
187         bool isAvailable(time_t day, time_t duration, int loadFactor, Task* t);
188
189         bool book(Booking* b);
190
191         bool bookSlot(uint idx, SbBooking* nb);
192         bool bookInterval(Booking* b);
193         bool addBooking(int sc, Booking* b);
194
195         double getCurrentLoad(const Interval& i, Task* task = 0);
196
197         long getCurrentLoadSub(uint startIdx, uint endIdx, Task* task);
198
199         double getLoad(int sc, const Interval& i, Task* task = 0);
200
201         long getLoadSub(int sc, uint startIdx, uint endIdx, Task* task);
202
203         double getCredits(int sc, const Interval& i, Task* task = 0);
204
205         QString getProjectIDs(int sc, const Interval& i, Task* task = 0);
206
207         bool isAllocated(int sc, const Interval& i, const QString& prjId);
208
209         BookingList getJobs(int sc);
210
211         void setKotrusId(const QString k) { kotrusId = k; }
212         const QString& getKotrusId() const { return kotrusId; }
213
214         bool dbLoadBookings(const QString& kotrusID,
215                                                 const QStringList& skipProjectIDs);
216
217         QDomElement xmlIDElement( QDomDocument& doc ) const;
218
219         void prepareScenario(int sc);
220         void finishScenario(int sc);
221
222 private:
223         Resource* subFirst() { return (Resource*) sub.first(); }
224         Resource* subNext() { return (Resource*) sub.next(); }
225
226         void getPIDs(int sc, const Interval& period, Task* task, QStringList& pids);
227
228         void initScoreboard();
229         uint sbIndex(time_t date) const;
230
231         time_t index2start(uint idx) const;
232         time_t index2end(uint idx) const;
233
234         /// Pointer used by subResourceFirst() and subResourceNext().
235         Resource* currentSR;
236
237         /// The minimum effort (in man days) the resource should be used per day.
238         double minEffort;
239
240         /// The maximum effort (in man days) the resource should be used per day.
241         double maxEffort;
242
243         /**
244          * The efficiency of the resource. A team of five should have an
245          * efficiency of 5.0 */
246         double efficiency;
247
248         /// The daily costs of this resource.
249         double rate;
250
251         /// KoTrus ID, ID by which the resource is known to KoTrus.
252         QString kotrusId;
253
254         /// The list of standard working or opening hours for the resource.
255         QList<Interval>* workingHours[7];
256
257         /**
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
262          * resource are used.
263          */
264         ShiftSelectionList shifts;
265
266         /// List of all intervals the resource is not available.
267         QList<Interval> vacations;
268
269         /**
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.
275         uint sbSize;
276
277         SbBooking** scoreboards[2];
278 } ;
279
280 #endif