From 91f54d7439803e102cce9cd4dff6d5aadc95dd91 Mon Sep 17 00:00:00 2001 From: Jeff MacKinnon Date: Wed, 1 Jan 2025 13:37:55 -0400 Subject: [PATCH] Added safety module for boundaries --- example_notebook.ipynb | 127 +++++++++++++++++++- jepl/Tables/Z462-Tables/Z46215-table1A.csv | 2 +- jepl/Tables/Z462-Tables/Z46215-table1B.csv | 2 +- jepl/jepl.py | 2 + jepl/jepl_safety.py | 129 +++++++++++++++++++++ 5 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 jepl/jepl_safety.py diff --git a/example_notebook.ipynb b/example_notebook.ipynb index 0df9f91..b9c8d23 100644 --- a/example_notebook.ipynb +++ b/example_notebook.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -722,7 +722,130 @@ { "cell_type": "markdown", "metadata": {}, - "source": [] + "source": [ + "# Electrical Safety Module\n", + "\n", + "This module helps calculate various approach boundaries, etc based on voltage information. It will be expanded in the future.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#limitedApproach(voltage,fixed=False,DC=False,unitsSI=True,year=2015)\n", + "\n", + "jmk.limitedApproach(199)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0.3'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#restrictedApproach(voltage,DC=False,unitsSI=True,year=2015)\n", + "\n", + "jmk.restrictedApproach(190)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'00'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#def gloveClass(voltage,DC=False)\n", + "\n", + "jmk.gloveClass(600)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "jmk.gloveClass(600,DC=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Templates \n", + "\n", + "This module is used to write out labels, results for reports, etc in LaTeX, RestructuredText, Markdown, etc." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from jepl.jepl_templates import *\n", + "#af_label(equipment,working_distance,incident_energy,af_boundary,energy_level,voltage,limited_approach,restricted_approach, glove_class,author=\"Jeff MacKinnon\",warning=\"warning\",project=\"Arc Flash Warning Label\",project_num=\"####\")\n", + "af_label(\"equipnum\",\"3 ft\",3,\"36 in\",\"B\",\"480 Vac\",\"10 ft\",\"1 ft\", \"00\",author=\"Jeff MacKinnon\",warning=\"warning\",project=\"Arc Flash Warning Label\",project_num=\"####\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from jinja2 import Environment, FileSystemLoader\n", + "\n", + "\n", + "environment = Environment( block_start_string = '\\BLOCK{',\n", + " block_end_string = '}',\n", + " variable_start_string = '\\VAR((',\n", + " variable_end_string = '))',\n", + " comment_start_string = '\\#{',\n", + " comment_end_string = '}',\n", + " line_comment_prefix = '%#',\n", + " loader=FileSystemLoader(\"jepl/templates/\")\n", + " )\n", + "template = environment.get_template(\"template-label-ArcFlash.tex\")\n", + "#print(environment.loader)" + ] } ], "metadata": { diff --git a/jepl/Tables/Z462-Tables/Z46215-table1A.csv b/jepl/Tables/Z462-Tables/Z46215-table1A.csv index 05e0a7f..ad6450f 100644 --- a/jepl/Tables/Z462-Tables/Z46215-table1A.csv +++ b/jepl/Tables/Z462-Tables/Z46215-table1A.csv @@ -1,5 +1,5 @@ Voltage,Movable LA SI,Movable LA Imperial,Fixed LA SI,Fixed LA Imperial,Restricted SI,Restricted Imperial -50,N/A,N/A,N/A,N/A,N/A,N/A +50,Not Specified,Not Specified,Not Specified,Not Specified,Not Specified,Not Specified 150,3,120,1,42,0,0 750,3,120,1,42,0.3,12 15000,3,120,1.5,60,0.7,26 diff --git a/jepl/Tables/Z462-Tables/Z46215-table1B.csv b/jepl/Tables/Z462-Tables/Z46215-table1B.csv index dc02a46..0625f3b 100644 --- a/jepl/Tables/Z462-Tables/Z46215-table1B.csv +++ b/jepl/Tables/Z462-Tables/Z46215-table1B.csv @@ -1,5 +1,5 @@ Voltage,Movable LA SI,Movable LA Imperial,Fixed LA SI,Fixed LA Imperial,Restricted SI,Restricted Imperial -50,N/A,N/A,N/A,N/A,N/A,N/A +50,Not Specified,Not Specified,Not Specified,Not Specified,Not Specified,Not Specified 300,3,120,1,42,0,0 1000,3,120,1,42,0.3,12 5000,3,120,1.5,60,0.4,17 diff --git a/jepl/jepl.py b/jepl/jepl.py index baf84ec..fdde28e 100644 --- a/jepl/jepl.py +++ b/jepl/jepl.py @@ -8,6 +8,8 @@ import sys from .jepl_general import * from .jeplpv import * from .jepl_circuits import * +from .jepl_templates import * +from .jepl_safety import * def Test(): print( "JMK Python Module works! !") diff --git a/jepl/jepl_safety.py b/jepl/jepl_safety.py new file mode 100644 index 0000000..64388dd --- /dev/null +++ b/jepl/jepl_safety.py @@ -0,0 +1,129 @@ +''' +JMK Engineering Inc. Python Library for design and such. +by: Jeff MacKinnon + +email: jeff@jmkengineering.com + +Electrical Safety + +These functions are used to calculate boundaries, etc. + +''' + +import sqlite3 + +def limitedApproach(voltage,fixed=False,DC=False,unitsSI=True,year=2015): + + if year == 2015: + database = "jepl-z46215.db" + + if DC == True: + try: + with sqlite3.connect(database) as con: + cur = con.cursor() + + cur.execute('SELECT * FROM "Table1B" WHERE "Voltage" > ? ', (voltage,)) + row = cur.fetchone() + + except sqlite3.OperationalError as e: + print(e) + else: + try: + with sqlite3.connect(database) as con: + cur = con.cursor() + + cur.execute('SELECT * FROM "Table1A" WHERE "Voltage" > ? ', (voltage,)) + row = cur.fetchone() + + except sqlite3.OperationalError as e: + print(e) + + + if (fixed == False) & (unitsSI == True): + column = 1 + elif (fixed == False) & (unitsSI == False): + column = 2 + elif (fixed == True) & (unitsSI == True): + column = 3 + elif (fixed == True) & (unitsSI == False): + column = 4 + + distance = row[column] + return(distance) + +def restrictedApproach(voltage,DC=False,unitsSI=True,year=2015): + + if year == 2015: + database = "jepl-z46215.db" + + if DC == True: + try: + with sqlite3.connect(database) as con: + cur = con.cursor() + + cur.execute('SELECT * FROM "Table1B" WHERE "Voltage" > ? ', (voltage,)) + row = cur.fetchone() + + except sqlite3.OperationalError as e: + print(e) + else: + try: + with sqlite3.connect(database) as con: + cur = con.cursor() + + cur.execute('SELECT * FROM "Table1A" WHERE "Voltage" > ? ', (voltage,)) + row = cur.fetchone() + + except sqlite3.OperationalError as e: + print(e) + + + if (unitsSI == True): + column = 5 + else: + column = 6 + + distance = row[column] + return(distance) + + + +def gloveClass(voltage,DC=False): + ''' + The glove class is based on the ASTM standard D120. + ''' + + if DC == True: + if voltage <= 750: + gloveclass = '00' + elif voltage <= 1500: + gloveclass = '0' + elif voltage <= 11250: + gloveclass = '1' + elif voltage <= 25500: + gloveclass = '2' + elif voltage <= 39750: + gloveclass = '3' + elif voltage <= 54000: + gloveclass = '4' + else: + gloveclass = "Voltage too High" + + + else: + if voltage <= 500: + gloveclass = '00' + elif voltage <= 1000: + gloveclass = '0' + elif voltage <= 7500: + gloveclass = '1' + elif voltage <= 17000: + gloveclass = '2' + elif voltage <= 26500: + gloveclass = '3' + elif voltage <= 36000: + gloveclass = '4' + else: + gloveclass = "Voltage too High" + + return(gloveclass) \ No newline at end of file