123456789101112131415161718192021222324252627282930313233343536 |
- import numpy as np
- import Level_4 as LV4
- import Level_2 as LV2
- def list_to_string(list):
- first = True
- for entry in list:
- if first:
- liststring= "'" + str(entry) + "'"
- first=False
- else:
- liststring=liststring+", '" + str(entry)+ "'"
- return liststring
- def map_lv4_to_part(level4_instances, conn):
- cur = conn.cursor()
- lv4_part_map = np.array([], dtype=[('lv4', int), ('lv2', int)])
- for lv4 in level4_instances:
- query = "select distinct mt.part from measureTot mt join instances i on i.instance=mt.instance where i.instance in (select distinct i.called_by from instances i where i.instance in (select called_by from instances i where i.instance = '" + str(lv4) + "'))"
- cur.execute(query)
- lv2 = cur.fetchone()
- if not lv2 is None:
- lv2 = int(lv2[0])
- lv4_part_map = np.append(lv4_part_map, np.array([(lv4, lv2)],dtype=lv4_part_map.dtype))
- return lv4_part_map
- def convert_part_to_lv4(conn):
- mapDict = {}
- level4_instances = LV4.get_level4Instances(conn)
- mapList = map_lv4_to_part(level4_instances,conn)
- for key,value in mapList:
- mapDict[int(key)]=float(value)
- return mapDict
|