Help for awg.view_cable_finder
Sample CLI
gway awg view-cable-finder
Full Code
def view_cable_finder(
*, meters=None, amps="40", volts="220", material="cu",
max_lines="3", phases="1", conduit=None, neutral="0", **kwargs
):
"""Page builder for AWG cable finder with HTML form and result."""
# TODO: Add a image with the sponsor logo on the right side of the result page
if not meters:
return '''<h1>AWG Cable Finder</h1>
<form method="post">
<label>Meters: <input type="number" name="meters" required min="1" /></label><br/>
<label>Amps: <input type="number" name="amps" value="40" /></label><br/>
<label>Volts: <input type="number" name="volts" value="220" /></label><br/>
<label>Material:
<select name="material">
<option value="cu">Copper (cu)</option>
<option value="al">Aluminum (al)</option>
</select>
</label><br/>
<label>Phases:
<select name="phases">
<option value="2">AC Two Phases (2)</option>
<option value="1">AC Single Phase (1)</option>
<option value="3">AC Three Phases (3)</option>
</select>
</label><br/>
<label>Max Lines: <input type="number" name="max_lines" value="1" /></label><br/>
<button type="submit" class="submit">Find Cable</button>
</form>
'''
try:
result = find_cable(
meters=meters, amps=amps, volts=volts,
material=material, max_lines=max_lines, phases=phases,
)
except Exception as e:
return f"<p class='error'>Error: {e}</p><p><a href='/awg/cable-finder'>← Try again</a></p>"
if result.get("awg") == "n/a":
return """
<h1>No Suitable Cable Found</h1>
<p>No cable was found that meets the requirements within a 3% voltage drop.<br>
Try adjusting the <b>cable size, amps, length, or material</b> and try again.</p>
<p><a href="/awg/cable-finder">← Calculate again</a></p>
"""
return f"""
<h1>Recommended Cable</h1>
<ul>
<li><strong>AWG Size:</strong> {result['awg']}</li>
<li><strong>Lines:</strong> {result['lines']}</li>
<li><strong>Total Cables:</strong> {result['cables']}</li>
<li><strong>Total Length (m):</strong> {result['total_meters']}</li>
<li><strong>Voltage Drop:</strong> {result['vdrop']:.2f} V ({result['vdperc']:.2f}%)</li>
<li><strong>Voltage at End:</strong> {result['vend']:.2f} V</li>
</ul>
<p>
<em>Special thanks to the expert electrical engineers at <strong>
<a href="https://www.gelectriic.com">Gelectriic Solutions</a></strong> for their
useful input and support while creating this calculator.</em>
</p>
<p><a href="/awg/cable-finder">← Calculate again</a></p>
"""