def test_min_max_x(): fig = Figure() fig.with_colors = False fig.set_x_limits(min_=0, max_=1) fig.plot([-1, -0.5, -0, 0.5, 1, 1.5], [-1, -0.5, -0, 0.5, 1, 1.5]) print(fig.show()) expected = ' | 0 0.1250000 0.2500000 0.3750000 0.5000000 0.6250000 0.7500000 0.8750000 1 ' assert expected == fig.show().split('\n')[-1]
def test_max_x(): fig = Figure() fig.with_colors = False fig.set_x_limits(max_=1) fig.plot([-1, -0.5, -0, 0.5, 1, 1.5], [-1, -0.5, -0, 0.5, 1, 1.5]) print(fig.show()) expected = ' | -1.200000 -0.925000 -0.650000 -0.375000 -0.100000 0.1750000 0.4500000 0.7250000 1 ' assert expected == fig.show().split('\n')[-1]
def test_min_x(): fig = Figure() fig.with_colors = False fig.set_x_limits(min_=0) fig.plot([-1, -0.5, -0, 0.5, 1, 1.5], [-1, -0.5, -0, 0.5, 1, 1.5]) print(fig.show()) expected = ' | 0 0.2062500 0.4125000 0.6187500 0.8250000 1.0312500 1.2375000 1.4437500 1.6500000' assert expected == fig.show().split('\n')[-1]
def test_date_min_max_x(): fig = Figure() fig.with_colors = False day = orig_datetime.timedelta(days=1) now = orig_datetime.datetime(2018, 1, 16, 11, 9, 42, 100) x = [now + i * day for i in range(6)] fig.set_x_limits(min_=x[0], max_=x[-1]) fig.plot(x, [-1, -0.5, -0, 0.5, 1, 1.5]) print(fig.show()) expected = ' | 16T11:09 17T02:09 17T17:09 18T08:09 18T23:09 19T14:09 20T05:09 20T20:09 21T11:09 ' assert expected == fig.show().split('\n')[-1]
def create_chart(scriptpath, args): timerange = str(args.dayrange) interval = "" filename = scriptpath + timerange + "range_" + interval + "interval.json" urllib3.disable_warnings() if not path.isfile(filename) or ( time() - path.getmtime(filename)) / 60 > 15 or args.force: url = "https://bitcoincharts.com/charts/chart.json?m=bitstampUSD&SubmitButton=Draw&r={0}&i={1}"\ .format(timerange, interval) with open(filename, "w") as file: dump(requests.get(url, verify=False).json(), file) with open(filename, "r") as file: response = load(file) zipped = list(zip(*response)) timestamps = zipped[0] weighted = zipped[7] openprice = weighted[0] closeprice = weighted[-1] change = (closeprice - openprice) / openprice if change > 0: color = custom_text_color((38, 200, 0)) else: color = custom_text_color((255, 43, 0)) print(f'Current price: ${closeprice:.2f}, {color}{change:.2%}{ENDC}') if args.log: weighted = [log(i) for i in weighted] fig = Figure() fig.width = int(args.width) fig.height = int(args.height) fig.x_axis_round = 2 fig.set_x_limits(min_=min(timestamps), max_=max(timestamps)) fig.set_y_limits(min_=min(weighted), max_=max(weighted)) fig.y_label = "USD/BTC" fig.color_mode = 'byte' fig.y_axis_transform = lambda x: "${:,.2f}".format(x) if args.log: fig.y_axis_transform = lambda x: "${:,.2f}".format(exp(x)) fig.x_axis_transform = lambda x: '{:%m-%d-%y}'.format( datetime.fromtimestamp(x)) fig.plot(timestamps, weighted, lc=2, label="Bitcoin price") print(fig.show(legend=True)) print('Data provided by bitcoincharts [{0}]'.format( "http://bitcoincharts.com/")) print('Last Updated {:.2} minutes ago'.format( (time() - path.getmtime(filename)) / 60))
def plot_ram(self, show_legend=False) -> str: """ Creates a str with a histogram that can be printed to the command line. :param show_legend: Shows a legend :return: str """ ram = [ ram.size_update / 1000 # convert to MB for ram in self.image_size_events ] dates = [ram.time_stamp for ram in self.image_size_events] if len(ram) == 0: return "" # No memory usage detected if len(ram) == 1: return str(f"Single memory update found:\n" f"Memory usage on the {dates[0]} " f"was updated to {ram[0]} MB\n") # else fig = Figure() fig.y_ticks_fkt = lambda x, y: self.mean_y_value(ram, x, y) fig.width = 55 fig.height = 15 fig.set_x_limits(min_=min(dates)) min_ram = int(min(ram)) # raises error if not casted fig.set_y_limits(min_=min_ram) fig.y_label = "Usage [MB]" fig.x_label = "Time" # this will use the self written function _ # num_formatter, to convert the y-label to int values fig.register_label_formatter(float, _int_formatter) fig.plot(dates, ram, lc='green', label="Continuous Graph") fig.scatter(dates, ram, lc='red', label="Single Values") return fig.show(legend=show_legend)
def analyze(self, log_files: list_of_logs) -> log_inf_list: """ Analyze the given log files one by one. :param log_files: list of valid HTCondor log files :return: list with information of each log file """ logging.info('Starting the analyze mode') if not log_files: raise_value_error("No files to analyze") result_list = list() # create progressbar, do not redirect output with Progress(transient=True, redirect_stdout=False, redirect_stderr=False) as progress: task = progress.add_task("Analysing...", total=len(log_files)) for file in log_files: progress.update(task, advance=1) result_dict = dict() logging.debug(f"Analysing the HTCondor log file: {file}") msg = f"[green]Job analysis of: {file}[/green]" result_dict["description"] = msg job_dict, res_dict, time_dict, \ ram_history, occurred_errors = self.log_to_dict(file) if job_dict: result_dict["execution-details"] = job_dict if time_dict: result_dict["times"] = time_dict if res_dict: result_dict["all-resources"] = \ self.manage_thresholds(res_dict) # show HTCondor errors if occurred_errors: result_dict["errors"] = occurred_errors # managing the ram history if ram_history: ram = np.array(ram_history.get('Image size updates')) dates = np.array(ram_history.get('Dates')) if ram_history and len(ram) > 1: fig = Figure() fig.width = 55 fig.height = 15 fig.set_x_limits(min_=min(dates)) min_ram = int(min(ram)) # raises error if not casted fig.set_y_limits(min_=min_ram) fig.y_label = "Usage" fig.x_label = "Time" # this will use the self written function _ # num_formatter, to convert the y-label to int values fig.register_label_formatter(float, _int_formatter) fig.plot(dates, ram, lc='green', label="Continuous Graph") fig.scatter(dates, ram, lc='red', label="Single Values") result_dict["ram-history"] = fig.show( legend=self.show_legend) elif ram_history: msg = f"Single memory update found:\n" \ f"Memory usage on the {dates[0]} " \ f"was updatet to {ram[0]} MB" result_dict["ram-history"] = msg if self.show_list: job_spec_id = self.get_job_spec_id(file) if 'htc-err' in self.show_list: result_dict['htc-err'] = self.htcondor_stderr( job_spec_id + self.ext_err) if 'htc-out' in self.show_list: result_dict['htc-out'] = self.htcondor_stdout( job_spec_id + self.ext_out) result_list.append(result_dict) return result_list