|
|
@ -0,0 +1,60 @@ |
|
|
|
|
|
import re |
|
|
|
|
|
compound = {} |
|
|
|
|
|
base_comp = set() |
|
|
|
|
|
|
|
|
|
|
|
def get_input(comp): |
|
|
|
|
|
ret = {} |
|
|
|
|
|
ret['type'] = input('type: ').lower() |
|
|
|
|
|
ret['parents'] = set() |
|
|
|
|
|
if type == 'compound': |
|
|
|
|
|
ret['sub'] = {} |
|
|
|
|
|
first = True |
|
|
|
|
|
while True: |
|
|
|
|
|
i = input('sub: ' if first else '>').lower() |
|
|
|
|
|
if i == 'end': |
|
|
|
|
|
break |
|
|
|
|
|
if i != '' |
|
|
|
|
|
s = re.split(r' *\* ',i) |
|
|
|
|
|
if len(s) == 2: |
|
|
|
|
|
name,count = s |
|
|
|
|
|
else: |
|
|
|
|
|
name = s[0] |
|
|
|
|
|
count = 0 |
|
|
|
|
|
ret[name] = int(count) |
|
|
|
|
|
first = False |
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
|
|
def get_sub(comp): |
|
|
|
|
|
# either not base component or not entered yet |
|
|
|
|
|
if comp not in base_comp: |
|
|
|
|
|
try: |
|
|
|
|
|
# check to see if it is already entered |
|
|
|
|
|
subs = compound[comp] |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
# entry |
|
|
|
|
|
subs = get_input(comp) |
|
|
|
|
|
|
|
|
|
|
|
if subs['type'] == 'base': |
|
|
|
|
|
base_comp.add(comp) |
|
|
|
|
|
else: |
|
|
|
|
|
compound[comp] = subs |
|
|
|
|
|
return subs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __inner__(comp,count,bases,components,prev = None): |
|
|
|
|
|
component_data = get_sub(comp) |
|
|
|
|
|
if prev: |
|
|
|
|
|
component_data['parents'].add(prev) |
|
|
|
|
|
# not a compound component |
|
|
|
|
|
if component_data is None: |
|
|
|
|
|
prev = bases.get(comp,0) |
|
|
|
|
|
bases[comp] = prev + count |
|
|
|
|
|
else: |
|
|
|
|
|
prev = components.get(comp,0) |
|
|
|
|
|
components[comp] = prev + count |
|
|
|
|
|
for sub,count in component_data['sub']: |
|
|
|
|
|
__inner__(sub,count,bases,components,comp) |
|
|
|
|
|
|
|
|
|
|
|
def get_overall_usage(comp): |
|
|
|
|
|
ret_bases = {} |
|
|
|
|
|
ret_components = {} |