コード例 #1
0
def average_time():
    '''
       Doc string relativo ao código
    '''
    try:
        writer = csv.writer(open("relatorio_average.csv", 'w'))
        writer.writerow([
            'service_id', 'average_latency_proxy', 'average_latency_gateway',
            'average_latency_request'
        ])

        consumer_table = pd.read_csv('general_data.csv')
        data_sum = consumer_table[[
            'service_id', 'latency_proxy', 'latency_gateway',
            'latency_request', 'count'
        ]].groupby('service_id').sum()

        i = 0
        for data in range(len(data_sum.index)):
            writer.writerow([
                data_sum.index[i], data_sum.iat[i, 0] / data_sum.iat[i, 3],
                data_sum.iat[i, 1] / data_sum.iat[i, 3],
                data_sum.iat[i, 2] / data_sum.iat[i, 3]
            ])

            i += 1
        return status_msg.sucess_data_200("Generated Average")
    except Exception as err:
        return status_msg.error_500(err)
コード例 #2
0
def requests_by_consumer():
    '''
       Doc string relativo ao código
    '''
    try:
        consumer_table = pd.read_csv('general_data.csv')
        consumers = consumer_table[['consumer_id',
                                    'count']].groupby('consumer_id').sum()
        consumers.to_csv('relatorio_requests_by_consumer.csv')
        return status_msg.sucess_data_200("Generated Requests by Consumer")
    except Exception as err:
        return status_msg.error_500(err)
コード例 #3
0
def populate():
    '''
       Popula o banco de dados
    '''
    try:
        datas = open('logs.txt').readlines()
        for data in datas:
            data_new = json.loads(data)
            WorkData.objects.create(
                consumer_id=data_new['authenticated_entity']['consumer_id']
                ['uuid'],
                service_id=data_new['service']['id'],
                latency_proxy=data_new['latencies']['proxy'],
                latency_gateway=data_new['latencies']['gateway'],
                latency_request=data_new['latencies']['request'])

        return status_msg.sucess_data_200("Consumers and Services populated")
    except Exception as err:
        transaction.set_rollback(True)
        return status_msg.error_500(err)
コード例 #4
0
def to_csv():
    '''
       Gera CSV
    '''
    try:
        writer = csv.writer(open("general_data.csv", 'w'))
        writer.writerow([
            'consumer_id', 'service_id', 'latency_proxy', 'latency_gateway',
            'latency_request', 'count'
        ])

        datas = WorkData.objects.prefetch_related()

        for data in chunked_queryset_iterator(datas, 20):
            writer.writerow([
                data.consumer_id, data.service_id, data.latency_proxy,
                data.latency_gateway, data.latency_request, 1
            ])

        return status_msg.sucess_data_200("Generated CSV")
    except Exception as err:
        return status_msg.error_500(err)