def generate_report(): report = MdUtils(file_name=f'./report.md') report.new_header(level=1, title='Выделение признаков символов') report.new_line(text='Выполнил Ахманов Алексей Б18-514') report.new_line(text=f'Алфавит - {ALPHABET}') for letter in ALPHABET: letter_folder_path = f'./{folder_helper.IMAGES_FOLDER_PATH}/letter_{letter}' os.makedirs(letter_folder_path, exist_ok=True) letter_image_path = f'{letter_folder_path}/{letter}.png' letter_image = Image.new(mode=constants.GRAYSCALE_MODE, size=(FONT_SIZE, FONT_SIZE), color=WHITE) result = ImageDraw.Draw(im=letter_image, mode=constants.GRAYSCALE_MODE) result.text(xy=(0, 0), text=letter, font=FONT, fill=0, anchor='lt') letter_image = cut_empty_rows_and_cols(letter_image) letter_image.save(letter_image_path) report.new_header(level=2, title=f'Буква {letter}') report.new_line(report.new_inline_image(text=letter, path=letter_image_path)) thresholded = simple_threshold(letter_image, 100) report.new_line(text=f'Вес черного - {black_weight(thresholded)}') report.new_line(text=f'Удельный вес черного - {normalized_black_weight(thresholded)}') center = gravity_center(thresholded) report.new_line(text=f'Координаты центра масс - ({center[0]}, {center[1]})') normalized_center = normalized_gravity_center(thresholded) report.new_line(text=f'Нормированные координаты центра масс - ({normalized_center[0]}, {normalized_center[1]})') report.new_line(text=f'Центральный горизонтальный осевой момент - {central_horizontal_axial_moment(thresholded)}') report.new_line(text=f'Центральный вертикальный осевой момент - {central_vertical_axial_moment(thresholded)}') report.new_line(text=f'Нормированный центральный горизонтальный осевой момент -' f'{normalized_central_horizontal_axial_moment(thresholded)}') report.new_line(text=f'Нормированный центральный вертикальный осевой момент -' f'{normalized_central_vertical_axial_moment(thresholded)}') h_levels, h_projections = horizontal_projection(thresholded) pyplot.plot(h_levels, h_projections) pyplot.title(f'Horizontal projection {letter}') path = f'{letter_folder_path}/horizontal_projection_{letter}.png' pyplot.savefig(path) pyplot.close() report.new_line(report.new_inline_image(text=letter, path=path)) v_levels, v_projections = vertical_projection(thresholded) pyplot.plot(v_levels, v_projections) pyplot.title(f'Vertical projection {letter}') path = f'{letter_folder_path}/vertical_projection_{letter}.png' pyplot.savefig(path) pyplot.close() report.new_line(report.new_inline_image(text=letter, path=path)) report.new_line() report.create_md_file()
def generate_report(): df_final = predictionsPerSecond() explode = (0.1, 0.1, 0.1) plt.pie(df_final.Label.value_counts(), explode=explode, labels=df_final.Label.value_counts().index.to_list(), autopct='%1.1f%%', shadow=True, startangle=90) plt.title('Tiempo de uso de mascarilla') plt.savefig('predictions.png') mdFile = MdUtils( file_name='report', title='Reporte de predicción de uso correcto de mascarilla') mdFile.new_line( mdFile.new_inline_image(text='Predicciones', path='predictions.png')) mdFile.new_header(title='Tablas de resultados', level=1) mdFile.new_line('Juan Pablo Carranza Hurtado') mdFile.new_line('José Alberto Ligorría Taracena') mdFile.create_md_file() f = open("report.html", "w") f.write(markdown2.markdown_path('report.md')) f.write(pd.crosstab(df_final.Time, df_final.Label).to_html()) f.write('<h1> Cantidad de segundos de utilización de mascarilla </h1>') f.write(pd.DataFrame(df_final.Label.value_counts()).to_html()) f.close()
def test_new_inline_image(self): md_file = MdUtils(file_name="Test_file", title="") expected_image = '![image](../image.png)' created_image = md_file.new_inline_image(text='image', path='../image.png') self.assertEqual(expected_image, created_image)
def img_to_markdown(path: str) -> str: """ Creates a Markdown Image. Parameters ---------- path: str The image path. """ return MdUtils.new_inline_image(text=path, path=path)
link = "https://github.com/raymiranda/actions-craps/issues/new?title=Roll%20Some%20Dice&body=https://api.github.com/repos/raymiranda/action-craps/issues?title=Let%27s%20Roll%20Some%20Dice&body=Add%20your%20own%20comments" text = "--> We need a new shooter! <--" mdFile.new_line(mdFile.new_inline_link(link=link, text=text)) else: d = last_line.strip().replace(" ", "").split("|") point = d[2] dice = d[1].split(",") dice1 = './images/' + str(dice[0]) + '.png' dice2 = './images/' + str(dice[1]) + '.png' last_roll = re.sub("[^0-9]", "", d[0]) if "lets try to hit that" in last_saying: mdFile.new_header(level=2, title="The point is now " + str(last_roll) + "! Let's go shooter!") else: mdFile.new_header(level=2, title="Last roll was a " + str(last_roll) + "! The point is " + str(point)) mdFile.new_line(mdFile.new_inline_image(text='Dice 1', path=dice1)) mdFile.new_line(mdFile.new_inline_image(text='Dice 2', path=dice2)) link = "https://github.com/raymiranda/actions-craps/issues/new?title=Roll%20Some%20Dice&body=https://api.github.com/repos/raymiranda/action-craps/issues?title=Let%27s%20Roll%20Some%20Dice&body=Add%20your%20own%20comments" text = "--> The Dice Are Hot - Keep It Going! <-- " mdFile.new_line(mdFile.new_inline_link(link=link, text=text)) # Create a table of contents mdFile.new_table_of_contents(table_title='Contents', depth=2) mdFile.create_md_file()
under_config = {**user_yaml, **yaml.load(static, Loader=yaml.FullLoader)} with open(f"{submod}/_config.yml", 'w') as dest: documents = yaml.dump(under_config, dest) return documents def find_recent_resume(url)->str: import glob season = {'W': 4, 'F': 3, 'X': 2, 'S': 1} recent_sort = lambda r: (r[-7], r[-6], season.get(r[-5], 0)) s = max((r.split("/docs/")[1] for r in glob.glob(f"./{url}/docs/Resume_*.pdf")), key=recent_sort) return s # Generate markdowns if updategithub: mdReadMe = MdUtils(file_name='README') #include some flags mdReadMe.new_line(mdReadMe.new_inline_image(text='image', path='https://github.com/kevinfjiang/kevinfjiang/blob/master/hello_world.png')) # Read existing yamls # Intro and config logger.debug("Opening user.yml") with open(PATH+"user.yml") as user: user_info = yaml.load(user, Loader=yaml.FullLoader) submod = user_info['url'] logger.debug(f"submod path is {submod}") alt_badges = [button_templates[key].format(user_info[key]) for key in ["github_username", "spotify_username"]] if not keep_resume: import googleapiclient from oauth2client.service_account import ServiceAccountCredentials
def neuron2md(nt, neuron, doc_path): """ name: str (analyzers or responders) neuron: str doc_path: str """ # Title neuron_path = path.join(nt, neuron) mdFile = MdUtils(file_name="{}.md".format(neuron), title="") mdFile.new_header(level=1, title=neuron) # add README.md file in description mdFile.new_line() if 'README.md' in listdir(neuron_path): readme = open("{}/README.md".format(neuron_path), 'r') mdFile.new_line("!!! abstract \"README\"") mdFile.new_paragraph(" {}".format(readme.read().replace( '\n', '\n '))) readme.close #print(neuron) # Analyzers or Responders flavors for f in listdir(path.join(nt, neuron)): if nt in ["analyzers", "responders"] and f.endswith(".json"): with open(path.join(neuron_path, f), 'r') as fc: config = json.load(fc) # Title mdFile.new_header(level=2, title=config.get('name')) # Logo if config.get('service_logo'): logo_path = config.get('service_logo').get('path') logo_src_path = path.join(neuron_path, logo_path) if path.exists(logo_src_path) and logo_path != "": logo_filename = path.basename(logo_path) ext = logo_filename.split('.')[-1] logo_filename = logo_filename.split('.')[0] logo_filename = "{}_logo.{}".format( f.split('.')[0], ext) logo_md_path = path.join("assets", logo_filename) logo_dest_path = path.join(doc_path, nt, logo_md_path) copy(logo_src_path, logo_dest_path) logo_md_path = path.join( "../", logo_md_path) ## trick to make Html.image work mdFile.new_paragraph( Html.image(path=logo_md_path, size='150', align='center')) mdFile.new_line() # Identity mdFile.new_line("!!! note \"\"") mdFile.new_line(" **Author**: _{}_".format( config.get('author'))) mdFile.new_line(" **License**: _{}_".format( config.get('license'))) mdFile.new_line(" **Version**: _{}_".format( config.get('version'))) if nt == "analyzers": mdFile.new_line(" **Supported observables types**:") else: mdFile.new_line(" **Supported data types**:") for item in config.get('dataTypeList'): mdFile.new_line(" - {}".format(item)) mdFile.new_line(" **Registration required**: \ _{}_".format(config.get('registration_required', 'N/A'))) mdFile.new_line(" **Subscription required**: \ _{}_".format(config.get('subscription_required', 'N/A'))) mdFile.new_line(" **Free subscription**: \ _{}_".format(config.get('free_subscription', 'N/A'))) mdFile.new_line(' **Third party service**: '+\ mdFile.new_inline_link(link=config.get('service_homepage', 'N/A'), text=config.get('service_homepage', 'N/A'))) # Description mdFile.new_line() mdFile.new_header(level=3, title='Description') mdFile.new_paragraph(config.get('description', 'N/A')) # Configuration mdFile.new_line() mdFile.new_header(level=3, title='Configuration') if config.get('configurationItems') and len( config.get('configurationItems')) > 0: for c in config.get('configurationItems'): configuration_items = [ "**{}**".format(c.get('name')), c.get('description', 'No description') ] configuration_items.extend([ "**Default value if not configured**", "_{}_".format(c.get('defaultValue', 'N/A')) ]) configuration_items.extend([ "**Type of the configuration item**", "_{}_".format(c.get('type')) ]) configuration_items.extend([ "**The configuration item can contain multiple values**", "_{}_".format(c.get('multi')) ]) configuration_items.extend([ "**Is required**", "_{}_".format(c.get('required')) ]) mdFile.new_line() mdFile.new_table(columns=2, rows=5, text=configuration_items, text_align='left') else: mdFile.new_paragraph("No specific configuration required.") # Notes.md file if 'notes.md' in listdir(neuron_path): notes = open("{}/notes.md".format(neuron_path), 'r') mdFile.new_line("!!! tip \"Developer notes\"") mdFile.new_paragraph(" {}".format(notes.read().replace( '\n', '\n '))) notes.close # Analysers report samples if nt == "analyzers" and f.endswith(".json"): # Templates for TheHive mdFile.new_line() mdFile.new_header(level=3, title='Templates samples for TheHive') ## Copy images files to destination folder base_neuronname = f.split('.')[0] if config.get('screenshots'): for idx, sc in enumerate(config.get('screenshots')): sc_path = sc.get('path') sc_src_path = path.join(neuron_path, sc.get('path')) if path.exists(sc_src_path): sc_filename = path.basename(sc.get('path')) ext = sc_filename.split('.')[-1] sc_filename = path.basename(f).split('.')[0] sc_filename = "{}_{}.{}".format(sc_filename, idx, ext) sc_md_path = path.join("assets", sc_filename) sc_dest_path = path.join(doc_path, nt, sc_md_path) copy(sc_src_path, sc_dest_path) mdFile.new_paragraph( mdFile.new_inline_image(text=sc.get( 'caption', 'screenshot'), path=sc_md_path)) else: mdFile.new_paragraph("No template samples to display.") # Save md file dest_dir = path.join(doc_path, nt) if not path.exists(dest_dir): makedirs(dest_dir) olddir = path.abspath(path.curdir) chdir(dest_dir) mdFile.create_md_file() chdir(olddir)
class DataAnalyzer(object): def __init__(self, data_path): self._images_path = os.path.join(data_path, 'images') self._parser = Parser(data_path) self._results = MdUtils(file_name='results', title='Overview') self._num_images = None self._counts = None self._image_shape = None self._image_shape_mean = None def _compute_stats(self): self._num_images = self._parser.data.shape[1] self._counts = self._parser.data.loc['anomaly_class'].value_counts( ).to_dict() def _plot_random_image(self): random_image_file = f'{random.randint(0, self._num_images)}.jpg' image = img.imread(os.path.join(self._images_path, random_image_file)) self._image_shape = image.shape fig = plt.figure() plt.tight_layout() plt.imshow(image) plt.xticks([]), plt.yticks([]) plt.tight_layout() plt.title('Random Image') plt.savefig('random_image.png') plt.close(fig) plt.figure() plt.tight_layout() plt.hist(image.flatten()) plt.xlabel('Pixel Value') plt.ylabel('Counts') plt.title('Histogram') plt.savefig('random_image_histogram.png') plt.close(fig) def _compute_mean_shape(self): h, w = [], [] for im in self._parser.image_list: print(f'Reading image: {im}') image = img.imread(os.path.join(self._images_path, im)) h.append(image.shape[0]) w.append(image.shape[1]) self._image_shape_mean = (np.mean(h), np.mean(w)) def _plot_image_each_class(self): fig = plt.figure(figsize=(10, 10)) plt.tight_layout() plt.title('Random Image In Each Class') i = 1 for label in self._parser.labels: image_list = self._parser.get_label_images(label) random_selection = random.choice(image_list) image_path = self._parser.data.loc['image_filepath'].tolist( )[random_selection] image = img.imread(os.path.join(self._images_path, image_path[7:])) plt.subplot(4, 3, i) i += 1 plt.subplots_adjust(hspace=1, wspace=1) plt.title(f'Class: {label}') cur_axes = plt.gca() cur_axes.axes.get_xaxis().set_ticks([]) cur_axes.axes.get_yaxis().set_ticks([]) plt.imshow(np.uint8(image)) plt.savefig('random_image_each_class.png') plt.close(fig) def analyze(self): self._parser.parse() self._compute_stats() self._plot_random_image() self._compute_mean_shape() self._plot_image_each_class() def save_results(self): self._results.new_paragraph(f'Number of images: {self._num_images}') self._results.new_paragraph( f'Number of unique classes: {len(self._parser.labels)}') self._results.new_paragraph(f'Class names:') self._results.new_list(items=self._parser.labels) self._results.new_paragraph(f'Number of images per class: ') self._results.new_list( items=[f'{k}: {v}' for k, v in self._counts.items()]) self._results.new_paragraph(f'Image shape: {self._image_shape}') self._results.new_paragraph( f'Mean Image shape: {self._image_shape_mean}') self._results.new_paragraph( self._results.new_inline_image(text='Random Image', path='random_image.png')) self._results.new_paragraph( self._results.new_inline_image(text='Histogram', path='random_image_histogram.png')) self._results.new_paragraph( self._results.new_inline_image(text='Classes', path='random_image_each_class.png')) self._results.create_md_file()
def main(): #-----Getting parser-----# args = get_parser() ProducedIsotopes = [] if args.Energy is not None: ProducedIsotopes = data_extractor(args.Infile, args.Energy) else: print(colored('ERROR :', 'red'), ' Energy not provided') raise SystemExit try: os.mkdir(args.Outfolder) except: print(colored('WARNING :', 'yellow'), " Output folder already exist. All content will be replaced") finally: os.system('rm -r ' + args.Outfolder) os.mkdir(args.Outfolder) os.mkdir(args.Outfolder + '/Images') Primary = PrimaryProduction(args.XsecTh, ProducedIsotopes) Second = NextProduction(Primary) Third = NextProduction(Second) # print(Primary) # print(Second) # print(Third) mdFile = MdUtils(file_name=args.Outfolder + '/Resume', title='ENSDF Resume') blacklist = [] for iso in Primary: E = [] M = [] HL = [] flag = args.Levels levelflag = True nucleon = iso['A'] proton = iso['Z'] try: E, M, HL = list_levels(nucleons=nucleon, protons=proton) levelflag = level_scheme(nucleons=nucleon, protons=proton, filename=args.Outfolder + '/Images/' + str(proton) + str(nucleon) + '.png') except: flag = False El = element(proton) title = str(nucleon) + El.symbol blacklist.append(title) mdFile.new_header(3, title) mdFile.new_line("Element " + title + " direct production cross section -> " + str(iso['Xsec']) + " mb") x = checkisopresence(iso['Z'], iso['A'], Second) y = checkisopresence(iso['Z'], iso['A'], Third) if x != -1: Z, A = decayreverse(Second[x]['Z'], Second[x]['A'], Second[x]['Prev']) El2 = element(Z) title2 = str(A) + El2.symbol mdFile.new_line("Second generation production cross section -> " + str(Second[x]['Xsec']) + " mb") mdFile.new_line("Coming from " + Second[x]['Prev'] + " decay of " + title2) if y != -1: Z, A = decayreverse(Third[y]['Z'], Third[y]['A'], Third[y]['Prev']) El2 = element(Z) title2 = str(A) + El2.symbol mdFile.new_line("Third generation production cross section -> " + str(Third[y]['Xsec']) + " mb") mdFile.new_line("Coming from " + Third[y]['Prev'] + " decay of " + title2) if flag: list_of_levels = ["Energy", "Jπ", "λ"] for index in range(len(E)): list_of_levels.extend( [f"{E[index]}", f"{M[index]}", HL[index]]) mdFile.new_line() mdFile.new_table(columns=3, rows=len(E) + 1, text=list_of_levels, text_align='left') # if levelflag : # mdFile.new_line(mdFile.new_inline_image(text=title, path='Images/'+Isotope[1]+'.png')) for iso in Second: E = [] M = [] HL = [] flag = args.Levels levelflag = True nucleon = iso['A'] proton = iso['Z'] El = element(proton) title = str(nucleon) + El.symbol if title not in blacklist: blacklist.append(title) try: E, M, HL = list_levels(nucleons=nucleon, protons=proton) levelflag = level_scheme(nucleons=nucleon, protons=proton, filename=args.Outfolder + '/Images/' + str(proton) + str(nucleon) + '.png') except: flag = False mdFile.new_header(3, title) Z, A = decayreverse(iso['Z'], iso['A'], iso['Prev']) El2 = element(Z) title2 = str(A) + El2.symbol mdFile.new_line("Second generation production cross section -> " + str(iso['Xsec']) + " mb") mdFile.new_line("Coming from " + iso['Prev'] + " decay of " + title2) if flag: list_of_levels = ["Energy", "Jπ", "λ"] for index in range(len(E)): list_of_levels.extend( [f"{E[index]}", f"{M[index]}", HL[index]]) mdFile.new_line() mdFile.new_table(columns=3, rows=len(E) + 1, text=list_of_levels, text_align='left') # if levelflag : # mdFile.new_line(mdFile.new_inline_image(text=title, path='Images/'+Isotope[1]+'.png')) for iso in Third: E = [] M = [] HL = [] flag = args.Levels levelflag = True nucleon = iso['A'] proton = iso['Z'] El = element(proton) title = str(nucleon) + El.symbol if title not in blacklist: blacklist.append(title) try: E, M, HL = list_levels(nucleons=nucleon, protons=proton) levelflag = level_scheme(nucleons=nucleon, protons=proton, filename=args.Outfolder + '/Images/' + str(proton) + str(nucleon) + '.png') except: flag = False mdFile.new_header(3, title) Z, A = decayreverse(iso['Z'], iso['A'], iso['Prev']) El2 = element(Z) title2 = str(A) + El2.symbol mdFile.new_line("Third generation production cross section -> " + str(iso['Xsec']) + " mb") mdFile.new_line("Coming from " + iso['Prev'] + " decay of " + title2) if flag: list_of_levels = ["Energy", "Jπ", "λ"] for index in range(len(E)): list_of_levels.extend( [f"{E[index]}", f"{M[index]}", HL[index]]) mdFile.new_line() mdFile.new_table(columns=3, rows=len(E) + 1, text=list_of_levels, text_align='left') # if levelflag : # mdFile.new_line(mdFile.new_inline_image(text=title, path='Images/'+Isotope[1]+'.png')) cmdstr = '' for el in blacklist: cmdstr += ' --Produced ' + el os.system('python ChartDrawer.py --n 129 148 --z 85 97 nubase16.xml ' + args.Outfolder + '/chart.svg ' + cmdstr) os.system('inkscape ' + args.Outfolder + '/chart.svg --export-filename ' + args.Outfolder + '/chart.pdf') mdFile.new_line( mdFile.new_inline_image(text="Production Nuclide Chart", path=args.Outfolder + '/chart.png')) mdFile.create_md_file() os.system('grip -b ' + args.Outfolder + '/Resume.md') os.system('xdg-open ' + args.Outfolder + '/chart.pdf')
mdFile.new_header(2, "Add images") # *********************************************** Inline Image ******************************************************* image_text = "snow trees" path = "./doc/source/images/photo-of-snow-covered-trees.jpg" mdFile.new_header(3, "Inline Images") mdFile.new_paragraph( "You can add inline images using ``new_inline_image`` method. Method will return: " "``[image](../path/to/your/image.png)``. Check the following example: ") mdFile.insert_code( "mdFile.new_line(mdFile.new_inline_image(text='{}', path='{}'))".format( image_text, path)) mdFile.new_line(mdFile.new_inline_image(text=image_text, path=path)) # *********************************************** Reference Image **************************************************** mdFile.new_header(3, "Reference Images") mdFile.new_paragraph( "You can add inline images using ``new_reference_image`` method. Method will return: " "``[image][im]``. Check the following example: ") mdFile.insert_code( "mdFile.new_line(mdFile.new_reference_image(text='{}', path='{}', reference_tag='im'))" .format(image_text, path)) mdFile.new_line( mdFile.new_reference_image(text=image_text, path=path, reference_tag='im')) # ************************************************* Html Image ******************************************************* mdFile.new_header(2, "Add HTML images")