예제 #1
0
 def from_json_file(file_dir: str, file_name: str) -> "EventStream":
     """
     :param file_dir: full path to containing directory for the file
     :param file_name: name of file and extension to load data from
     :return: EventStream from json file
     """
     if file_name is None:
         file_name = io.get_json_file(file_dir)
         if file_name is None:
             result = EventStream("Empty")
             result.append_error("JSON file to load EventStream from not found.")
             return result
     json_data = io.json_file_to_dict(os.path.join(file_dir, f"{file_name}.json"))
     if "name" in json_data.keys():
         result = EventStream(json_data["name"], json_data["schema"], FileSystemSaveMode.DISK, file_dir)
         result.metadata = json_data["metadata"]
         result.timestamps_metadata = json_data["timestamps_metadata"]
         result.set_errors(RedVoxExceptions.from_dict(json_data["errors"]))
         result.read_from_dir(json_data["file_path"])
     else:
         result = EventStream("Empty")
         result.append_error(f"Loading from {file_name} failed; missing EventStream name.")
     return result