original_docstring: 
  		This function will create a html file of the categories by each month.
  		html syntax for a table that is ugly
      <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Age</th>
    </tr>
  	
docstring: This function will create a html file of the categories by each month.
  html syntax for a table that is ugly
  
  Firstname
  Lastname
  Age
  
docstring_tokens: This function will create a html file of the categories by each month . html syntax for a table that is ugly Firstname Lastname Age
code: def html_categories_for_year(bank_data, bank_categories, html_directory):
  	'''
  		This function will create a html file of the categories by each month.
  		html syntax for a table that is ugly
      <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Age</th>
    </tr>
  	'''
  	html_header = '''
  <!DOCTYPE html>
  <html>
  <head>
  <style>
  table, th, td {
      border: 1px solid black;
  }
  </style>
  </head>
  <body>
  
  <table style="width:100%">
  	'''
  
  	html_footer = '''
  </body>
  </html>
  	'''
  	# go through the bank_data make html_detail files and adding up category totals
  	html_file_name = html_directory + "/qia_categories_summary_table.html"
  	html = ""
  	with open(html_file_name, 'w') as html_file:
  		html_file.write(html_header)
  		# gather all the data and put everything into a dictionary
  		category_total = {}
  		for bank_index in range(0, len(bank_data)):
  			if bank_categories[bank_index] in category_total.keys():
  				category_total[bank_categories[bank_index]] = category_total[bank_categories[bank_index]] + bank_data[bank_index]['amount']
  				# add the details to the html_detail_file
  				html_detail_file_name = html_directory + "/" + bank_categories[bank_index] + ".html"
  				with open(html_detail_file_name, 'a') as html_detail_file:
  					html += "<tr>"
  					html += "<td>%s</td><td>%06.2f</td><td>%s</td><td>%s</td><td>%s</td>" % (bank_data[bank_index]['date'],
  						bank_data[bank_index]['amount'], bank_data[bank_index]['description_1'], bank_data[bank_index]['description_2'],
  						bank_data[bank_index]['type'])
  					html += "</tr>\n"
  					html_detail_file.write(html)
  					html = ""
  			else:
  				# new category so we have to create a record in the data dictionary
  				# also need to create a new file because we have not seen it before
  				category_total[bank_categories[bank_index]] = bank_data[bank_index]['amount']
  				html_detail_file_name = html_directory + "/" + bank_categories[bank_index] + ".html"
  				with open(html_detail_file_name, 'w') as html_detail_file:
  					html_detail_file.write(html_header)
  					html += "<p>\n"
  					html += "<tr>"
  					html += "<td><b>Date</b></td><td><b>Amount</b></td><td><b>Description_1</b></td><td><b>Description_2</b></td><td><b>Type</b></td>"
  					html += "</tr>\n"
  					html += "<tr>"
  					html += "<td>%s</td><td>%06.2f</td><td>%s</td><td>%s</td><td>%s</td>" % (bank_data[bank_index]['date'],
  						bank_data[bank_index]['amount'], bank_data[bank_index]['description_1'], bank_data[bank_index]['description_2'],
  						bank_data[bank_index]['type'])
  					html += "</tr>\n"
  					html_detail_file.write(html)
  					html = ""
  
  		# sort the dictionary category_total and place into a list
  		# https://stackoverflow.com/questions/20577840/python-dictionary-sorting-in-descending-order-based-on-values
  		category_total_sorted_keys = sorted(category_total, key=category_total.get, reverse=True)
  
  		# now we have to go through each of the categories and write a total line
  		# close the table and the html_footer for the html_detail files
  		for category_key in category_total_sorted_keys:
  			html_detail_file_name = html_directory + "/" + category_key + ".html"
  			with open(html_detail_file_name, 'a') as html_detail_file:
  				# make a total line
  				html = ""
  				html += "<tr>"
  				html += ("<td><b>Total</b></td><td><b>$%6.2f</b></td>" % category_total[category_key])
  				html += "</tr>\n"
  				html += "</table>\n"
  				html += "</p>\n"
  				html_detail_file.write(html)
  				html_detail_file.write(html_footer)
  
  		# now that we have gathered the data lets pretty print the results in a summary table
  		# include a link to the detail file in the summary table
  		# <a href="url">link text</a>
  		profit = 0.0
  		html = ""
  		html += "<p>"
  		html += "<tr>"
  		html += "<td><b>Category</b></td><td><b>Amount</b></td>"
  		html += "</tr>\n"
  		for category_key in category_total_sorted_keys:
  			html += "<tr>"
  			html += ("<td><a href='./%s.html'>" % category_key)
  			html += "{0:20}</a></td><td>${1:,.2f}</td>".format(category_key, category_total[category_key])
  			html += "</tr>\n"
  			#print("{0:20}  ${1:,.2f}".format(category_key, category_total[category_key]))
  			profit += category_total[category_key]
  
  		# make a profit line
  		html += "<tr>"
  		html += ("<td><b>Profit</b></td><td><b>$%6.2f</b></td>" % profit)
  		html += "</tr>\n"
  		html += "</table>\n"
  		html += "</p>\n"
  		html_file.write(html)
  
  		# make a graph and save to a file
  		#category_list = list(category_total.values())
  		#category_name = list(category_total.keys())
  		category_list = []
  		category_name = []
  		for category_key in category_total_sorted_keys:
  			category_list.append(category_total[category_key])
  			category_name.append(category_key)
  		fix, ax = plt.subplots()
  		width = 0.35
  		N = len(category_list)
  		ind = np.arange(N)
  		rects1 = ax.bar(ind, category_list, width, color='y')
  		ax.set_ylabel('Amount')
  		ax.set_title('Category Amount from Month %d to %d' % (1, 12))
  		ax.set_xticks(ind + (width/2))
  		ax.set_xticklabels(category_name, rotation=90)
  		plt.tight_layout()
  		plt.savefig(html_directory + "/category_plot.png")
  
  		#html = "<p><img src='category_plot.png' alt='category plot' width='500' height='377'></p>\n"
  		html = "<p><img src='category_plot.png' alt='category plot' width=800 height=400></p>\n"
  		html_file.write(html)
  		html_file.write(html_footer)
code_tokens: def html_categories_for_year ( bank_data , bank_categories , html_directory ) : html_header = '''
  <!DOCTYPE html>
  <html>
  <head>
  <style>
  table, th, td {
      border: 1px solid black;
  }
  </style>
  </head>
  <body>
  
  <table style="width:100%">
  	''' html_footer = '''
  </body>
  </html>
  	''' html_file_name = html_directory + "/qia_categories_summary_table.html" html = "" with open ( html_file_name , 'w' ) as html_file : html_file . write ( html_header ) category_total = { } for bank_index in range ( 0 , len ( bank_data ) ) : if bank_categories [ bank_index ] in category_total . keys ( ) : category_total [ bank_categories [ bank_index ] ] = category_total [ bank_categories [ bank_index ] ] + bank_data [ bank_index ] [ 'amount' ] html_detail_file_name = html_directory + "/" + bank_categories [ bank_index ] + ".html" with open ( html_detail_file_name , 'a' ) as html_detail_file : html += "<tr>" html += "<td>%s</td><td>%06.2f</td><td>%s</td><td>%s</td><td>%s</td>" % ( bank_data [ bank_index ] [ 'date' ] , bank_data [ bank_index ] [ 'amount' ] , bank_data [ bank_index ] [ 'description_1' ] , bank_data [ bank_index ] [ 'description_2' ] , bank_data [ bank_index ] [ 'type' ] ) html += "</tr>\n" html_detail_file . write ( html ) html = "" else : category_total [ bank_categories [ bank_index ] ] = bank_data [ bank_index ] [ 'amount' ] html_detail_file_name = html_directory + "/" + bank_categories [ bank_index ] + ".html" with open ( html_detail_file_name , 'w' ) as html_detail_file : html_detail_file . write ( html_header ) html += "<p>\n" html += "<tr>" html += "<td><b>Date</b></td><td><b>Amount</b></td><td><b>Description_1</b></td><td><b>Description_2</b></td><td><b>Type</b></td>" html += "</tr>\n" html += "<tr>" html += "<td>%s</td><td>%06.2f</td><td>%s</td><td>%s</td><td>%s</td>" % ( bank_data [ bank_index ] [ 'date' ] , bank_data [ bank_index ] [ 'amount' ] , bank_data [ bank_index ] [ 'description_1' ] , bank_data [ bank_index ] [ 'description_2' ] , bank_data [ bank_index ] [ 'type' ] ) html += "</tr>\n" html_detail_file . write ( html ) html = "" category_total_sorted_keys = sorted ( category_total , key = category_total . get , reverse = True ) for category_key in category_total_sorted_keys : html_detail_file_name = html_directory + "/" + category_key + ".html" with open ( html_detail_file_name , 'a' ) as html_detail_file : html = "" html += "<tr>" html += ( "<td><b>Total</b></td><td><b>$%6.2f</b></td>" % category_total [ category_key ] ) html += "</tr>\n" html += "</table>\n" html += "</p>\n" html_detail_file . write ( html ) html_detail_file . write ( html_footer ) profit = 0.0 html = "" html += "<p>" html += "<tr>" html += "<td><b>Category</b></td><td><b>Amount</b></td>" html += "</tr>\n" for category_key in category_total_sorted_keys : html += "<tr>" html += ( "<td><a href='./%s.html'>" % category_key ) html += "{0:20}</a></td><td>${1:,.2f}</td>" . format ( category_key , category_total [ category_key ] ) html += "</tr>\n" profit += category_total [ category_key ] html += "<tr>" html += ( "<td><b>Profit</b></td><td><b>$%6.2f</b></td>" % profit ) html += "</tr>\n" html += "</table>\n" html += "</p>\n" html_file . write ( html ) category_list = [ ] category_name = [ ] for category_key in category_total_sorted_keys : category_list . append ( category_total [ category_key ] ) category_name . append ( category_key ) fix , ax = plt . subplots ( ) width = 0.35 N = len ( category_list ) ind = np . arange ( N ) rects1 = ax . bar ( ind , category_list , width , color = 'y' ) ax . set_ylabel ( 'Amount' ) ax . set_title ( 'Category Amount from Month %d to %d' % ( 1 , 12 ) ) ax . set_xticks ( ind + ( width / 2 ) ) ax . set_xticklabels ( category_name , rotation = 90 ) plt . tight_layout ( ) plt . savefig ( html_directory + "/category_plot.png" ) html = "<p><img src='category_plot.png' alt='category plot' width=800 height=400></p>\n" html_file . write ( html ) html_file . write ( html_footer )
short_docstring: This function will create a html file of the categories by each month.
short_docstring_tokens: This function will create a html file of the categories by each month .
comment: '''
  		This function will create a html file of the categories by each month.
  		html syntax for a table that is ugly
      <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Age</th>
    </tr>
  	'''$SEP$# go through the bank_data make html_detail files and adding up category totals$SEP$# gather all the data and put everything into a dictionary$SEP$# add the details to the html_detail_file$SEP$# new category so we have to create a record in the data dictionary$SEP$# also need to create a new file because we have not seen it before$SEP$# sort the dictionary category_total and place into a list$SEP$# https://stackoverflow.com/questions/20577840/python-dictionary-sorting-in-descending-order-based-on-values$SEP$# now we have to go through each of the categories and write a total line$SEP$# close the table and the html_footer for the html_detail files$SEP$# make a total line$SEP$# now that we have gathered the data lets pretty print the results in a summary table$SEP$# include a link to the detail file in the summary table$SEP$# <a href="url">link text</a>$SEP$#print("{0:20}  ${1:,.2f}".format(category_key, category_total[category_key]))$SEP$# make a profit line$SEP$# make a graph and save to a file$SEP$#category_list = list(category_total.values())$SEP$#category_name = list(category_total.keys())$SEP$#html = "<p><img src='category_plot.png' alt='category plot' width='500' height='377'></p>\n"