Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and assign unit within cable length attribute #198

Merged
merged 4 commits into from
Dec 13, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __post_init__(self) -> None:
try:
g, u = self.gauge.split(' ')
except Exception:
raise Exception('Gauge must be a number, or number and unit separated by a space')
raise Exception(f'{self.gauge} - Gauge must be a number, or number and unit separated by a space')
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
self.gauge = g

formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
if u.upper() == 'AWG':
Expand All @@ -214,6 +214,20 @@ def __post_init__(self) -> None:
else:
pass # gauge not specified

if isinstance(self.length, str): # length and unit specified
try:
l, u = self.length.split(' ')
l = float(l)
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
raise Exception(f'{self.length} - Length must be a number, or number and unit separated by a space')
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
self.length = l
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
self.length_unit = u
elif self.length is not None: # length specified, assume m
if self.gauge_unit is None:
self.length_unit = 'm'
else:
pass # length not specified
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved

self.connections = []

if self.length_unit is None: #Default wire length units to meters if left undeclared
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down