Beispiel #1
0
def test_sql_queries(function: Callable):
    """
    Проверка SQL запроса на корректность
    :param function: функция, возвращаюшая SQL запрос
    """
    filename = f'./results/{function.__name__}'
    orig_values = utils.read_pickled(filename)

    query = function()
    if type(query) != str:
        pytest.fail(
            f'Ваша функция {function.__name__} должна возвращать SQL запрос в виде строки'
        )
    if 'select' not in query.lower():
        pytest.fail(
            f'Запрос функции {function.__name__} должна быть SELECT запросом, но вместо этого там "{query}"'
        )

    try:
        results, columns = utils.execute_query(query)
    except Exception as e:
        pytest.fail(
            f'Непредвиденная ошибка во время выполнения запроса функции {function.__name__} '
            f'! Получена ошибка: "{e}"')
        return

    try:
        utils.compare_results(results, orig_values)
    except ValueError as e:
        pytest.fail(f'Неверный ответ для функции {function.__name__} ! {e}')
    except Exception as e:
        pytest.fail(
            f'Непредвиденная ошибка во время проверки результата функции {function.__name__}'
        )
def get_accuracy(datasets):
    accuracy = {}
    for dname in datasets:

        ground_truth = []
        predicted = []

        data = datasets[dname]
        for image_path, label in tqdm(data["gen"], total=data["len"]):

            image = get_image_file_object(image_path)
            job = computervision_client.read_in_stream(image=image, raw=True)

            operation_id = job.headers['Operation-Location'].split('/')[-1]
            image_analysis = computervision_client.get_read_result(
                operation_id)

            while image_analysis.status in ['notStarted', 'running']:
                time.sleep(1)
                image_analysis = computervision_client.get_read_result(
                    operation_id=operation_id)

            response = image_analysis.as_dict()

            result = reformat_azure_response(response)

            ground_truth.append(label)
            predicted.append(result)

        postprocessing = datasets[dname]["postprocessing"]
        predicted = postprocessing(predicted)

        accuracy[dname] = compare_results(ground_truth, predicted)

    return accuracy
Beispiel #3
0
def get_accuracy(datasets):
    accuracy = {}
    for dname in datasets:

        ground_truth = []
        predicted = []

        data = datasets[dname]
        for image_path, label in tqdm(data["gen"], total=data["len"]):

            with open(image_path, 'br') as image_file:
                content = image_file.read()

            response = client.detect_text(Image={'Bytes': content})
            result = reformat_aws_response(response)

            ground_truth.append(label)
            predicted.append(result)

        postprocessing = datasets[dname]["postprocessing"]
        predicted = postprocessing(predicted)

        accuracy[dname] = compare_results(ground_truth, predicted)

    return accuracy
import utils

# get entropy score
utils.get_entropy_from_file('recommend.txt', False)

# Compare recommend files
utils.compare_results('recommend.txt', 'recommend_2.txt', False)

# Check recs duplication
utils.check_recs_duplication('recommend.txt', False)
                    ]],
                    tablefmt="psql",
                ))

            pd.DataFrame(
                results_dict[data_i][learner_name][encoder_name]
                ["grid_results"]).to_csv(
                    "./results_regression/grid_results/MAEvsMSE{}_{}.csv".
                    format(f"{learner_name}_{encoder_name}_grid_results",
                           data_i[5:10]))

            if encoder_name != "te":

                pvalue = compare_results(
                    results_dict[data_i][learner_name]["te"]["grid_results"],
                    results_dict[data_i][learner_name][encoder_name]
                    ["grid_results"],
                )
                print(
                    f"p-value of wilcoxon test with {encoder_name}: {pvalue}")

    # Add Results
    resultados.append([
        data_i.split("/")[1],
        # Scores
        results_dict[data_i]["lm"]["te"]["train_mae"],
        results_dict[data_i]["lm"]["te"]["test_mae"],
        results_dict[data_i]["lm"]["te"]["train_mse"],
        results_dict[data_i]["lm"]["te"]["test_mse"],
        results_dict[data_i]["lm"]["pe"]["train_mae"],
        results_dict[data_i]["lm"]["pe"]["test_mae"],
Beispiel #6
0
                ");")[0].split(",")[0:2]
            # car desc is just text of the html
            car_desc = soup_descs[car_idx].get_text(' ').strip()
            # calculate distance between user coords and station coords from infos
            distance = utils.get_distance(user_coords, [
                station_stored_infos['Longitude'],
                station_stored_infos['Latitude']
            ])
            slot["cars"].append({
                "Name": station_name,
                "distance": distance,
                "description": car_desc
            })
        new_slots[id_slot] = slot

flag_new, new_slots = utils.compare_results(new_slots, old_slots)

# save the new json file containing most recent slots locally or in Gdrive
if "gdrive_results" in os.environ.keys():
    gdrive_conn.save_byte_file(new_slots, results_fileid)
else:
    json.dump(new_slots, json_file, indent=4, separators=(',', ': '))

# send mail if something new happened
if flag_new:
    pprint.pprint(new_slots)
    # if we pass a list (stringyfied), convert it to list again
    to_email = os.environ["communauto_mailto"]
    if '[' in to_email:
        to_email = ast.literal_eval(to_email)
    utils.send_mail(new_slots, to_email)