Example #1
0
 def get(request):
     experiment_id = request.query_params['id']
     experiment = Experiment.objects.get(pk=experiment_id)
     progress = experiment.progress
     all_iter = progress.iteration * experiment.runs_number
     actual_iter = progress.last_iter_number + progress.run_number * progress.iteration
     progress_percent = float(actual_iter / all_iter)
     time = (all_iter - actual_iter) * progress.mean_time
     progress_data = ExperimentUtils.ProgressData(time, progress_percent)
     str_progress_data = ExperimentUtils.get_json_progress(progress_data)
     data = json.loads(str_progress_data)
     return Response(status=status.HTTP_200_OK, data=data)
Example #2
0
    def put(request, format=None):
        name_list = ["names", "data", "test", "xml"]
        user = request.user
        username = user.username
        groups = list(user.groups.values_list('name', flat=True))
        if '3_exp_data' not in groups:
            return Response(status=status.HTTP_403_FORBIDDEN, data="Not enough permissions!")
        file_list = request.FILES.getlist('file')
        name_file = list()
        for file in file_list:
            name = file._name
            extension = name.rsplit(".")[1]
            if extension not in name_list:
                return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                data="Wrong file extension! Page accept only *.xml, *.data, *.test, *.names")

            path = "users/" + username + "/" + name
            name = ExperimentUtils.generate_file_name(path)
            name_file.append(name.split("/")[-1])
            # todo need to check it
            with open(name, 'wb') as f:
                for chunk in file.chunks():
                    f.write(chunk)
            data = ",".join(name_file)
        return Response(status=status.HTTP_200_OK, data=f'Add file/files with name: {data}')
Example #3
0
def create_config_file(data: ConfigFile, config_file_path: str, user_dir: str) -> str:
    with open(config_file_path, "r") as file:
        read_lines = file.read().replace('\n', '')
    config = xmltodict.parse(read_lines)
    config['MLPExperiment']['MLPClassification']['@Runs'] = data.runs
    # config['MLPExperiment']['MLPClassification']['MLPClassifiers']['MLPClassifier']['MLPParam']['MLPSubParam'] = data.runs
    # config['MLPExperiment']['MLPClassification']['@Runs'] = data.runs
    # config['MLPExperiment']['MLPClassification']['@Runs'] = data.runs
    mlp_param_: List[dict] = config['MLPExperiment']['MLPClassification']['MLPClassifiers']['MLPClassifier']['MLPParam']
    attribute_dict: dict = data.__dict__
    for i in mlp_param_:
        if i.get("@Name") == 'parallelizationOMP':
            sub_param: List[dict] = i.get("MLPSubParam")
            for param in sub_param:
                if param.get("@Name").lower() in attribute_dict:
                    if attribute_dict.get(param.get("@Name").lower()):
                        param['@Value'] = 'yes'
                    else:
                        param['@Value'] = 'no'
            i['MLPSubParam'] = sub_param
        if i.get("@Name") in attribute_dict:
            i['@Value'] = str(attribute_dict.get(i.get("@Name")))
    config['MLPExperiment']['MLPClassification']['MLPClassifiers']['MLPClassifier']['MLPParam'] = mlp_param_
    unparsed = xmltodict.unparse(config, pretty=True)
    file_name = user_dir + "/" + data.name + ".xml"
    name = ExperimentUtils.generate_file_name(file_name)
    with open(name, "w") as file:
        file.write(unparsed)
    if file_name != name:
        return "File with that name exist -> create file with new name: " + name.split("/")[2]
    return "File created with name: " + name.split("/")[2]
Example #4
0
def create_experiment_file_copy(experiment: Experiment, username: str, option: int) -> None:
    if option == 0:
        path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/{experiment.config_file_name}'
        new_path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/old_{experiment.config_file_name}'
        name = ExperimentUtils.generate_file_name(new_path)
        os.rename(path, name)
    if option == 1:
        path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/{experiment.data_file_name}.data'
        new_path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/old_{experiment.data_file_name}.data'
        name = ExperimentUtils.generate_file_name(new_path)
        os.rename(path, name)
    if option == 2:
        path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/{experiment.data_file_name}.names'
        new_path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/old {experiment.data_file_name}.names'
        name = ExperimentUtils.generate_file_name(new_path)
        os.rename(path, name)
    if option == 3:
        path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/{experiment.data_file_name}.test'
        new_path = f'{settings.BASE_USERS_DIR}{username}/{str(experiment.id)}_{experiment.name}/old {experiment.data_file_name}.test'
        name = ExperimentUtils.generate_file_name(new_path)
        os.rename(path, name)
Example #5
0
    def get(request):
        experiment_id = request.query_params['id']
        run_number: int = int(request.query_params['runNumber'])
        error = ('Finished', 'Error')
        experiment = Experiment.objects.get(pk=experiment_id)
        if experiment.status not in error:
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data="Experiment is not finished yet")
        path = experiment.result_directory_path + "/out/"
        only_files = [f for f in listdir(path) if isfile(join(path, f))]
        filename: str = ""
        for name in only_files:
            number_ = "RUN" + str(run_number)
            if number_ in name and name.endswith(".txt"):
                filename = name
                break
        tree = ExperimentUtils.get_tree(path + filename)
        print(tree)
        tree_without_line = tree.replace("| ", "")
        obj = json.loads(tree_without_line)

        return Response(status=status.HTTP_200_OK, data=obj)
Example #6
0
    def post(request):
        user = request.user
        groups = list(user.groups.values_list('name', flat=True))
        if '3_exp_data' not in groups:
            return Response(status=status.HTTP_403_FORBIDDEN, data="Not enough permissions!")
        username: str = user.username
        filename: str = request.data['filename']
        new_name: str = request.data['new_name']
        path: str = settings.BASE_USERS_DIR + username + "/" + filename
        file_extension = filename.rsplit(".", 1)[1]
        new_path = settings.BASE_USERS_DIR + username + "/" + new_name + "." + file_extension
        if len(new_name.rsplit(".", 1)) >= 2:
            new_file_extension = new_name.rsplit(".", 1)[1]
            if new_file_extension == file_extension:
                new_path = settings.BASE_USERS_DIR + username + "/" + new_name

        if isfile(path):
            if isfile(new_path):
                new_path = ExperimentUtils.generate_file_name(new_path)
            rename(path, new_path)
            return Response(status=status.HTTP_200_OK, data=f'Successfully change file name to: {new_name}')
        else:
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data="Cannot change file name")
Example #7
0
 def post(request):
     user = request.user
     username = user.username
     experiment_id = request.query_params['id']
     experiment = Experiment.objects.get(pk=experiment_id)
     change_xml_params_and_model(experiment, True)
     progress = experiment.progress
     progress.mean_time = 0
     progress.run_number = 0
     progress.last_iter_number = 0
     progress.save()
     path = settings.BASE_USERS_DIR + username + "/" + str(experiment.id) + "_" + experiment.name
     file_path = path + '/out_old'
     new_out_path = ExperimentUtils.generate_dir_name(file_path)
     os.rename(path + '/out', new_out_path)
     mkdir(path + '/out')
     config_file_path = experiment.result_directory_path + "/" + experiment.config_file_name
     logger.debug(f'Config file used in celery task run {config_file_path}')
     experiment.status = "In queue"
     res = gdt_run.delay(config_file_path, experiment.id)
     experiment.task_id = res.id
     experiment.save()
     return Response(status=status.HTTP_200_OK, data="Successfully rerun experiment")
Example #8
0
def copy_experiment_files(old_path: str, new_path: str):
    os.mkdir(new_path)
    ExperimentUtils.copytree(old_path, new_path)
Example #9
0
def copy_out_folder(experiment: Experiment, username: str) -> None:
    path = settings.BASE_USERS_DIR + username + "/" + str(experiment.id) + "_" + experiment.name
    old_out_path = path + '/out_old'
    new_out_path = ExperimentUtils.generate_dir_name(old_out_path)
    os.rename(old_out_path, new_out_path)
    mkdir(path + '/out')