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"
32 Booking(const Interval& iv, Task* t, QString a = "",
34 : interval(iv), task(t), account(a), projectId(i) { }
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; }
42 Task* getTask() const { return task; }
44 void setAccount(const QString a) { account = a; }
45 const QString& getAccount() const { return account; }
47 void setProjectId(const QString i) { projectId = i; }
48 const QString& getProjectId() const { return projectId; }
50 void setLockTS( const QString& ts ) { lockTS = ts; }
51 const QString& getLockTS() const { return lockTS; }
53 void setLockerId( const QString& id ) { lockerId = id; }
54 const QString& getLockerId() const { return lockerId; }
57 // The booked time period.
59 // A pointer to the task that caused the booking
61 // String identifying the KoTrus account the effort is credited to.
66 // The database lock timestamp
72 // A list of flags that can be used to select a sub-set of tasks.
76 class BookingList : public QPtrList<Booking>
83 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
86 typedef QPtrListIterator<Booking> BookingListIterator;
90 class ResourceList : public CoreAttributesList
96 Resource* first() { return (Resource*) CoreAttributesList::first(); }
97 Resource* next() { return (Resource*) CoreAttributesList::next(); }
99 Resource* getResource(const QString& id);
102 virtual int compareItems(QCollection::Item i1, QCollection::Item i2);
105 class Resource : public CoreAttributes
107 friend int ResourceList::compareItems(QCollection::Item i1,
108 QCollection::Item i2);
110 Resource(Project* p, const QString& i, const QString& n, Resource* p);
113 virtual char* getType() { return "Resource"; }
115 Resource* getParent() const { return (Resource*) parent; }
117 bool isGroup() const { return !sub.isEmpty(); }
118 void getSubResourceList(ResourceList& rl);
120 Resource* subResourcesFirst();
121 Resource* subResourcesNext();
123 void setMinEffort(double e) { minEffort = e; }
124 double getMinEffort() const { return minEffort; }
126 void setMaxEffort(double e) { maxEffort = e; }
127 double getMaxEffort() const { return maxEffort; }
129 void setEfficiency(double e) { efficiency = e; }
130 double getEfficiency() const { return efficiency; }
132 void setRate(double r) { rate = r; }
133 double getRate() const { return rate; }
135 void addVacation(Interval* i) { vacations.append(i); }
136 bool hasVacationDay(time_t day);
138 void setWorkingHours(int day, QPtrList<Interval>* l)
140 if (day < 0 || day > 6)
141 qFatal("day out of range");
142 delete workingHours[day];
143 workingHours[day] = l;
146 bool addShift(const Interval& i, Shift* s)
148 return shifts.insert(new ShiftSelection(i, s));
151 bool isAvailable(time_t day, time_t duration, int loadFactor, Task* t);
153 void book(Booking* b);
155 double getPlanLoad(const Interval& i, Task* task = 0);
157 double getActualLoad(const Interval& i, Task* task = 0);
159 double getPlanCredits(const Interval& i, Task* task = 0);
161 double getActualCredits(const Interval& i, Task* task = 0);
163 QString getPlanProjectIDs(const Interval& i, Task* task = 0);
164 QString getActualProjectIDs(const Interval& i, Task* task = 0);
166 void setKotrusId(const QString k) { kotrusId = k; }
167 const QString& getKotrusId() const { return kotrusId; }
169 bool dbLoadBookings(const QString& kotrusID,
170 const QStringList& skipProjectIDs);
172 QDomElement xmlIDElement( QDomDocument& doc ) const
175 QDomElement elem = doc.createElement( "ResourceID" );
176 QDomText t=doc.createTextNode( getId() );
177 elem.appendChild( t );
178 elem.setAttribute( "Name", getName() );
183 BookingList getPlanJobs();
184 BookingList getActualJobs();
189 void prepareActual();
193 Resource* subFirst() { return (Resource*) sub.first(); }
194 Resource* subNext() { return (Resource*) sub.next(); }
196 void getPlanPIDs(const Interval& period, Task* task, QStringList& pids);
197 void getActualPIDs(const Interval& period, Task* task, QStringList& pids);
199 void initScoreboard();
200 uint sbIndex(time_t date) const;
202 /// Pointer used by subResourceFirst() and subResourceNext().
205 /// The minimum effort (in man days) the resource should be used per day.
208 /// The maximum effort (in man days) the resource should be used per day.
212 * The efficiency of the resource. A team of five should have an
213 * efficiency of 5.0 */
216 /// The daily costs of this resource.
219 /// KoTrus ID, ID by which the resource is known to KoTrus.
222 /// The list of standard working or opening hours for the resource.
223 QList<Interval>* workingHours[7];
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
232 ShiftSelectionList shifts;
234 /// List of all intervals the resource is not available.
235 QList<Interval> vacations;
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.
245 /// Scoring of planned usages of the resource.
246 Booking** planScoreboard;
247 /// Scoring of actual usages of the resource.
248 Booking** actualScoreboard;