def main(): args = docopt(__doc__, version="Plot Times v0.1") output_path = args['--out'] traces = load_traces(args['<conf-file>']) # Check if all data directories actually exist for trace in traces: if not trace.data_dir.path.is_dir(): print_error(f"data directory not found: {str(trace.data_dir)}") sys.exit(1) # Setup the application app = Application(container=LabeledFileContainer( containers={trace.label: trace.data_dir for trace in traces}), selector=ExtensionFileSelector(extension=".basic.csv"), loader=TerminationTimesLoader(), processor=TerminationTimesProcessor( plotter=Plotter(trace_lines={ trace.label: trace.line for trace in traces }, output=Path(output_path + '.html')), printer=CSVPrinter(Path(output_path + '.csv')))) return app.run()
def main(): args = docopt(__doc__, version="Basic Data v0.1") conf_path = Path(args['<conf-file>']) output_path = Path(args['--out'] + ".csv") if not conf_path.is_file(): print_error(f"Configuration file was not found: {str(conf_path)}") sys.exit(1) data_sets = load_data_sets(conf_path) if not args['--ignore-non-existing']: # Make sure all data directories exist - If one does not, then exit for label, directory in data_sets.items(): if not directory.is_dir(): print_error(f"Data directory not found: {str(directory)}") sys.exit(1) # Setup the application app = Application( container=LabeledFileContainer(containers={ label: Directory(data_dir) for label, data_dir in data_sets.items() }), selector=ExtensionFileSelector(extension=".basic.csv"), loader=BasicDataLoader(), processor=BasicDataProcessor(printer=CSVPrinter(output_path))) return app.run()
def parse(eq, verbose, degree): if "=" not in eq: print_error(0, 0, 0, 0) eq = re.sub(r"\s+", ' ', eq) eq = re.sub(r"(\s\^\s)", '^', eq) eq = eq.replace("x", "X") for i, letter in enumerate(eq): if letter not in charset: print_error(0, letter, i, 1) left, degree = set_polynom_list(eq[:eq.index("=")].strip(), degree) right, degree = set_polynom_list(eq[eq.index("=") + 1:].strip(), degree) return left, right, degree
def run(self) -> None: try: print("Selecting files...") data_files = self.selector.select(self.container) print("Loading data...") data = self.loader.load(data_files) print("Processing...") self.processor.process(data) print("Completed successfully!") except ProcessingError as e: print_error(str(e)) print("Failed!")
def set_polynom_list(side, degree): error = False side_list = [] separator = re.split('[0-9X^.* ]+', side)[:-1] polynomList = re.split('[\-+=]', side) if not separator: print_error(0, 0, 0, 0) if separator[0] == "-": polynomList = re.split('[\-+=]', side)[1:] for i in range(len(separator)): power = -1 sign = True if (separator[i] == '' or separator[i] == '+') else False try: index = polynomList[i][polynomList[i].index("X^") + 2:] if len(index) == 0 or not index[0].isdigit(): error = True raise Exception() power = re.findall(r'\d+', index) if len(power) == 0: error = True raise Exception() power = int(power[0]) if power > degree: degree = power nums = re.findall(r'\d+.\d+|\d+', polynomList[i]) if len(nums) == 1: nums.append(1) factor = float(nums[0]) if nums.index(str(power)) == 1 else float( nums[1]) except: if error == False: power = 0 factor = re.findall(r'\d+.\d+|\d+', polynomList[i]) x_index = lookup_index(polynomList[i], 'X') if len(factor) > 0: factor = atof(factor[0]) else: factor = 1 if x_index != -1: format_check(polynomList[i], x_index) power = 1 else: power = 0 if error == True: print_error(polynomList[i], 0, 0, 2) new_term = Polynom(sign, polynomList[i].strip(), power, factor) new_term.check() side_list.append(new_term) return side_list, degree
def check(self): count = Counter(self.definition) numbers = len(re.findall('[^X\^ *]+', self.definition)) if count['X'] > 1 or count['*'] > 1 or count['^'] > 1: print_error(self.definition, 0, 0, 2) self.x = True if count['X'] == 1 else False if self.x == True: if count['*'] == 0 and count['^'] == 1 and numbers > 2: print_error(self.definition, 0, 0, 2) if count['*'] == 1 and count['^'] == 0 and numbers > 1: print_error(self.definition, 0, 0, 2) if count['*'] == 0 and count['^'] == 0 and numbers > 1: print_error(self.definition, 0, 0, 2) index = lookup_index(self.definition, '^') index2 = lookup_index(self.definition, 'X') if index > 0 and (index2 == -1 or index2 != index - 1): print_error(self.definition, 0, 0, 2) else: if count['^'] > 0 or count['*'] > 0 or numbers > 1: print_error(self.definition, 0, 0, 2)