<commit_before># -*- coding: utf-8 -*-

import os
import gevent
import json
import signal
import logging

from locust import runners, events


logger = logging.getLogger(__name__)


class TimeOutException(Exception): pass


class LoadTest(object):
    '''
    The LoadTest runs the load test and returns statistics
    '''
    def __init__(self, settings):
        self.settings = settings
        signal.signal(signal.SIGALRM, self.sig_alarm_handler)
        gevent.signal(signal.SIGTERM, self.sig_term_handler)

    def stats(self):
        '''
        Returns the statistics from the load test in JSON
        '''
        statistics = {
            'success': {},
            'fail': {},
            'num_requests': runners.locust_runner.stats.num_requests,
            'num_requests_success': 0,
            'num_requests_fail': 0,
            'locust_host': runners.locust_runner.host
        }

        for name, value in runners.locust_runner.stats.entries.items():
            statistics['success'][name[0]] = {
                'request_type': name[1],
                'num_requests': value.num_requests,
                'min_response_time': value.min_response_time,
                'median_response_time': value.median_response_time,
                'max_response_time': value.max_response_time,
                'total_rps': value.total_rps,
                'total_rpm': value.total_rps * 60
            }<commit_msg>Adding avg_response_time to stats<commit_after># -*- coding: utf-8 -*-

import os
import gevent
import json
import signal
import logging

from locust import runners, events


logger = logging.getLogger(__name__)


class TimeOutException(Exception): pass


class LoadTest(object):
    '''
    The LoadTest runs the load test and returns statistics
    '''
    def __init__(self, settings):
        self.settings = settings
        signal.signal(signal.SIGALRM, self.sig_alarm_handler)
        gevent.signal(signal.SIGTERM, self.sig_term_handler)

    def stats(self):
        '''
        Returns the statistics from the load test in JSON
        '''
        statistics = {
            'success': {},
            'fail': {},
            'num_requests': runners.locust_runner.stats.num_requests,
            'num_requests_success': 0,
            'num_requests_fail': 0,
            'locust_host': runners.locust_runner.host
        }

        for name, value in runners.locust_runner.stats.entries.items():
            statistics['success'][name[0]] = {
                'request_type': name[1],
                'num_requests': value.num_requests,
                'min_response_time': value.min_response_time,
                'median_response_time': value.median_response_time,
                'avg_response_time': value.avg_response_time,
                'max_response_time': value.max_response_time,
                'total_rps': value.total_rps,
                'total_rpm': value.total_rps * 60
            }
{'fraction_non_alphanumeric': 0.10122699386503067, 'fraction_numerical': 0.004771642808452625, 'mean_word_length': 2.2502768549280177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444324', 'n_tokens_mistral': 854, 'n_tokens_neox': 814, 'n_words': 177}