From cf86793e1fc29aaab76004d3870d487c1dde14bd Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 28 Dec 2025 22:06:19 -0400 Subject: [PATCH] adding command line tool calls tools. --- README.md | 6 +++ jepl/jepl_general.py | 2 +- tools.py | 100 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 tools.py diff --git a/README.md b/README.md index 9a891f2..8a20cc6 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ There are also a few VSCodium extensions that will be needed. My preferred way to manage this tool for multiple projects is using [git](https://git-scm.com/downloads). I will typically clone the entire repo and then work from there. +# Commandline tool + +A commandline interface (CLI) is in progress for the purpose of calling individual functions as they are needed during the work day. Over time all functions will be added there, but the re-write for the tables from SQL to arrays needs to be finished first. + +For now, ``tools.py`` is there to be used and added to as time allows. + # Limitations Currently the tools use the CEC, in most cases this will match the NEC, but something we are working on is updating that so we can select from which code version should be used for the calculation. diff --git a/jepl/jepl_general.py b/jepl/jepl_general.py index 91b82bf..02092ba 100644 --- a/jepl/jepl_general.py +++ b/jepl/jepl_general.py @@ -21,7 +21,7 @@ def va(voltage, current,phases=3): va = (math.sqrt(3) * voltage * current) elif phases == 1: - vs = voltage * current + va = voltage * current else: print("Phases needs to be 1 or 3 for now.") diff --git a/tools.py b/tools.py new file mode 100644 index 0000000..2bd2cae --- /dev/null +++ b/tools.py @@ -0,0 +1,100 @@ +''' +JMK Engineering Inc. Python Library for design and such. +by: Jeff MacKinnon + +email: jeff@jmkengineering.com + +Commandline tools for JEPL functions + +''' + +import argparse +import jepl.jepl as jmk + + +# +# functions for the functions +# + +# General + +def va(args): + x = [1,3,None] + if args.phases in x: + if args.phases == None: + phases = 3 + else: + phases = args.phases + result = jmk.va(args.voltage, args.current, phases=phases) + print ( str(round(result,2))+ "VA") + else: + print(args.phases) + + +# Solar + + + +def temp_adj_Voc(args): + if args.beta == None: + beta = -0.5 + else: + beta = args.beta + if args.stctemp == None: + stctemp = 25 + else: + stctemp = args.stctemp + result = jmk.temp_adj_Voc(args.voc, args.temperature, beta, stctemp) + print(str(round(result,2))+"V") + + +# +# Parse the options +# + +try: + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers( + title="tools", help="Commandline Functions" + ) + +# +# This section is for the jepl_general functions +# + +# Calcuating VA + + va_parser = subparsers.add_parser("va", help="calculate VA (S)") + va_parser.add_argument("voltage", type=float,help="Voltage of the circuit") + va_parser.add_argument("current", type=float,help="Current of the circuit.") + va_parser.add_argument("-p","--phases", type=int,help="Phases of the circuit. It should be either 1 or 3, and we will assume 3 if it is not used.") + va_parser.set_defaults(func=va) + + +# +# Solar Tools +# + + tempvoc = subparsers.add_parser("tempVoc", help="Calculate the temperature adjusted Voc of a PV panel.") + tempvoc.add_argument("voc", type=float,help="Open circuit voltage of the panel.") + tempvoc.add_argument("temperature", type=float, help="Temperature the panel will be at.") + tempvoc.add_argument("-b", "--beta", type=float, help="Panel Beta value, if none is added -0.5 will be used.") + tempvoc.add_argument("-t", "--stctemp", type=float, help="The STC temp. If none is added 25C will be used.") + tempvoc.set_defaults(func=temp_adj_Voc) + + + +# This runs the function that was selected with the arguments in the command. + args = parser.parse_args() + args.func(args) + + + +except argparse.ArgumentError as e: + #log.error("Error parsing arguments") + raise e + + +#else: +# print(f"Something clever") +