def test_set_axes(self): chart = leather.Chart() chart.set_x_axis(leather.Axis(ticks=[0, 4, 8])) chart.set_y_axis(leather.Axis(ticks=[3, 6, 9])) chart.add_dots(self.data1) svg = self.render_chart(chart) self.assertTickLabels(svg, 'left', ['3', '6', '9']) self.assertTickLabels(svg, 'bottom', ['4', '8', '0'])
def test_ticks(self): chart = leather.Chart() chart.add_dots(self.data) axis = leather.Axis(ticks=6) chart.set_x_axis(axis) svg = self.render_chart(chart) self.assertTickLabels(svg, 'bottom', ['2', '4', '6', '8', '10', '0'])
def test_ticks(self): chart = leather.Chart() chart.add_dots(self.data) axis = leather.Axis(ticks=[-12, 0, 17, 44, 87, 99]) chart.set_x_axis(axis) svg = self.render_chart(chart) self.assertTickLabels(svg, 'bottom', ['-12', '17', '44', '87', '99', '0'])
def test_tick_formatter(self): chart = leather.Chart() chart.add_dots(self.data) def test_formatter(value, i, count): return '%i+' % (value * 10) axis = leather.Axis(tick_formatter=test_formatter) chart.set_x_axis(axis) svg = self.render_chart(chart) self.assertTickLabels(svg, 'bottom', ['25+', '50+', '75+', '100+', '0+'])
def main(): verbose = True out_dir = "" root = tkinter.Tk() root.withdraw() num_drives = input("How many drives would you like to process?\n>>> ") int_received = False while not int_received: try: num_drives = int(num_drives) int_received = True except ValueError: print("ERROR: You must enter an integer") num_drives = input( "How many drives would you like to process?\n>>> ") if num_drives <= 0: print("Too Few Drives") exit(0) lpo_drive_list = [] for drive_num in range(num_drives): txt_files_parsed = 0 html_files_parsed = 0 drive_name = input("What would you like to call drive #" + str(drive_num) + "?\n>>> ") lpo = LPOSeries() lpo.title = drive_name root.filename = filedialog.askopenfilenames( initialdir="C:\\Users\\Jake\\Desktop\\Projects\\Regression Testing", title=("Choose files for " + drive_name), filetypes=(('all files', '*.*'), )) # if we don't get a filename just bail if root.filename: infile_names = root.filename if out_dir == "": match = re.search('(.*)\.', infile_names[0]) dirs = match.group(1).split("/") dirs.pop() out_dir = '\\'.join(dirs) + "\\Processed" pathlib.Path(out_dir).mkdir(parents=True, exist_ok=True) else: exit(0) eztool_present = False sft_present = False for infile in infile_names: if infile[-4:] == ".txt": eztool_present = True text = read_file(infile, verbose) ezt_list = build_ezt_list(text, verbose) txt_files_parsed += 1 for ezt in ezt_list: lpo.add_ezt_cycle(ezt) elif infile[-4:] == "html": sft_present = True text = read_file(infile, verbose) sft_list = build_sft_list(text, verbose) html_files_parsed += 1 for sft in sft_list: lpo.add_sft_cycle(sft) if not eztool_present: ezt = EZTCycle("1", "1", "1") lpo.add_ezt_cycle(ezt) if not sft_present: sft = SFTCycle("1", "1", "1") message_string = (str(txt_files_parsed) + " EZTool files and " + str(html_files_parsed) + " SFT files were parsed for " + drive_name + "\n") if verbose: print(message_string) lpo_drive_list.append(lpo) for lpo in lpo_drive_list: lpo.generate_power_cycle_list() chart_list = [] for lpo in lpo_drive_list: power_cycle_file = out_dir + "\\" + lpo.title + "_AllCycles.txt" failing_cycle_file = out_dir + "\\" + lpo.title + "_ImportantCycles.txt" chart_file = out_dir + "\\" + lpo.title + "_Chart.svg" with open(power_cycle_file, "w") as f: f.write(PowerCycle.get_display_header()) for cycle in lpo.cycles: f.write(cycle.get_display_line()) with open(failing_cycle_file, "w") as f: f.write(PowerCycle.get_display_header()) for cycle in lpo.failed_cycles: f.write(cycle.get_display_line()) sft_data = lpo.get_sft_points() ezt_data = lpo.get_ezt_points() chart = leather.Chart(lpo.title) chart.add_dots(ezt_data, name="EZTool FWBootTime", radius=1.5) chart.add_dots(sft_data, name="SFT Detect Time", radius=1.5) x_axis = leather.Axis(name="Power Cycle") y_axis = leather.Axis(name="Detect Time in Seconds") chart.set_x_axis(x_axis) chart.set_y_axis(y_axis) chart.to_svg(chart_file, 500, 400) chart_list.append(chart) if len(chart_list) > 1: grid_file = out_dir + "\\" for lpo in lpo_drive_list: grid_file += lpo.title + "_" grid_file += "_Grid.svg" grid = leather.Grid() grid.add_many(chart_list) grid.to_svg(grid_file, 800, 600) max_file = out_dir + "\\" + "MaxPowerOnTimes.txt" max_text = "Max Times per Drive:\n" for lpo in lpo_drive_list: lpo.find_max_cycle() max_text += lpo.title + ": " + str(round(lpo.max_cycle.max_time(), 2)) + "\n" with open(max_file, "w") as f: f.write(max_text) if num_drives != 0: print("Processed Data stored in the directory:\n\n" + out_dir) else: print("You chose to process 0 drives, program exiting") Ju.wait()
import leather import math import csv chart = leather.Chart('Income vs. health') with open('data.csv', 'r') as csvfile: reader = csv.DictReader(csvfile) data = list(reader) def size_dot_by_area(x, y, i): return math.sqrt(int(data[i]['population'])) / 1000 dots = leather.Dots('rgba(0,0,0,0.5)', radius=size_dot_by_area) series = leather.Series(data, dots, x=lambda row, i: math.log(float(row['income'])), y=lambda row, i: float(row['health'])) chart.add_series(series) chart.set_x_axis(leather.Axis(name='Log GDP per capita')) chart.set_y_axis(leather.Axis(name='Life expectancy in years')) chart.to_svg('chart.svg')