Skip to content

Commit 337f101

Browse files
committed
use enum for result
1 parent e732e26 commit 337f101

20 files changed

+414
-847
lines changed

atf_core/scripts/analyser.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import rostest
99
import sys
1010
import time
11+
import traceback
1112
import unittest
1213
import yaml
1314

@@ -78,11 +79,13 @@ def __init__(self, package_name, test_generation_config_file = "atf/test_generat
7879
break
7980
except Exception as e:
8081
print "general Exception in ATF analyser", type(e), e
82+
print traceback.format_exc()
8183
count_error += 1
8284
continue
8385
bar.update(j)
8486
except Exception as e:
8587
print "FATAL exception in bag file", type(e), e
88+
print traceback.format_exc()
8689
continue
8790
bar.finish()
8891

@@ -178,18 +181,15 @@ def aggregate_results(self, atf_result):
178181
for tl_test in tl_tests.keys():
179182
#print " tl_test=", tl_test
180183
metric_result = MetricResult()
181-
started = True
182-
finished = True
184+
status = TestblockStatus.SUCCEEDED
183185
groundtruth_result = True
184186
groundtruth_error_message = ""
185187
details = []
186188
for test in mbt[metric][testblock].keys():
187189
if test.startswith(tl_test):
188-
# aggregate started/stopped from every metric_result
189-
if not mbt[metric][testblock][test].started:
190-
started = False
191-
if not mbt[metric][testblock][test].finished:
192-
finished = False
190+
# aggregate status SUCCEEDED from every metric_result
191+
if mbt[metric][testblock][test].status != TestblockStatus.SUCCEEDED:
192+
status = TestblockStatus.ERROR
193193

194194
# aggregate data from every metric_result
195195
data = mbt[metric][testblock][test].data
@@ -219,8 +219,7 @@ def aggregate_results(self, atf_result):
219219

220220
metric_result.name = mbt[metric][testblock][test].name
221221
metric_result.mode = MetricResult.SPAN_MEAN # aggregated metrics are always SPAN_MEAN
222-
metric_result.started = started
223-
metric_result.finished = finished
222+
metric_result.status = status
224223
# metric_result.series is set above
225224
metric_result.data.stamp = stamp
226225
metric_result.data.data = metrics_helper.get_mean(metric_result.series)

atf_core/src/atf_core/atf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def stop(self, testblock, metric_result = None):
9292
else:
9393
rospy.loginfo("no user result set for testblock \'%s\'"%testblock)
9494
metric_result = MetricResult()
95-
metric_result.groundtruth.error_message = "!!USER ERROR!!: no user result set for testblock %s"%testblock # TODO use from global field (same as in atf.stop())
9695

9796
rospy.loginfo("stopping testblock \'%s\'"%testblock)
9897
trigger = TestblockTrigger()

atf_core/src/atf_core/testblock.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
from atf_core import ATFAnalyserError
4-
from atf_msgs.msg import TestblockResult, TestblockStatus
4+
from atf_msgs.msg import TestblockResult, TestblockStatus, Groundtruth
55

66
class Testblock:
77
def __init__(self, name, metric_handles, recorder_handle):
@@ -12,7 +12,6 @@ def __init__(self, name, metric_handles, recorder_handle):
1212
self.trigger = None
1313
self.timestamp = None
1414
self.exception = None
15-
self.atf_started = False
1615
self.status = None
1716

1817
def get_result(self):
@@ -35,11 +34,11 @@ def get_result(self):
3534
testblock_result.results.append(metric_result)
3635

3736
# aggregate result
38-
if metric_result.groundtruth.result != None and not metric_result.groundtruth.result:
37+
if metric_result.groundtruth.result != None and metric_result.groundtruth.result != Groundtruth.SUCCEEDED:
3938
testblock_result.result = False
4039
testblock_result.error_message += "\n - metric '%s': %s"%(metric_result.name, metric_result.groundtruth.error_message)
4140
#print testblock_result.groundtruth_error_message
42-
if testblock_result.result == None and metric_result.groundtruth.result:
41+
if testblock_result.result == None and metric_result.groundtruth.result == Groundtruth.SUCCEEDED:
4342
testblock_result.result = True
4443

4544
if testblock_result.result == None:

atf_metrics/src/atf_metrics/calculate_interface.py

Lines changed: 23 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python
2-
import copy
32
import math
43
import rospy
54

65
from atf_core import ATFAnalyserError, ATFConfigurationError
76
from atf_msgs.msg import Api
8-
from atf_msgs.msg import MetricResult, Groundtruth, KeyValue, DataStamped
7+
from atf_msgs.msg import MetricResult, Groundtruth, KeyValue, DataStamped, TestblockStatus
98
from atf_metrics import metrics_helper
109

1110
class CalculateInterfaceParamHandler:
@@ -61,29 +60,25 @@ def __init__(self, name, testblock_name, params, mode, series_mode):
6160
Class for calculating the interface type.
6261
"""
6362
self.name = name
64-
self.started = False
65-
self.finished = False
66-
self.active = False
63+
self.testblock_name = testblock_name
64+
self.status = TestblockStatus()
6765
self.groundtruth = Groundtruth()
6866
self.groundtruth.available = True
6967
self.groundtruth.data = 100 # this is the max score
7068
self.groundtruth.epsilon = 0 # no deviation from max score allowed
71-
self.testblock_name = testblock_name
7269
self.mode = mode
7370
self.series_mode = series_mode
7471
self.series = []
75-
self.data = DataStamped()
72+
7673
self.interface_details = {}
7774
self.api_dict = {}
7875
self.params = params
7976

8077
def start(self, status):
81-
self.active = True
82-
self.started = True
78+
self.status = status
8379

8480
def stop(self, status):
85-
self.active = False
86-
self.finished = True
81+
self.status = status
8782

8883
def pause(self, status):
8984
pass
@@ -93,13 +88,14 @@ def purge(self, status):
9388

9489
def update(self, topic, msg, t):
9590
# get data if testblock is active
96-
if self.active:
91+
if self.status.status == TestblockStatus.ACTIVE:
9792
if topic == "/atf/api" and msg.testblock_name == self.testblock_name:
9893
self.api_dict = self.msg_to_dict(msg)
9994
interface_data, self.interface_details = self.calculate_data_and_details()
100-
self.data.stamp = t
101-
self.data.data = interface_data
102-
self.series.append(copy.deepcopy(self.data)) # FIXME handle fixed rates
95+
data = DataStamped()
96+
data.stamp = t
97+
data.data = interface_data
98+
self.series.append(data) # FIXME handle fixed rates
10399

104100
def msg_to_dict(self, msg):
105101
api_dict = {}
@@ -196,78 +192,32 @@ def get_result(self):
196192
metric_result = MetricResult()
197193
metric_result.name = self.name
198194
metric_result.mode = self.mode
199-
metric_result.started = self.started # FIXME remove
200-
metric_result.finished = self.finished # FIXME remove
195+
metric_result.status = self.status.status
201196
metric_result.series = []
202197
metric_result.groundtruth.available = self.groundtruth.available
203198
metric_result.groundtruth.data = self.groundtruth.data
204199
metric_result.groundtruth.epsilon = self.groundtruth.epsilon
205200

206-
if not self.started:
207-
error_message = "testblock %s never started"%self.testblock_name
208-
#print error_message
209-
metric_result.groundtruth.result = False
210-
metric_result.groundtruth.error_message = error_message
211-
return metric_result
212-
213-
if not self.finished:
214-
error_message = "testblock %s never stopped"%self.testblock_name
215-
#print error_message
216-
metric_result.groundtruth.result = False
217-
metric_result.groundtruth.error_message = error_message
201+
if self.status.status != TestblockStatus.SUCCEEDED:
202+
metric_result.groundtruth.result = Groundtruth.FAILED
203+
metric_result.groundtruth.error_message = metrics_helper.extract_error_message(self.status)
218204
return metric_result
219205

220206
# check if result is available
221207
if len(self.series) == 0:
222208
# let the analyzer know that this test failed
223-
metric_result.groundtruth.result = False
209+
metric_result.groundtruth.result = Groundtruth.FAILED
224210
metric_result.groundtruth.error_message = "testblock %s stopped without result"%self.testblock_name
225211
return metric_result
226212

227213
# at this point we're sure that any result is available
228214

229-
# calculate metric data
215+
# set series
230216
if self.series_mode != None:
231217
metric_result.series = self.series
232-
if metric_result.mode == MetricResult.SNAP:
233-
metric_result.data = self.series[-1] # take last element from self.series for data and stamp
234-
metric_result.min = metric_result.data
235-
metric_result.max = metric_result.data
236-
metric_result.mean = metric_result.data.data
237-
metric_result.std = 0.0
238-
elif metric_result.mode == MetricResult.SPAN_MEAN:
239-
metric_result.min = metrics_helper.get_min(self.series)
240-
metric_result.max = metrics_helper.get_max(self.series)
241-
metric_result.mean = metrics_helper.get_mean(self.series)
242-
metric_result.std = metrics_helper.get_std(self.series)
243-
metric_result.data.data = metric_result.mean # take mean for data
244-
metric_result.data.stamp = self.series[-1].stamp # take stamp from last element in self.series for stamp
245-
elif metric_result.mode == MetricResult.SPAN_MIN:
246-
metric_result.min = metrics_helper.get_min(self.series)
247-
metric_result.max = metrics_helper.get_max(self.series)
248-
metric_result.mean = metrics_helper.get_mean(self.series)
249-
metric_result.std = metrics_helper.get_std(self.series)
250-
metric_result.data = metric_result.min
251-
elif metric_result.mode == MetricResult.SPAN_ABSMIN:
252-
metric_result.min = metrics_helper.get_absmin(self.series)
253-
metric_result.max = metrics_helper.get_absmax(self.series)
254-
metric_result.mean = metrics_helper.get_mean(self.series)
255-
metric_result.std = metrics_helper.get_std(self.series)
256-
metric_result.data = metric_result.min
257-
elif metric_result.mode == MetricResult.SPAN_MAX:
258-
metric_result.min = metrics_helper.get_min(self.series)
259-
metric_result.max = metrics_helper.get_max(self.series)
260-
metric_result.mean = metrics_helper.get_mean(self.series)
261-
metric_result.std = metrics_helper.get_std(self.series)
262-
metric_result.data = metric_result.max
263-
elif metric_result.mode == MetricResult.SPAN_ABSMAX:
264-
metric_result.min = metrics_helper.get_absmin(self.series)
265-
metric_result.max = metrics_helper.get_absmax(self.series)
266-
metric_result.mean = metrics_helper.get_mean(self.series)
267-
metric_result.std = metrics_helper.get_std(self.series)
268-
metric_result.data = metric_result.max
269-
else: # invalid mode
270-
raise ATFAnalyserError("Analysing failed, invalid mode '%s' for metric '%s'."%(metric_result.mode, metric_result.name))
218+
219+
# calculate metric data
220+
[metric_result.data, metric_result.min, metric_result.max, metric_result.mean, metric_result.std] = metrics_helper.calculate_metric_data(metric_result.name, metric_result.mode, self.series)
271221

272222
# fill details as KeyValue messages
273223
details = []
@@ -277,14 +227,14 @@ def get_result(self):
277227
# evaluate metric data
278228
if metric_result.groundtruth.available: # groundtruth available
279229
if math.fabs(metric_result.groundtruth.data - metric_result.data.data) <= metric_result.groundtruth.epsilon:
280-
metric_result.groundtruth.result = True
230+
metric_result.groundtruth.result = Groundtruth.SUCCEEDED
281231
metric_result.groundtruth.error_message = "all OK"
282232
else:
283-
metric_result.groundtruth.result = False
233+
metric_result.groundtruth.result = Groundtruth.FAILED
284234
metric_result.groundtruth.error_message = "groundtruth missmatch: %f not within %f+-%f"%(metric_result.data.data, metric_result.groundtruth.data, metric_result.groundtruth.epsilon)
285235

286236
else: # groundtruth not available
287-
metric_result.groundtruth.result = True
237+
metric_result.groundtruth.result = Groundtruth.SUCCEEDED
288238
metric_result.groundtruth.error_message = "all OK (no groundtruth available)"
289239

290240
return metric_result

0 commit comments

Comments
 (0)