Repository navigation
Expand file tree
/
Copy pathnichrome.py
More file actions
91 lines (80 loc) · 3.48 KB
/
Copy pathnichrome.py
File metadata and controls
91 lines (80 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
# Copyright: Khan Kibria
# License: GNU GPL 3.0
import math
import argparse
import nicrlib
def spec(string):
try:
values = string.split(':')
parts = []
for value in values:
parts.append(int(value))
assert len(parts) <= 2
if len(parts) == 2:
assert parts[0] < parts[1]
return parts
except:
msg = "%r not a valid range format, use <int> or <int:int>" % string
raise argparse.ArgumentTypeError(msg)
def to_range(spec, inc):
if len(spec) == 1:
return range(spec[0], spec[0]+inc, inc)
return range(spec[0], spec[1]+inc, inc)
def spec_range(range_obj, spec, arg_name):
new_range_obj = to_range(spec, range_obj.step)
if new_range_obj.start < range_obj.start or new_range_obj.stop > range_obj.stop:
raise Exception('invalid argument "{} {}:{}", must be within {}:{}'.format(arg_name, new_range_obj.start, new_range_obj.stop-1, range_obj.start, range_obj.stop-1))
return new_range_obj
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--watts", action="store", type=spec, help="Power range in watts")
parser.add_argument("-v", "--voltage", action="store", type=spec, help="Supply voltage in volts")
parser.add_argument("-t", "--wire-type", action="store", type=spec, help="Nichrome wire type")
parser.add_argument("-g", "--awg", action="store", type=spec, help="Nichrome wire gauge")
parser.add_argument("-l", "--length", action="store", type=spec, help="Wire length in foot")
args = parser.parse_args()
tolerance = 1
watts_range = range(1, 5000, 1)
voltage_range = range(1, 5000, 1)
wire_type_range = range(20, 90, 10)
awg_range = range(1, 50, 1)
length_range = range(1, 200, tolerance)
constraint = 0
try:
if args.watts:
watts_range = spec_range(watts_range, args.watts, "--watts")
constraint += 1
if args.voltage:
voltage_range = spec_range(voltage_range, args.voltage, "--voltage")
constraint += 1
if args.wire_type:
wire_type_range = spec_range(wire_type_range, args.wire_type, "--wire-type")
constraint += 1
if args.awg:
awg_range = spec_range(awg_range, args.awg, "--awg")
constraint += 1
if args.length:
if constraint < 4:
length_range = spec_range(length_range, args.length, "--length")
constraint += 1
else:
raise Exception("You can only specify maximum 4 constraints, length is ignored")
if constraint < 1:
raise Exception ("You have to specify at least 1 constraints")
except Exception as e:
print(e)
exit(1)
for watts in watts_range:
for voltage in voltage_range:
for wire_type in wire_type_range:
for awg in awg_range:
for length in length_range:
min_length = length
max_length = length + length_range.step
try:
l = nicrlib.calc_wire_length(watts, voltage, wire_type, awg)
if (l >= min_length and l < max_length):
print ('power: {} watts, voltage: {} volts, wire-type: Nichrome-{}, gauge: {} awg, length: {:3.2f} feet'.format(watts, voltage, wire_type, awg, l))
except:
pass