Пример #1
0
def test_server_additional_config(host):
    hostname = host.backend.get_hostname()
    version = get_version(hostname)
    if get_distribution(hostname) == 'centos':
        configfile = '/var/lib/pgsql/{version}/data/postgresql.conf'
    else:
        configfile = '/etc/postgresql/{version}/main/postgresql.conf'
    f = host.file(configfile.format(version=version)).content_string
    lines = f.split('\n')
    assert "shared_preload_libraries = 'pg_stat_statements'" in lines
    assert "log_filename = 'postgresql-%F.log'" in lines
def test_databases(host, name, expected_db):
    hostname = host.backend.get_hostname()
    sql = ("SELECT datname,datcollate,datctype FROM pg_database "
           "WHERE datname='%s'" % name)
    with host.sudo('postgres'):
        out = host.check_output('psql postgres -c "%s" -At' % sql)

    if get_distribution(hostname) == 'centos':
        lang = 'en_US'
    else:
        lang = 'C'
    assert out == expected_db.format(lang=lang)
Пример #3
0
def test_server_log_file_name(host):
    # Check previous day too in case this is run at midnight
    hostname = host.backend.get_hostname()
    version = get_version(hostname)
    if get_distribution(hostname) == 'centos':
        logdir = '/var/lib/pgsql/{version}/data/pg_log'
    else:
        logdir = '/var/lib/postgresql/{version}/main/pg_log'
    date1 = datetime.today()
    date0 = date1 - timedelta(days=1)
    logdir = logdir.format(version=version)
    file1 = '%s/postgresql-%s.log' % (logdir, date1.strftime('%F'))
    file0 = '%s/postgresql-%s.log' % (logdir, date0.strftime('%F'))
    assert host.file(file1).is_file or host.file(file0).is_file
Пример #4
0
def get_num_unique_combos(data_dir, keys):
    """
    Get number of occurrences for a property combination.
    """
    for input_file in glob.glob('%s/*.*' % data_dir):
        with open(input_file, 'rb') as f:
            data=pickle.load(f)
            grouped_by_props=defaultdict(list)
            for doc_id, doc_data in data.items():
                for part_id, part_props in doc_data.items():
                    k=utils.create_key(part_props, keys)
                    grouped_by_props[k].append(part_id)
        print(input_file)
        print('Number of unique combinations:', len(grouped_by_props.keys()))
        print('Distribution', json.dumps(utils.get_distribution(grouped_by_props), sort_keys=True))
def test_server_listen(host):
    hostname = host.backend.get_hostname()
    version = get_version(hostname)
    if get_distribution(hostname) == 'centos':
        configfile = '/var/lib/pgsql/{version}/data/postgresql.conf'
    else:
        configfile = '/etc/postgresql/{version}/main/postgresql.conf'
    with host.sudo():
        value = configfile.format(version=version)
        f = host.file(value).content_string

    count_listen_addresses = 0
    for line in f.split('\n'):
        if match(r'\s*listen_addresses', line):
            count_listen_addresses += 1
            listen_addresses = line
    assert count_listen_addresses == 1

    assert listen_addresses == "listen_addresses = localhost"
Пример #6
0
def get_voltage_distributions(lines):
    differences = []
    curr_voltage = 0
    max_voltage = max([lines[i] for i in range(len(lines))])
    lines.append(max_voltage + 3)
    print(lines)
    while curr_voltage <= max_voltage:
        min_diff = None
        min_idx = None
        tmp_voltage = curr_voltage
        for i in range(len(lines)):
            #print (curr_voltage, lines[i])
            if curr_voltage < lines[i] <= curr_voltage + 3:
                #print ("Valid voltage: {v}".format(v = lines[i]))
                if (min_diff is None or lines[i] - curr_voltage < min_diff):
                    min_diff = lines[i] - curr_voltage
                    min_idx = i
                    tmp_voltage = lines[i]
        curr_voltage = tmp_voltage
        #print(lines[min_idx], min_diff)
        differences.append(min_diff)
    #print(differences)

    return get_distribution(differences)
Пример #7
0
# verify that encoder + legitimate channel + decoder makes no error
print("verify the concatenation of encoder, uniform channel and decoder")
verify_encoder_channel_decoder(uniform_error_channel, 1)

print("\nTASK 4\n")

#here I am supposing that the input messages are uniformly distributed
marginal_u = np.ones(8) / 8
conditional = np.zeros((8, 2**7))

for i, u in tqdm(enumerate(product([0, 1], [0, 1], [0, 1]))):
    u = np.array(u)
    #keep this high enough so we are sure that there is one
    #sample for each of the possible z
    unique, counts = get_distribution(u, 10**5)

    cond_prob = counts / np.sum(counts)
    uniques = [np_to_number(uni) for uni in unique]
    conditional[i, uniques] = cond_prob

joint = compute_joint(conditional, marginal_u)
marginal_z = compute_marginal_z(joint)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X = np.arange(2**3)
Y = np.arange(2**7)
X, Y = np.meshgrid(X, Y)
ax.plot_surface(X,
                Y,