-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
49 lines (46 loc) · 1.3 KB
/
reader.py
File metadata and controls
49 lines (46 loc) · 1.3 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
from number import Number
from shunt import Shunt
def read_structure(line):
structure = []
line = line.replace(" ", "")
line = line.split(",")
count = 0
while count < len(line):
var = line[count]
count += 1
if count < len(line):
if line[count] == "Error":
structure.append((var, True))
count += 1
else:
structure.append((var, False))
return structure
def read_vars(line, structure, variables):
line = line.replace(" ", "")
line = (line.strip()).split(",")
count = 0
for var, status in structure:
value = line[count]
if value != "":
value = float(value)
error = 0
count += 1
if status:
error = line[count]
if error != "":
error = float(error)
count += 1
number = Number(value, var, error)
if value != "":
variables[var] = number
return True
def read_formula(file):
equations = []
for line in file:
equation = line.strip()
equation = equation.replace(" ", "")
equation = equation.split("=")
shunt = Shunt()
shunted = shunt.convert(equation[1])
equations.append((equation[0], shunted))
return equations