def parse_json()

in scheme_adapters/pso_adapter/pso_adapter.py [0:0]


    def parse_json(self, file_name):
        file = open(self.damoos_path + "/scheme_adapters/pso_adapter/json_files/" + file_name, "r")
        json_parsed = json.load(file)

        self.num_dim = json_parsed["num_dimension"]
        if type(self.num_dim) != int:
            raise Exception("Integer expected.")

        self.metrics = json_parsed["metrics"]
        self.validate_json_list(self.metrics)

        self.workload = json_parsed["workload"]
        self.validate_json_string(self.workload)

        self.score_func_path = json_parsed["score_function"]
        self.validate_json_string(self.score_func_path)

        self.ranges = json_parsed["range"]
        if not isinstance(self.ranges, dict):
            raise Exception("Dictionary expected.")

        count = 0
        for key, value in self.ranges.items():
            if isinstance(value, list):
                if key == "action":
                    raise Exception("Action is a non-tunable parameter. Please specify only one action.")
                else:
                    count += 1
                    if count > self.num_dim:
                        raise Exception("Number of dimensions and number of ranges given does not match.")

        self.num_runs = json_parsed["num_runs"]
        if type(self.num_runs) != int:
            raise Exception("Integer expected.")

        self.total_runtime = json_parsed["total_runtime"]
        if type(self.total_runtime) != int:
            raise Exception("Integer expected.")

        self.cache_read_enabled = json_parsed["read_from_cache"]
        if type(self.cache_read_enabled) != bool:
            raise Exception("Boolean expected")

        self.cache_write_enabled = json_parsed["write_to_cache"]
        if type(self.cache_write_enabled) != bool:
            raise Exception("Boolean expected")

        self.cache_option = json_parsed["cache_option"]
        self.validate_json_string(self.cache_option)

        self.cache_file = json_parsed["cache_file"]
        self.validate_json_string(self.cache_file)