
# injected:
testRunCis = testRuns.getPreviousRuns(testRun, 5)

# now get the result event from each of the testruns
all_responsetimes = []
print ""
for t in testRunCis:
  eventsInRun = t.getEvents()
  for ev in eventsInRun:
    if ev.type == 'performanceResult':
      all_responsetimes.append(float(ev.get('meanResponseTime.total')))

print 'previous responsetime results', all_responsetimes
avg_responsetime = 0
if len(all_responsetimes) > 0:
  avg_responsetime = sum(all_responsetimes) / len(all_responsetimes)
else:
  print "WARNING avg responsetime could not be computed. Its length is zero"

last_responsetime = 0
import time
time.sleep(1) # delays for 1 seconds to get consistency in store. Yes this is debatable.
for ev in events:
  if ev.type == 'performanceResult':
    last_responsetime = float(ev.get('meanResponseTime.total'))

success = (float(last_responsetime) * 1.1) > avg_responsetime
print "success: ", success, "(float(last_responsetime) * 1.1) is: ", (float(last_responsetime) * 1.1), "should be larger than", avg_responsetime
resultHolder.setResult(success)