annotate PerfsDb/TestResult.py @ 608:ba06331ac8dd

new test for issue #219
author Alain Mazy <am@osimis.io>
date Wed, 24 Jan 2024 13:23:29 +0100
parents 85a2074f8794
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
1 import time
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
2 import statistics
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
3 from orthancRestApi import OrthancClient
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
4
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
5 class TestResult:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7 def __init__(self, name: str):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
8 self.minTimeInMs = 0
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
9 self.maxTimeInMs = 0
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10 self.averageTimeInMs = 0
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
11 self.name = name
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12 self._durations = []
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 def add(self, durationInMs: float):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 self._durations.append(durationInMs)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
17 def compute(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
19 if len(self._durations) >= 2:
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
20 mean = statistics.mean(self._durations)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
21 stdDev = statistics.stdev(self._durations)
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
23 # remove outliers
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
24 cleanedDurations = [x for x in self._durations if (x > mean - 2*stdDev) and (x < mean + 2*stdDev)]
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
25
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
26 self.averageTimeInMs = statistics.mean(cleanedDurations)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
27 self.minTimeInMs = min(cleanedDurations)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
28 self.maxTimeInMs = max(cleanedDurations)
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
29 elif len(self._durations) == 1:
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
30 self.averageTimeInMs = self._durations[0]
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
31 self.minTimeInMs = self._durations[0]
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
32 self.maxTimeInMs = self._durations[0]
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
33 else:
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
34 raise ArithmeticError # you need at least one measure !
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
35
169
85a2074f8794 measuring orthanc startup time
am@osimis.io
parents: 156
diff changeset
36
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
37
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
38 def __str__(self):
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
39 return "{name:<40}: {avg:>8.2f} ms {min:>8.2f} ms {max:>8.2f} ms".format(
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
40 name=self.name,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
41 avg = self.averageTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
42 min=self.minTimeInMs,
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
43 max=self.maxTimeInMs
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
44 )