def load_json(self, json_str): """ Load project from JSON. :param json_str: JSON-formatted string representing a project. :return: Nothing """ # project_list elements are tuples containing presentation name and file contents # The format is ["presentationname", ["file1", "file2", ...]"] project_list = json.loads(json_str) # create the real presentations by replacing file list with Presentation objects presentation_list = [] for presentation_tuple in project_list: name = presentation_tuple[0] files = presentation_tuple[1] paths = [] for file in files: path = fh.absolute_path(PathConstants.ABSOLUTE_MEDIA_FOLDER, file) paths.append(path) pres = Presentation(name) pres.presentation_filenames = paths presentation_list.append((name, pres)) self.presentations = presentation_list
def run_onion_hulls(samples): times = [] types = [1, 2, 3] names = { 1: "GrahamScan", 2: "JarvisMarch", 3: "QuickHull" } for x in types: ax = OnionHull(x) ax.peel(samples) print("\nCompleted Onion Hull using %s" % (names[x])) print("Inputs : ", len(samples)) print("Peels Generated: ", len(ax.peels)) print("Execution time : ", ax.exec_time) save_file = "Outputs/output_onion_%s.txt"%(names[x]) print("Saving output to - %s "%(save_file)) FileHandler.saveOutput(save_file, ax.peels) # ax.plot() times.append(ax.exec_time) return times
def run_skylines(samples): times = [] types = [1, 2, 3] names = { 1: "GrahamScan", 2: "JarvisMarch", 3: "QuickHull" } for x in types: ax = SkyLine(x) ax.match(samples) print("\nCompleted SkyLine using %s" % (names[x])) print("Inputs : ", len(samples)) print("Points in Hull: ", len(ax.hull)) print("Points in Skyline: ", len(ax.skyline)) print("Execution time : ", ax.exec_time) save_file = "Outputs/output_skylines_%s.txt"%(names[x]) print("Saving output to - %s "%(save_file)) sk_result = sorted(ax.skyline[:, 2]) FileHandler.saveOutput(save_file, sk_result) times.append(ax.exec_time) return times
def verify_project(self, project, media_path=PathConstants.ABSOLUTE_MEDIA_FOLDER): """ Verifies that all required files exist, filetypes are supported and filenames are valid. :param project: The project to be verified :return: True if valid, False otherwise """ available_files = fh.get_filenames_from_path(media_path) for presentation in project.presentations: for filepath in presentation[1].presentation_filenames: filename = fh.get_filename_only(filepath) if fh.check_filename(filename) is False: Logger.debug("Master: Invalid filename: %s ", filename) return False if not filename in available_files: Logger.debug("Master: File not found in media folder: %s", filename) return False if not supp.extension_is_supported( fh.get_type_extension(filename)): Logger.debug("Master: Invalid file type: %s", filename) return False return True
def dump_json(self): """ Returns a json-formatted string representing the project. Presentation status is lost, only the presentation name and file contents are saved. This is intended to be used for saving the project as a file. :return: A json representation of the project. """ # A list with presentation-objects replaced with the list of files in that project list_presentations = [] for tuple in self.presentations: filenames = [] for path in tuple[1].presentation_filenames: filenames.append(fh.get_filename_only(path)) list_presentations.append((tuple[0], filenames)) return json.dumps(list_presentations)
def run_hulls_only(samples): times = [] jm = JarvisMarch() jm.fit(samples) print("\nCompleted running Jarvis March on the Data") print("Inputs : ", len(samples)) print("Length of hull: ", len(jm.hull)) print("Execution time : ", jm.exec_time) print("Hull(%s): " % len(jm.hull), jm.hull) print("Saving output to - %s "%("Outputs/results_JarvisMarch.txt")) jm_result = sorted(jm.hull[:, 2]) FileHandler.saveOutput("Outputs/results_JarvisMarch.txt", jm_result) # jm.plotter(samples) times.append(jm.exec_time) gs = GrahamScan() gs.fit(samples) print("\nCompleted running Graham Scan on the Data") print("Inputs : ", len(samples)) print("Length of hull: ", len(gs.hull)) print("Execution time : ", gs.exec_time) print("Hull(%s): " % len(gs.hull), gs.hull) print("Saving output to - %s "%("Outputs/results_GrahamScan.txt")) gs_result = sorted(gs.hull[:, 2]) # gs.plot(samples) FileHandler.saveOutput("Outputs/results_GrahamScan.txt", gs_result) times.append(gs.exec_time) qh = QuickHull() qh.fit(samples) print("\nCompleted running Quick Hull on the Data") print("Inputs : ", len(samples)) print("Length of hull: ", len(qh.hull)) print("Execution time : ", qh.exec_time) print("Hull(%s): " % len(qh.hull), qh.hull) print("Saving output to - %s "%("Outputs/results_QuickHull.txt")) qh_result = sorted(qh.hull[:, 2]) FileHandler.saveOutput("Outputs/results_QuickHull.txt", qh_result) # qh.plot() times.append(qh.exec_time) return times
def read_file(name): test_cases, samples = FileHandler.readFile(name) return samples