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_
22 #include "VacationList.h"
23 #include "CoreAttributes.h"
24 #include "ShiftList.h"
33 SbBooking(Task* t, QString a = "", QString i = "")
34 : task(t), account(a), projectId(i) { }
37 Task* getTask() const { return task; }
39 void setAccount(const QString a) { account = a; }
40 const QString& getAccount() const { return account; }
42 void setProjectId(const QString i) { projectId = i; }
43 const QString& getProjectId() const { return projectId; }
46 // A pointer to the task that caused the booking
48 // String identifying the KoTrus account the effort is credited to.
54 class Booking : public SbBooking
57 Booking(const Interval& iv, Task* t, QString a = "",
59 : SbBooking(t, a, i), interval(iv) { }
60 Booking(const Interval& iv, SbBooking* sb) : SbBooking(*sb),
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; }
69 void setLockTS( const QString& ts ) { lockTS = ts; }
70 const QString& getLockTS() const { return lockTS; }
72 void setLockerId( const QString& id ) { lockerId = id; }
73 const QString& getLockerId() const { return lockerId; }
76 // The booked time period.
78 // The database lock timestamp
85 class BookingList : public QPtrList<Booking>
92 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
95 typedef QPtrListIterator<Booking> BookingListIterator;
99 class ResourceList : public CoreAttributesList
105 Resource* first() { return (Resource*) CoreAttributesList::first(); }
106 Resource* next() { return (Resource*) CoreAttributesList::next(); }
108 Resource* getResource(const QString& id);
111 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
114 class Resource : public CoreAttributes
116 friend int ResourceList::compareItems(QCollection::Item i1,
117 QCollection::Item i2);
119 Resource(Project* p, const QString& i, const QString& n, Resource* p);
122 virtual char* getType() { return "Resource"; }
124 Resource* getParent() const { return (Resource*) parent; }
126 bool isGroup() const { return !sub.isEmpty(); }
127 void getSubResourceList(ResourceList& rl);
129 Resource* subResourcesFirst();
130 Resource* subResourcesNext();
132 void setMinEffort(double e) { minEffort = e; }
133 double getMinEffort() const { return minEffort; }
135 void setMaxEffort(double e) { maxEffort = e; }
136 double getMaxEffort() const { return maxEffort; }
138 void setEfficiency(double e) { efficiency = e; }
139 double getEfficiency() const { return efficiency; }
141 void setRate(double r) { rate = r; }
142 double getRate() const { return rate; }
144 void addVacation(Interval* i) { vacations.append(i); }
145 bool hasVacationDay(time_t day);
147 void setWorkingHours(int day, QPtrList<Interval>* l)
149 if (day < 0 || day > 6)
150 qFatal("day out of range");
151 delete workingHours[day];
152 workingHours[day] = l;
155 bool addShift(const Interval& i, Shift* s)
157 return shifts.insert(new ShiftSelection(i, s));
160 bool isAvailable(time_t day, time_t duration, int loadFactor, Task* t);
162 bool book(Booking* b);
164 bool bookSlot(uint idx, SbBooking* nb);
165 bool bookInterval(Booking* b);
166 bool addPlanBooking(Booking* b);
167 bool addActualBooking(Booking* b);
169 double getPlanLoad(const Interval& i, Task* task = 0);
171 double getActualLoad(const Interval& i, Task* task = 0);
173 double getPlanCredits(const Interval& i, Task* task = 0);
175 double getActualCredits(const Interval& i, Task* task = 0);
177 QString getPlanProjectIDs(const Interval& i, Task* task = 0);
178 QString getActualProjectIDs(const Interval& i, Task* task = 0);
180 void setKotrusId(const QString k) { kotrusId = k; }
181 const QString& getKotrusId() const { return kotrusId; }
183 bool dbLoadBookings(const QString& kotrusID,
184 const QStringList& skipProjectIDs);
186 QDomElement xmlIDElement( QDomDocument& doc ) const
189 QDomElement elem = doc.createElement( "ResourceID" );
190 QDomText t=doc.createTextNode( getId() );
191 elem.appendChild( t );
192 elem.setAttribute( "Name", getName() );
197 BookingList getPlanJobs();
198 BookingList getActualJobs();
203 void prepareActual();
207 Resource* subFirst() { return (Resource*) sub.first(); }
208 Resource* subNext() { return (Resource*) sub.next(); }
210 void getPlanPIDs(const Interval& period, Task* task, QStringList& pids);
211 void getActualPIDs(const Interval& period, Task* task, QStringList& pids);
213 void initScoreboard();
214 uint sbIndex(time_t date) const;
216 time_t index2start(uint idx) const;
217 time_t index2end(uint idx) const;
219 /// Pointer used by subResourceFirst() and subResourceNext().
222 /// The minimum effort (in man days) the resource should be used per day.
225 /// The maximum effort (in man days) the resource should be used per day.
229 * The efficiency of the resource. A team of five should have an
230 * efficiency of 5.0 */
233 /// The daily costs of this resource.
236 /// KoTrus ID, ID by which the resource is known to KoTrus.
239 /// The list of standard working or opening hours for the resource.
240 QList<Interval>* workingHours[7];
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
249 ShiftSelectionList shifts;
251 /// List of all intervals the resource is not available.
252 QList<Interval> vacations;
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.
262 /// Scoring of planned usages of the resource.
263 SbBooking** planScoreboard;
264 /// Scoring of actual usages of the resource.
265 SbBooking** actualScoreboard;