Skip to main content
summaryrefslogtreecommitdiffstats
blob: 692916d3fe374eb79f21833581a04bd71ce58fb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.search.engine.internal.tagger;

import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.search.engine.ITagItemStatistics;
import org.eclipse.osee.framework.search.engine.ITaggerStatistics;
import org.eclipse.osee.framework.search.engine.TagListenerAdapter;
import org.eclipse.osee.framework.search.engine.utility.SearchTagDataStore;

/**
 * @author Roberto E. Escobar
 */
public class TaggerStatistics extends TagListenerAdapter implements Cloneable, ITaggerStatistics {
   public static final TaggerStatistics EMPTY_STATS = new TaggerStatistics(null);
   private static final TaskStatistics DEFAULT_TASK_STATS = new TaskStatistics(-1, -1, -1);

   private long averageQueryIdWaitTime;
   private long averageAttributeProcessingTime;
   private long averageQueryIdProcessingTime;
   private long totalTags;
   private int totalAttributesProcessed;
   private int totalQueryIdsProcessed;
   private long totalQueryIdWaitTime;
   private long totalQueryIdProcessingTime;
   private long totalAttributeProcessingTime;
   private long longestQueryIdWaitTime;
   private long longestQueryIdProcessingTime;
   private TaskStatistics longestTask;
   private TaskStatistics mostTags;
   private final SearchTagDataStore tagDataStore;

   public TaggerStatistics(SearchTagDataStore tagDataStore) {
      this.tagDataStore = tagDataStore;
      clear();
   }

   public void clear() {
      this.averageQueryIdWaitTime = 0;
      this.totalTags = 0;
      this.averageAttributeProcessingTime = 0;
      this.averageQueryIdProcessingTime = 0;
      this.totalAttributesProcessed = 0;
      this.totalQueryIdsProcessed = 0;
      this.totalQueryIdWaitTime = 0;
      this.totalAttributeProcessingTime = 0;
      this.totalQueryIdProcessingTime = 0;
      this.longestQueryIdWaitTime = 0;
      this.longestQueryIdProcessingTime = 0;
      this.longestTask = DEFAULT_TASK_STATS;
      this.mostTags = DEFAULT_TASK_STATS;
   }

   @Override
   public long getLongestQueryIdWaitTime() {
      return longestQueryIdWaitTime;
   }

   @Override
   public long getLongestQueryIdProcessingTime() {
      return longestQueryIdProcessingTime;
   }

   @Override
   public long getAverageQueryIdWaitTime() {
      return averageQueryIdWaitTime;
   }

   @Override
   public int getTotalQueryIdsProcessed() {
      return this.totalQueryIdsProcessed;
   }

   @Override
   public long getAverageQueryIdProcessingTime() {
      return averageQueryIdProcessingTime;
   }

   @Override
   public long getAverageAttributeProcessingTime() {
      return averageAttributeProcessingTime;
   }

   @Override
   public long getTotalTags() {
      return totalTags;
   }

   @Override
   public int getTotalAttributesProcessed() {
      return totalAttributesProcessed;
   }

   @Override
   public long getLongestAttributeProcessingTime() {
      return longestTask.getProcessingTime();
   }

   @Override
   public ITagItemStatistics getLongestTask() {
      return longestTask;
   }

   @Override
   public ITagItemStatistics getMostTagsTask() {
      return mostTags;
   }

   @Override
   public long getTagsInSystem() throws OseeDataStoreException {
      return tagDataStore != null ? tagDataStore.getTotalTags() : 0;
   }

   @Override
   public long getTotalQueryIdsInQueue() throws OseeDataStoreException {
      return tagDataStore != null ? tagDataStore.getTotalQueryIdsInQueue() : 0;
   }

   @Override
   protected ITaggerStatistics clone() throws CloneNotSupportedException {
      TaggerStatistics other = (TaggerStatistics) super.clone();
      other.averageAttributeProcessingTime = this.averageAttributeProcessingTime;
      other.averageQueryIdProcessingTime = this.averageQueryIdProcessingTime;
      other.averageQueryIdWaitTime = this.averageQueryIdWaitTime;
      other.totalTags = this.totalTags;
      other.totalAttributesProcessed = this.totalAttributesProcessed;
      other.totalQueryIdsProcessed = this.totalQueryIdsProcessed;
      other.totalAttributeProcessingTime = this.totalAttributeProcessingTime;
      other.totalQueryIdProcessingTime = this.totalQueryIdProcessingTime;
      other.totalQueryIdWaitTime = this.totalQueryIdWaitTime;
      other.longestQueryIdWaitTime = this.longestQueryIdWaitTime;
      other.longestQueryIdProcessingTime = this.longestQueryIdProcessingTime;
      other.longestTask = this.longestTask.clone();
      other.mostTags = this.mostTags.clone();
      return other;
   }

   @Override
   public void onAttributeTagComplete(int queryId, long gammaId, int totalTags, long processingTime) {
      this.totalTags += totalTags;
      this.totalAttributesProcessed++;
      this.totalAttributeProcessingTime += processingTime;
      this.averageAttributeProcessingTime = this.totalAttributeProcessingTime / this.totalAttributesProcessed;

      TaskStatistics newTask = new TaskStatistics(gammaId, totalTags, processingTime);
      if (newTask.getProcessingTime() > this.longestTask.getProcessingTime()) {
         this.longestTask = newTask;
      }
      if (newTask.getTotalTags() > this.mostTags.getTotalTags()) {
         this.mostTags = newTask;
      }
   }

   @Override
   public void onTagQueryIdTagComplete(int queryId, long waitTime, long processingTime) {
      this.totalQueryIdsProcessed++;
      this.totalQueryIdWaitTime += waitTime;
      this.totalQueryIdProcessingTime += processingTime;

      this.averageQueryIdWaitTime = totalQueryIdWaitTime / this.totalQueryIdsProcessed;
      this.averageQueryIdProcessingTime = totalQueryIdProcessingTime / this.totalQueryIdsProcessed;

      this.longestQueryIdProcessingTime = Math.max(this.longestQueryIdProcessingTime, processingTime);
      this.longestQueryIdWaitTime = Math.max(this.longestQueryIdWaitTime, waitTime);
   }
}

Back to the top