OSDN Git Service

- Partial fix for timezone handling.
[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 #include <qstring.h>
19 #include <qdom.h>
20
21 #include "Interval.h"
22 #include "VacationList.h"
23 #include "CoreAttributes.h"
24 #include "ShiftList.h"
25
26 class Project;
27 class Task;
28 class Resource;
29
30 class SbBooking
31 {
32 public:
33         SbBooking(Task* t, QString a = "", QString i = "")
34                 : task(t), account(a), projectId(i) { }
35         ~SbBooking() { }
36         
37         Task* getTask() const { return task; }
38
39         void setAccount(const QString a) { account = a; }
40         const QString& getAccount() const { return account; }
41
42         void setProjectId(const QString i) { projectId = i; }
43         const QString& getProjectId() const { return projectId; }
44
45 private:
46         // A pointer to the task that caused the booking
47         Task* task;
48         // String identifying the KoTrus account the effort is credited to.
49         QString account;
50         // The Project ID
51         QString projectId;
52 };
53
54 class Booking : public SbBooking
55 {
56 public:
57         Booking(const Interval& iv, Task* t, QString a = "",
58                         QString i = "")
59                 : SbBooking(t, a, i), interval(iv) { }
60         Booking(const Interval& iv, SbBooking* sb) : SbBooking(*sb),
61                         interval(iv) { }
62         ~Booking() { }
63
64         time_t getStart() const { return interval.getStart(); }
65         time_t getEnd() const { return interval.getEnd(); }
66         time_t getDuration() const { return interval.getDuration(); }
67         Interval& getInterval() { return interval; }
68
69         void setLockTS( const QString& ts ) { lockTS = ts; }
70         const QString& getLockTS() const { return lockTS; }
71
72         void setLockerId( const QString& id ) { lockerId = id; }
73         const QString& getLockerId() const { return lockerId; }
74
75 private:
76         // The booked time period.
77         Interval interval;
78         // The database lock timestamp
79         QString lockTS;
80
81         // the lockers ID
82         QString lockerId;
83 } ;
84
85 class BookingList : public QPtrList<Booking>
86 {
87 public:
88         BookingList() { }
89         ~BookingList() { }
90
91 protected:
92         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
93 };
94
95 typedef QPtrListIterator<Booking> BookingListIterator;
96
97 class Resource;
98
99 class ResourceList : public CoreAttributesList
100 {
101 public:
102         ResourceList();
103         ~ResourceList() { }
104
105         Resource* first() { return (Resource*) CoreAttributesList::first(); }
106         Resource* next() { return (Resource*) CoreAttributesList::next(); }
107
108         Resource* getResource(const QString& id);
109
110 protected:
111         virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
112 } ;
113
114 class Resource : public CoreAttributes
115 {
116         friend int ResourceList::compareItems(QCollection::Item i1,
117                                               QCollection::Item i2);
118 public:
119         Resource(Project* p, const QString& i, const QString& n, Resource* p);
120         virtual ~Resource();
121
122         virtual char* getType() { return "Resource"; }
123
124         Resource* getParent() const { return (Resource*) parent; }
125
126         bool isGroup() const { return !sub.isEmpty(); }
127         void getSubResourceList(ResourceList& rl);
128
129         Resource* subResourcesFirst();
130         Resource* subResourcesNext();
131
132         void setMinEffort(double e) { minEffort = e; }
133         double getMinEffort() const { return minEffort; }
134
135         void setMaxEffort(double e) { maxEffort = e; }
136         double getMaxEffort() const { return maxEffort; }
137
138         void setEfficiency(double e) { efficiency = e; }
139         double getEfficiency() const { return efficiency; }
140
141         void setRate(double r) { rate = r; }
142         double getRate() const { return rate; }
143
144         void addVacation(Interval* i) { vacations.append(i); }
145         bool hasVacationDay(time_t day);
146
147         void setWorkingHours(int day, QPtrList<Interval>* l)
148         {
149                 if (day < 0 || day > 6)
150                         qFatal("day out of range");
151                 delete workingHours[day];
152                 workingHours[day] = l;
153         }
154
155         bool addShift(const Interval& i, Shift* s)
156         {
157                 return shifts.insert(new ShiftSelection(i, s));
158         }
159
160         bool isAvailable(time_t day, time_t duration, int loadFactor, Task* t);
161
162         bool book(Booking* b);
163
164         bool bookSlot(uint idx, SbBooking* nb);
165         bool bookInterval(Booking* b);
166         bool addPlanBooking(Booking* b);
167         bool addActualBooking(Booking* b);
168
169         double getPlanLoad(const Interval& i, Task* task = 0);
170
171         double getActualLoad(const Interval& i, Task* task = 0);
172
173         double getPlanCredits(const Interval& i, Task* task = 0);
174
175         double getActualCredits(const Interval& i, Task* task = 0);
176
177         QString getPlanProjectIDs(const Interval& i, Task* task = 0);
178         QString getActualProjectIDs(const Interval& i, Task* task = 0);
179
180         void setKotrusId(const QString k) { kotrusId = k; }
181         const QString& getKotrusId() const { return kotrusId; }
182
183         bool dbLoadBookings(const QString& kotrusID,
184                                                 const QStringList& skipProjectIDs);
185
186         QDomElement xmlIDElement( QDomDocument& doc ) const
187         {
188            
189            QDomElement elem = doc.createElement( "ResourceID" );
190            QDomText t=doc.createTextNode( getId() );
191            elem.appendChild( t );
192            elem.setAttribute( "Name", getName() );
193
194            return( elem );
195         }
196
197         BookingList getPlanJobs();
198         BookingList getActualJobs();
199
200         void preparePlan();
201         void finishPlan();
202
203         void prepareActual();
204         void finishActual();
205
206 private:
207         Resource* subFirst() { return (Resource*) sub.first(); }
208         Resource* subNext() { return (Resource*) sub.next(); }
209
210         void getPlanPIDs(const Interval& period, Task* task, QStringList& pids);
211         void getActualPIDs(const Interval& period, Task* task, QStringList& pids);
212
213         void initScoreboard();
214         uint sbIndex(time_t date) const;
215
216         time_t index2start(uint idx) const;
217         time_t index2end(uint idx) const;
218
219         /// Pointer used by subResourceFirst() and subResourceNext().
220         Resource* currentSR;
221
222         /// The minimum effort (in man days) the resource should be used per day.
223         double minEffort;
224
225         /// The maximum effort (in man days) the resource should be used per day.
226         double maxEffort;
227
228         /**
229          * The efficiency of the resource. A team of five should have an
230          * efficiency of 5.0 */
231         double efficiency;
232
233         /// The daily costs of this resource.
234         double rate;
235
236         /// KoTrus ID, ID by which the resource is known to KoTrus.
237         QString kotrusId;
238
239         /// The list of standard working or opening hours for the resource.
240         QList<Interval>* workingHours[7];
241
242         /**
243          * In addition to the standard working hours a set of shifts can be
244          * defined. This is useful when the working hours change over time.
245          * A shift is only active in a defined interval. If no interval is
246          * defined for a period of time the standard working hours of the
247          * resource are used.
248          */
249         ShiftSelectionList shifts;
250
251         /// List of all intervals the resource is not available.
252         QList<Interval> vacations;
253
254         /**
255          * For each time slot (of length scheduling granularity) we store a
256          * pointer to a booking, a '1' if slot is off-hours, a '2' if slot is
257          * during a vacation or 0 if resource is available. */
258         SbBooking** scoreboard;
259         /// The number of time slots in the project.
260         uint sbSize;
261
262         /// Scoring of planned usages of the resource.
263         SbBooking** planScoreboard;
264         /// Scoring of actual usages of the resource.
265         SbBooking** actualScoreboard;
266 } ;
267
268 #endif