Support.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import numpy as np
  2. import Level_4 as LV4
  3. import Level_2 as LV2
  4. def list_to_string(list):
  5. first = True
  6. for entry in list:
  7. if first:
  8. liststring= "'" + str(entry) + "'"
  9. first=False
  10. else:
  11. liststring=liststring+", '" + str(entry)+ "'"
  12. return liststring
  13. def map_lv4_to_part(level4_instances, conn):
  14. cur = conn.cursor()
  15. lv4_part_map = np.array([], dtype=[('lv4', int), ('lv2', int)])
  16. for lv4 in level4_instances:
  17. 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) + "'))"
  18. cur.execute(query)
  19. lv2 = cur.fetchone()
  20. if not lv2 is None:
  21. lv2 = int(lv2[0])
  22. lv4_part_map = np.append(lv4_part_map, np.array([(lv4, lv2)],dtype=lv4_part_map.dtype))
  23. return lv4_part_map
  24. def convert_part_to_lv4(conn):
  25. mapDict = {}
  26. level4_instances = LV4.get_level4Instances(conn)
  27. mapList = map_lv4_to_part(level4_instances,conn)
  28. for key,value in mapList:
  29. mapDict[int(key)]=float(value)
  30. return mapDict