2
Copyright (c) 1997-2005 Benhur Stein
4
This file is part of Paj�.
6
Paj� is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
Paj� is distributed in the hope that it will be useful, but WITHOUT ANY
12
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16
You should have received a copy of the GNU Lesser General Public License
17
along with Paj�; if not, write to the Free Software Foundation, Inc.,
18
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
/* StatArray.m created by benhur on Fri 26-Sep-1997 */
22
#include "StatArray.h"
23
#include "../General/Macros.h"
25
@interface StatStateArray : StatArray
27
CondensedEntitiesArray *condensedArray;
32
- (id)initWithName:(NSString *)theName
33
type:(PajeEntityType *)type
34
startTime:(NSDate *)start
36
filter:(PajeFilter *)f
37
entityEnumerator:(NSEnumerator *)en;
39
- (void)addEntitiesFromEnumerator:(NSEnumerator *)enumerator;
42
@implementation StatArray
44
+ (StatArray *)stateArrayWithName:(NSString *)theName
45
type:(PajeEntityType *)type
46
startTime:(NSDate *)start
48
filter:(PajeFilter *)f
49
entityEnumerator:(NSEnumerator *)en
51
return [[[StatStateArray alloc] initWithName:theName
56
entityEnumerator:en] autorelease];
59
- (id)initWithName:(NSString *)theName
60
type:(PajeEntityType *)type
61
filter:(PajeFilter *)f
65
Assign(name, theName);
66
Assign(entityType, type);
75
Assign(entityType, nil);
86
[self subclassResponsibility:_cmd];
92
[self subclassResponsibility:_cmd];
98
[self subclassResponsibility:_cmd];
104
[self subclassResponsibility:_cmd];
108
- (NSString *)subNameAtIndex:(unsigned)index
110
[self subclassResponsibility:_cmd];
114
- (NSColor *)subColorAtIndex:(unsigned)index
116
[self subclassResponsibility:_cmd];
120
- (double)subValueAtIndex:(unsigned)index
122
[self subclassResponsibility:_cmd];
130
@implementation StatStateArray
131
- (id)initWithName:(NSString *)theName
132
type:(PajeEntityType *)type
133
startTime:(NSDate *)start
134
endTime:(NSDate *)end
135
filter:(PajeFilter *)f
136
entityEnumerator:(NSEnumerator *)en
138
self = [super initWithName:theName
142
Assign(startTime, start);
143
Assign(endTime, end);
144
condensedArray = [[CondensedEntitiesArray alloc] init];
145
[self addEntitiesFromEnumerator:en];
152
Assign(condensedArray, nil);
153
Assign(startTime, nil);
154
Assign(endTime, nil);
159
- (void)addEntitiesFromEnumerator:(NSEnumerator *)enumerator
163
BOOL incomplete[100];
165
NSString *names[100];
166
double duration[100];
168
while ((entity = [enumerator nextObject]) != nil) {
171
BOOL entityIsAggregate;
172
BOOL entityIsIncomplete;
173
double entityDuration;
174
double entityDurationInSelection;
176
entityStart = [filter startTimeForEntity:entity];
177
entityEnd = [filter endTimeForEntity:entity];
178
if ([entityStart isLaterThanDate:endTime]
179
|| [entityEnd isEarlierThanDate:startTime]) {
182
//entityDuration = [filter durationForEntity:entity];
183
entityDuration = [entity duration];
184
entityIsAggregate = [filter isAggregateEntity:entity];
186
while (top >= 0 && [entityEnd isEarlierThanDate:start[top]]) {
187
if (incomplete[top] && duration[top] > 0) {
188
[condensedArray addName:names[top]
189
duration:duration[top]];
194
entityIsIncomplete = NO;
195
entityDurationInSelection = entityDuration;
196
if ([entityStart isEarlierThanDate:startTime]) {
197
entityIsIncomplete = YES;
198
entityDurationInSelection
199
-= [startTime timeIntervalSinceDate:entityStart];
201
if ([entityEnd isLaterThanDate:endTime]) {
202
entityIsIncomplete = YES;
203
entityDurationInSelection
204
-= [entityEnd timeIntervalSinceDate:endTime];
207
if (!entityIsAggregate) {
208
NSString *entityName;
209
entityName = [filter nameForEntity:entity];
211
if (top >= 0 && incomplete[top]) {
212
duration[top] -= entityDurationInSelection;
215
incomplete[top] = entityIsIncomplete;
216
start[top] = entityStart;
217
if (entityIsIncomplete) {
218
names[top] = entityName;
219
duration[top] = entityDurationInSelection;
221
double entityExclusiveDuration;
222
//entityExclusiveDuration = [filter exclusiveDurationForEntity:entity];
223
entityExclusiveDuration = [entity exclusiveDuration];
224
[condensedArray addName:entityName
225
duration:entityExclusiveDuration];
227
//condensedEntitiesCount ++;
229
double correctionFactor;
230
double correctedDuration;
231
double entityExclusiveDuration;
232
//entityExclusiveDuration = [filter exclusiveDurationForEntity:entity];
233
entityExclusiveDuration = [entity exclusiveDuration];
234
correctionFactor = entityDurationInSelection / entityDuration;
235
correctedDuration = (entityDuration - entityExclusiveDuration)
237
if (correctedDuration > entityDurationInSelection) {
238
correctedDuration = entityDurationInSelection;
240
if (top >= 0 && incomplete[top]) {
241
duration[top] -= correctedDuration;
243
// BUG: should be corrected by correctionFactor
244
[condensedArray addArray:[entity condensedEntities]];
245
//[condensedArray addArray:[filter condensedEntitiesForEntity:entity]];
246
//condensedEntitiesCount += [entity condensedEntitiesCount];
252
&& duration[top]/[endTime timeIntervalSinceDate:startTime] > 1e-5) {
253
[condensedArray addName:names[top]
254
duration:duration[top]];
263
return [endTime timeIntervalSinceDate:startTime];
268
return [self subValueAtIndex:0];
273
return [self subValueAtIndex:[self subCount] - 1];
279
return [condensedArray count];
282
- (NSString *)subNameAtIndex:(unsigned)i
284
return [condensedArray nameAtIndex:i];
287
- (NSColor *)subColorAtIndex:(unsigned)i
289
return [filter colorForName:[condensedArray nameAtIndex:i]
290
ofEntityType:entityType];
293
- (double)subValueAtIndex:(unsigned)i
295
return [condensedArray durationAtIndex:i];