''' JMK Engineering Inc. Python Library for design and such. by: Jeff MacKinnon email: jeff@jmkengineering.com Template Generation These functions are used to create labels, reports, etc. ''' from .jepl_safety import * def af_label(equipment,working_distance,incident_energy,af_boundary,energy_level,voltage, author="Jeff MacKinnon",warning="warning",project="Arc Flash Warning Label",project_num="2500",DC=False,fixedElectrode = True, SI=True,project_year=2015,test=False): ''' This function is for printing a single label with all the information in the function above. Include the units (in, Vac, Vdc, ft, m, mm, etc.) in the values. All values are strings. ''' from datetime import date date = date.today() revdate = date.strftime("%m/%d/%Y") if DC == True: voltage_units = " Vdc" else: voltage_units = " Vac" label_voltage = str(voltage) + voltage_units glove_class = gloveClass(voltage,DC=DC) limited_approach = limitedApproach(voltage,fixed=fixedElectrode,DC=DC,unitsSI=SI,year=project_year) restricted_approach = restrictedApproach(voltage,DC=DC,unitsSI=SI,year=project_year) if warning =="warning": warning_colour = '242,85,31' warning_text = '\warning WARNING' elif warning == "danger": warning_colour = '242,85,31' # This colour needs to change warning_text = '\warning DANGER' else: warning_colour = '255,255,255' # This colour needs to change warning_text = '' from jinja2 import Environment, FileSystemLoader environment = Environment( block_start_string = '\BLOCK{', block_end_string = '}', variable_start_string = '\VAR((', variable_end_string = '))', comment_start_string = '\#{', comment_end_string = '}', line_comment_prefix = '%#', loader=FileSystemLoader("jepl/templates/") ) #template = environment.get_template("template-label-ArcFlash.tex") template = environment.get_template("template-AF_warning_label.tex") if test == True: filename = "test"+str(date) + "-"+project_num+"-label-ArcFlash.tex" else: filename = str(date) + "-"+project_num+"-label-ArcFlash.tex" content = template.render( DATE = revdate, EQUIPMENT = equipment, WORKING_DISTANCE = working_distance, INCIDENT_ENERGY = incident_energy, AF_BOUNDARY = af_boundary, ENERGY_LEVEL = energy_level, VOLTAGE = label_voltage, LIMITED_APPROACH = limited_approach, RESTRICTED_APPROACH = restricted_approach, GLOVE_CLASS = glove_class, AUTHOR = author, TITLE = project, WARNING_COLOUR = warning_colour, WARNING_TEXT = warning_text, ) with open(filename, mode="w", encoding="utf-8") as message: message.write(content) def af_labels(results_csv,author="JMK Engineering Inc.",warning="warning",project="Arc Flash Warning Label",project_num="2500",DC=False,fixedElectrode = True, SI=True,project_year=2015,output_folder='',test=False): from datetime import date date = date.today() revdate = date.strftime("%m/%d/%Y") if DC == True: voltage_units = " Vdc" else: voltage_units = " Vac" if warning =="warning": warning_colour = '242,85,31' warning_text = '\warning WARNING' elif warning == "danger": warning_colour = '242,85,31' # This colour needs to change warning_text = '\warning DANGER' else: warning_colour = '255,255,255' # This colour needs to change warning_text = '' label_info = {'date':date, 'title':project, 'author':author, 'voltage_units':voltage_units, 'warning_colour':warning_colour, 'warning_text':warning_text, 'project':project, 'project_num':project_num, } import pandas as pd results_af = pd.read_csv(results_csv) results = results_af.T.to_dict().values() # Need to take this information and add it to the label results dataframe above. # This needs to include working distance, which should actually be selectable from the ETAP results # 'working_distance':'18in' # This needs to change maybe I can get it added to the AF results. # Then when these values are added to the results CSV we can finish the template results thing from jinja2 import Environment, FileSystemLoader environment = Environment( block_start_string = '\BLOCK{', block_end_string = '}', variable_start_string = '\VAR((', variable_end_string = '))', comment_start_string = '\#{', comment_end_string = '}', line_comment_prefix = '%#', loader=FileSystemLoader("jepl/templates/") ) #template = environment.get_template("template-label4x6-base.tex") template = environment.get_template("template-AF_warning_label.tex") #template = environment.get_template("testblock.txt") if test == True: filename = output_folder +"test"+str(date) + "-"+project_num+"-label-ArcFlash.tex" else: filename = output_folder+str(date) + "-"+project_num+"-label-ArcFlash.tex" context = {"results":results,"project":label_info} content = template.render(context) with open(filename, mode="w", encoding="utf-8") as message: message.write(content)