OSDN Git Service

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