Пример #1
0
def get_data():
    data_details = dict()
    for d in delay:
        info = {'latency': [], 'pdr': [], 'goodput': []}
        path_json_data = my.path_media + "json_file/" + tech + "/relay_" + str(
            relay[index_relay]) + "/x/delay_XXX_" + str(
            d) + ".json"

        data = my.open_file_and_return_data(path=path_json_data)
        data_details[d] = dict()

        for item in elements:
            if tech == 'ble_output':
                info['latency'].append(data[item]['statistic_']['latency']['mean'])
                info['pdr'].append(data[item]['statistic_']['pdr'])
                info['goodput'].append(data[item]['statistic_']['goodput_1'])
            elif tech == 'ble_wifi_output':
                info['latency'].append(data[item]['statistic_']['total']['latency']['mean'])
                info['pdr'].append(data[item]['statistic_']['total']['pdr'])
                info['goodput'].append(data[item]['statistic_']['total']['goodput_1'])
            else:
                raise ValueError('tech incorrect!')

        out_latency = my.intervalli_di_confidenza(info['latency'])
        # my_confidential_interval_(info['latency'])
        out_pdr = my.intervalli_di_confidenza(info['pdr'])
        out_goodput = my.intervalli_di_confidenza(info['goodput'])

        data_details[d][terms[0]] = out_latency['mean']
        data_details[d][terms[1]] = out_latency['m_e']
        data_details[d][terms[2]] = out_pdr['mean']
        data_details[d][terms[3]] = out_pdr['m_e']
        data_details[d][terms[4]] = out_goodput['mean']
        data_details[d][terms[5]] = out_goodput['m_e']

    return data_details
Пример #2
0
def statistics(data, run):
    mex = data['_mex']
    latency_ble = dict()
    outcomes = {
        'S': 0,
        'R': 0,
        'L': 0,
        'L1': 0,
        'E': 0
    }  # L comprende anche E --> L1 + E = L
    end_test = dt.datetime.strptime(data['_info']['start'],
                                    '%Y-%m-%d %H:%M:%S.%f')
    status_time = dt.datetime.strptime(data['_info']['start'],
                                       '%Y-%m-%d %H:%M:%S.%f')
    for index, list_of_value in mex.items():
        length = len(list_of_value)
        outcomes['S'] += 1
        if length == 1:
            outcomes['L'] += 1
            outcomes['L1'] += 1
        elif length == 2:
            outcomes['E'] += 1
            outcomes['L'] += 1
        elif length == 3:
            if 'ble' in list_of_value[(length - 1)]:
                outcomes['R'] += 1
                latency_ble[int(index)] = list_of_value[(length -
                                                         1)]['ble']['latency']
                status_time = dt.datetime.strptime(
                    list_of_value[(length - 1)]['ble']['status_time'],
                    '%Y-%m-%d %H:%M:%S.%f')
            else:
                print("---")
                outcomes['L'] += 1
        else:
            print("- [" + str(len(list_of_value)) + "]", index, " -- ",
                  list_of_value)

        if status_time > end_test:
            end_test = status_time

    counting = outcomes['E'] + outcomes['L1']
    if counting != outcomes['L']:
        raise Exception("Error counting:[E+L1->L] {} -- [{}] -- {}".format(
            'ble', counting, outcomes))

    counting = outcomes['S'] - outcomes['R'] - outcomes['L']
    if counting != 0:
        raise Exception("Error counting: {} -- [{}] -- {}".format(
            'ble', counting, outcomes))
    else:
        print(outcomes)

    l_ble = list(latency_ble.values())
    ble_ = my.intervalli_di_confidenza(dataset=l_ble)

    start_test = dt.datetime.strptime(data['_info']['start'],
                                      '%Y-%m-%d %H:%M:%S.%f')
    time_test = end_test - start_test
    # TODO BLE
    pdr_ble = outcomes['R'] / outcomes['S']
    goodput_ble = (outcomes['R'] *
                   2) / time_test.total_seconds()  # 2 byte di dati utili

    # TODO Save data about LATENCY, PDR, GOODPUT
    my_dictionary[str(run)] = {
        '_info': data['_info'],
        'mex_': {
            'S': outcomes['S'],
            'R': outcomes['R'],
            'L': outcomes['L'],
            'E': outcomes['E']
        },
        'statistic_': {
            'sample_size': len(l_ble),
            'pdr': pdr_ble,
            'goodput': goodput_ble,
            'latency': {
                'mean': ble_['mean'],
                'std': ble_['std'],
                'm_e': ble_['m_e'],
                'low': ble_['low'],
                'up': ble_['up']
            }
        }
    }
    return latency_ble
Пример #3
0
def calculate_statistics(dataframe, times):
    outcomes = {
        'ble_1': {
            'latency': 0,
            'std': 0,
            'm_e': 0,
            'low': 0,
            'up': 0,
            'pdr': 0,
            'goodput': 0
        },
        'ble_wifi_2': {
            'latency': 0,
            'std': 0,
            'm_e': 0,
            'low': 0,
            'up': 0,
            'pdr': 0,
            'goodput': 0
        },
        'wifi_3': {
            'latency': 0,
            'std': 0,
            'm_e': 0,
            'low': 0,
            'up': 0,
            'pdr': 0,
            'goodput': 0
        },
        'ble_wifi_4': {
            'latency': 0,
            'std': 0,
            'm_e': 0,
            'low': 0,
            'up': 0,
            'pdr': 0,
            'goodput': 0
        },
        'ble_5': {
            'latency': 0,
            'std': 0,
            'm_e': 0,
            'low': 0,
            'up': 0,
            'pdr': 0,
            'goodput': 0
        }
    }
    for step in dataframe:
        l_ = dataframe[step]['latency']
        latency = my.intervalli_di_confidenza(dataset=l_)
        pdr = dataframe[step]['R'] / dataframe[step]['S']
        goodput = (dataframe[step]['R'] * 2) / 60  # TODO time test 1 minute
        outcomes[step]['latency'] = latency['mean']
        outcomes[step]['std'] = latency['std']
        outcomes[step]['m_e'] = latency['m_e']
        outcomes[step]['low'] = latency['low']
        outcomes[step]['up'] = latency['up']
        outcomes[step]['pdr'] = pdr
        outcomes[step]['goodput'] = goodput

    for k, v in outcomes.items():
        outcomes[k]['S'] = dataframe[k]['S']
        outcomes[k]['R'] = dataframe[k]['R']
        outcomes[k]['L'] = dataframe[k]['L']
        outcomes[k]['E'] = dataframe[k]['E']
    return outcomes
Пример #4
0
def statistics(data, run, x):
    mex = data['_mex']
    min_index = x[str(run)]['smaller']
    max_index = x[str(run)]['bigger']
    latency_ble = dict()
    latency_wifi = dict()
    latency_total = dict()
    outcomes = {'ble': {'S': 0, 'R': 0, 'L': 0, 'E': 0},
                'wifi': {'S': 0, 'R': 0, 'L': 0, 'E': 0},
                'total': {'S': 0, 'R': 0, 'L': 0}}
    end_test = dt.datetime.strptime(x[str(run)]['time']['new_end'], '%Y-%m-%d %H:%M:%S.%f')
    for index, list_of_value in mex.items():
        ble = False
        wifi = False
        for v in list_of_value:
            if min_index <= int(index) <= max_index:
                if 'type_mex' in v and v['type_mex'] == "S":
                    outcomes['ble']['S'] += 1
                    outcomes['total']['S'] += 1
                if 'type_mex' in v and v['type_mex'] == "E":
                    outcomes['ble']['E'] += 1
                if 'type_mex' in v and v['type_mex'] == "I":
                    wifi = True
                    outcomes['wifi']['S'] += 1
                if 'type_mex' in v and v['type_mex'] == "W":
                    outcomes['wifi']['W'] += 1

                if 'ble' in v:
                    ble = True
                    outcomes['ble']['R'] += 1
                    outcomes['total']['R'] += 1
                    latency_ble[int(index)] = v['ble']['latency']
                    latency_total[int(index)] = v['ble']['latency']
                    rcv = dt.datetime.strptime(v['ble']['status_time'], '%Y-%m-%d %H:%M:%S.%f')
                    if rcv > end_test:
                        end_test = rcv
                if 'wifi' in v:
                    outcomes['wifi']['R'] += 1
                    outcomes['total']['R'] += 1
                    latency_wifi[int(index)] = v['wifi']['latency']
                    rcv = dt.datetime.strptime(v['wifi']['status_time'], '%Y-%m-%d %H:%M:%S.%f')
                    if rcv > end_test:
                        end_test = rcv
                if 'ble_wifi' in v and 'latency_1' in v['ble_wifi']:
                    latency_total[int(index)] = v['ble_wifi']['latency_1']
        if ble and wifi:
            raise Exception('Double Sent: {}'.format(index))

    outcomes['ble']['L'] = outcomes['ble']['S'] - outcomes['ble']['R'] - outcomes['ble']['E']
    outcomes['wifi']['L'] = outcomes['wifi']['S'] - outcomes['wifi']['R'] - outcomes['wifi']['L']

    outcomes['total']['L'] = outcomes['total']['S'] - outcomes['total']['R']

    if outcomes['ble']['S'] - outcomes['ble']['R'] - outcomes['ble']['L'] - outcomes['ble']['E'] != 0:
        raise Exception("Error counting: {} -- {}".format('ble', outcomes['ble']))

    if outcomes['wifi']['S'] - outcomes['wifi']['R'] - outcomes['wifi']['L'] - outcomes['wifi']['E'] != 0:
        raise Exception("Error counting: {} -- {}".format('wifi', outcomes['wifi']))

    if outcomes['total']['S'] != x[str(run)]['S'] or outcomes['total']['S'] != x[str(run)]['S'] or outcomes['total'][
        'S'] != \
            x[str(run)]['S']:
        raise Exception('Error counting: {} -- {}\n{}'.format('total', outcomes['total'], x[str(run)]))

    if len(latency_total) != outcomes['total']['R']:
        raise Exception(
            'Error counting: size_total: {} -- total_R: {}'.format(len(latency_total), outcomes['total']['R']))

    l_ble = list(latency_ble.values())
    l_wifi = list(latency_wifi.values())
    ble_ = my.intervalli_di_confidenza(dataset=l_ble)
    wifi_ = my.intervalli_di_confidenza(dataset=l_wifi)

    l_ = list(latency_total.values())
    latency_ = my.intervalli_di_confidenza(dataset=l_)

    start_test = dt.datetime.strptime(x[str(run)]['time']['new_start'], '%Y-%m-%d %H:%M:%S.%f')
    end_send = dt.datetime.strptime(x[str(run)]['time']['new_end'], '%Y-%m-%d %H:%M:%S.%f')
    time_test = abs(end_test - start_test)
    time_ = abs(end_send - start_test)

    # TODO BLE
    pdr_ble = outcomes['ble']['R'] / outcomes['ble']['S']
    goodput_ble = (outcomes['ble']['R'] * 2) / time_test.total_seconds()  # 2 byte di dati utili

    # TODO WIFI
    s_t = start_test + dt.timedelta(0, 40)  # aggiungo 40 secondi
    t_t = end_test - s_t
    pdr_wifi = outcomes['wifi']['R'] / outcomes['wifi']['S']
    goodput_wifi = (outcomes['wifi']['R'] * 2) / t_t.total_seconds()  # 2 byte di dati utili

    # TODO General
    pdr = outcomes['total']['R'] / outcomes['total']['S']
    goodput = outcomes['total']['R'] * 2 / time_test.total_seconds()  # 2 byte di dati utili
    goodput_1 = outcomes['total']['R'] * 2 / time_.total_seconds()  # 2 byte di dati utili

    h, m, s = my.convert_timedelta(time_)
    time_send_ = str(h) + ":" + str(m) + "." + str(s) + " [h:m.s]"
    h, m, s = my.convert_timedelta(time_test)
    time_test_ = str(h) + ":" + str(m) + "." + str(s) + " [h:m.s]"

    my_dictionary[str(run)] = {'_info_0': data['_info'],
                               '_info_1': {'end_sent': x[str(run)]['time']['new_end'], 'end_test': end_test,
                                           'start': x[str(run)]['time']['new_start'], 'time_send': time_send_,
                                           'time_test': time_test_},
                               'mex_': {'ble': {'S': outcomes['ble']['S'], 'R': outcomes['ble']['R'],
                                                'L': outcomes['ble']['L'], 'E': outcomes['ble']['E']},
                                        'wifi': {'S': outcomes['wifi']['S'], 'R': outcomes['wifi']['R'],
                                                 'L': outcomes['wifi']['L'], 'E': outcomes['wifi']['E']},
                                        'total': {'S': outcomes['total']['S'], 'R': outcomes['total']['R'],
                                                  'L': outcomes['total']['L']}},
                               'statistic_': {'ble': {'sample_size': len(l_ble),
                                                      'pdr': pdr_ble,
                                                      'goodput': goodput_ble,
                                                      'latency': {'mean': ble_['mean'], 'std': ble_['std'],
                                                                  'm_e': ble_['m_e'],
                                                                  'low': ble_['low'],
                                                                  'up': ble_['up']}},
                                              'wifi': {'sample_size': len(l_wifi),
                                                       'pdr': pdr_wifi,
                                                       'goodput': goodput_wifi,
                                                       'latency': {'mean': wifi_['mean'], 'std': wifi_['std'],
                                                                   'm_e': wifi_['m_e'],
                                                                   'low': wifi_['low'],
                                                                   'up': wifi_['up']
                                                                   }},
                                              'total': {'sample_size': len(l_),
                                                        'pdr': pdr,
                                                        'goodput': goodput,
                                                        'goodput_1': goodput_1,
                                                        'latency': {'mean': latency_['mean'], 'std': latency_['std'],
                                                                    'm_e': latency_['m_e'],
                                                                    'low': latency_['low'],
                                                                    'up': latency_['up']
                                                                    }}}}
    return latency_ble, latency_wifi, latency_total
Пример #5
0
def statistics(data, run, x):
    mex = data['_mex']
    min_index = x[str(run)]['smaller']
    max_index = x[str(run)]['bigger']
    latency_ble = dict()
    outcomes = {'S': 0, 'R': 0, 'L': 0, 'L1': 0, 'E': 0}
    end_test = dt.datetime.strptime(x[str(run)]['time']['new_end'], '%Y-%m-%d %H:%M:%S.%f')
    end_send = dt.datetime.strptime(x[str(run)]['time']['new_end'], '%Y-%m-%d %H:%M:%S.%f')
    for index, list_of_value in mex.items():
        for v in list_of_value:
            if min_index <= int(index) <= max_index:
                if 'type_mex' in v and v['type_mex'] == "S":
                    outcomes['S'] += 1
                if 'type_mex' in v and v['type_mex'] == "E":
                    outcomes['E'] += 1

                if 'ble' in v:
                    outcomes['R'] += 1
                    latency_ble[int(index)] = v['ble']['latency']
                    rcv = dt.datetime.strptime(v['ble']['status_time'], '%Y-%m-%d %H:%M:%S.%f')
                    if rcv > end_test:
                        end_test = rcv

    outcomes['L1'] = outcomes['S'] - outcomes['R'] - outcomes['E']
    outcomes['L'] = outcomes['S'] - outcomes['R']

    if outcomes['S'] - outcomes['R'] - outcomes['L'] != 0:
        raise Exception("Error counting: {} -- {}".format('ble', outcomes))

    if outcomes['S'] != x[str(run)]['S'] or outcomes['R'] != x[str(run)]['R'] or outcomes['L'] != x[str(run)]['L']:
        raise Exception('Error counting: {} -- {}\n{}'.format('total', outcomes, x[str(run)]))

    if len(latency_ble) != outcomes['R']:
        raise Exception(
            'Error counting: size_total: {} -- total_R: {}'.format(len(latency_ble), outcomes['R']))

    l_ble = list(latency_ble.values())
    ble_ = my.intervalli_di_confidenza(dataset=l_ble)

    start_test = dt.datetime.strptime(x[str(run)]['time']['new_start'], '%Y-%m-%d %H:%M:%S.%f')
    time_test = abs(end_test - start_test)
    time_ = abs(end_send - start_test)
    # TODO BLE
    pdr_ble = outcomes['R'] / outcomes['S']
    goodput_ble = (outcomes['R'] * 2) / time_test.total_seconds()  # 2 byte di dati utili
    goodput_ble_1 = (outcomes['R'] * 2) / time_.total_seconds()  # 2 byte di dati utili

    h, m, s = my.convert_timedelta(time_)
    time_send_ = str(h) + ":" + str(m) + "." + str(s) + " [h:m.s]"
    h, m, s = my.convert_timedelta(time_test)
    time_test_ = str(h) + ":" + str(m) + "." + str(s) + " [h:m.s]"

    my_dictionary[str(run)] = {'_info_0': data['_info'],
                               '_info_1': {'end_sent': x[str(run)]['time']['new_end'], 'end_test': end_test,
                                           'start': x[str(run)]['time']['new_start'], 'time_send': time_send_,
                                           'time_test': time_test_},
                               'mex_': {'S': outcomes['S'], 'R': outcomes['R'], 'L': outcomes['L'], 'E': outcomes['E']},
                               'statistic_': {'sample_size': len(l_ble),
                                              'pdr': pdr_ble,
                                              'goodput': goodput_ble,
                                              'goodput_1': goodput_ble_1,
                                              'latency': {'mean': ble_['mean'], 'std': ble_['std'],
                                                          'm_e': ble_['m_e'],
                                                          'low': ble_['low'],
                                                          'up': ble_['up']}}}
    return latency_ble
Пример #6
0
def statistics(data, run):
    mex = data['_mex']
    latency_ble = dict()
    latency_wifi = dict()
    latency = dict()
    outcomes = {
        'ble': {
            'S': 0,
            'R': 0,
            'L': 0,
            'E': 0
        },
        'wifi': {
            'S': 0,
            'R': 0,
            'L': 0,
            'E': 0
        },
        'total': {
            'S': 0,
            'R': 0,
            'L': 0
        }
    }
    end_test = dt.datetime.strptime(data['_info']['start'],
                                    '%Y-%m-%d %H:%M:%S.%f')
    status_time = dt.datetime.strptime(data['_info']['start'],
                                       '%Y-%m-%d %H:%M:%S.%f')
    for index, list_of_value in mex.items():
        length = len(list_of_value)
        outcomes['ble']['S'] += 1
        if length == 1:
            outcomes['ble']['L'] += 1
            outcomes['total']['L'] += 1
        elif length == 2:
            outcomes['ble']['E'] += 1
            outcomes['total']['L'] += 1
        elif length == 3:
            if 'ble' in list_of_value[(length - 1)]:
                outcomes['ble']['R'] += 1
                latency_ble[int(index)] = list_of_value[(length -
                                                         1)]['ble']['latency']
                latency[int(index)] = list_of_value[(length -
                                                     1)]['ble']['latency']
                status_time = dt.datetime.strptime(
                    list_of_value[(length - 1)]['ble']['status_time'],
                    '%Y-%m-%d %H:%M:%S.%f')
            else:
                outcomes['ble']['L'] += 1
                outcomes['wifi']['S'] += 1
                outcomes['wifi']['L'] += 1
                outcomes['total']['L'] += 1
        elif length == 4:
            outcomes['ble']['E'] += 1
            outcomes['wifi']['S'] += 1
            outcomes['wifi']['L'] += 1
            outcomes['total']['L'] += 1
        elif length == 5 or length == 6:
            if length == 6:
                outcomes['ble']['E'] += 1
            else:
                outcomes['ble']['L'] += 1
            outcomes['wifi']['S'] += 1
            outcomes['wifi']['R'] += 1
            latency_wifi[int(index)] = list_of_value[(length -
                                                      2)]['wifi']['latency']
            latency[int(index)] = list_of_value[(length -
                                                 1)]['ble_wifi']['latency_1']
            status_time = dt.datetime.strptime(
                list_of_value[(length - 1)]['ble_wifi']['receive_wifi'],
                '%Y-%m-%d %H:%M:%S.%f')
        else:
            print("- [" + str(len(list_of_value)) + "]", index, " -- ",
                  list_of_value)

        if status_time > end_test:
            end_test = status_time

    if outcomes['ble']['S'] - outcomes['ble']['R'] - outcomes['ble'][
            'L'] - outcomes['ble']['E'] != 0:
        raise Exception("Error counting: {} -- {}".format(
            'ble', outcomes['ble']))

    if outcomes['wifi']['S'] - outcomes['wifi']['R'] - outcomes['wifi'][
            'L'] - outcomes['wifi']['E'] != 0:
        raise Exception("Error counting: {} -- {}".format(
            'wifi', outcomes['wifi']))

    outcomes['total']['S'] = outcomes['ble']['S']
    outcomes['total']['R'] = outcomes['ble']['R'] + outcomes['wifi']['R']
    if outcomes['total']['S'] - outcomes['total']['R'] - outcomes['total'][
            'L'] != 0:
        raise Exception("Error counting: {} -- {}".format(
            'total', outcomes['total']))

    l_ble = list(latency_ble.values())
    l_wifi = list(latency_wifi.values())
    ble_ = my.intervalli_di_confidenza(dataset=l_ble)
    wifi_ = my.intervalli_di_confidenza(dataset=l_wifi)

    l_ = list(latency.values())
    latency_ = my.intervalli_di_confidenza(dataset=l_)

    start_test = dt.datetime.strptime(data['_info']['start'],
                                      '%Y-%m-%d %H:%M:%S.%f')
    time_test = end_test - start_test
    # TODO BLE
    pdr_ble = outcomes['ble']['R'] / outcomes['ble']['S']
    goodput_ble = (outcomes['ble']['R'] *
                   2) / time_test.total_seconds()  # 2 byte di dati utili
    # TODO WIFI
    start_test = start_test + dt.timedelta(0, 40)  # aggiungo 40 secondi
    time_test = end_test - start_test
    pdr_wifi = outcomes['wifi']['R'] / outcomes['wifi']['S']
    goodput_wifi = (outcomes['wifi']['R'] *
                    2) / time_test.total_seconds()  # 2 byte di dati utili

    # TODO General
    pdr = outcomes['total']['R'] / outcomes['total']['S']
    goodput = outcomes['total']['R'] * 2 / time_test.total_seconds(
    )  # 2 byte di dati utili

    if data['_info_2']['mex_']['double_sent'] != 0:
        raise Exception('Double Sent n. {}'.format(
            data['_info_2']['mex_']['double_sent']))

    # TODO Save data about LATENCY, PDR, GOODPUT
    my_dictionary[str(run)] = {
        '_info': data['_info'],
        'mex_': {
            'ble': {
                'S': outcomes['ble']['S'],
                'R': outcomes['ble']['R'],
                'L': outcomes['ble']['L'],
                'E': outcomes['ble']['E']
            },
            'wifi': {
                'S': outcomes['wifi']['S'],
                'R': outcomes['wifi']['R'],
                'L': outcomes['wifi']['L'],
                'E': outcomes['wifi']['E']
            },
            'total': {
                'S': outcomes['total']['S'],
                'R': outcomes['total']['R'],
                'L': outcomes['total']['L']
            }
        },
        'statistic_': {
            'ble': {
                'sample_size': len(l_ble),
                'pdr': pdr_ble,
                'goodput': goodput_ble,
                'latency': {
                    'mean': ble_['mean'],
                    'std': ble_['std'],
                    'm_e': ble_['m_e'],
                    'low': ble_['low'],
                    'up': ble_['up']
                }
            },
            'wifi': {
                'sample_size': len(l_wifi),
                'pdr': pdr_wifi,
                'goodput': goodput_wifi,
                'latency': {
                    'mean': wifi_['mean'],
                    'std': wifi_['std'],
                    'm_e': wifi_['m_e'],
                    'low': wifi_['low'],
                    'up': wifi_['up']
                }
            },
            'total': {
                'sample_size': len(l_),
                'pdr': pdr,
                'goodput': goodput,
                'latency': {
                    'mean': latency_['mean'],
                    'std': latency_['std'],
                    'm_e': latency_['m_e'],
                    'low': latency_['low'],
                    'up': latency_['up']
                }
            }
        }
    }
    return latency_ble, latency_wifi, latency