generate_json.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import pandas as pd
  2. import os
  3. import json
  4. mapping_df = pd.read_excel(r'CMS-SCADA-关联.xlsx')
  5. mapping_df = mapping_df.dropna(subset=['id'])
  6. mapping_dict = dict()
  7. for index,row in mapping_df.iterrows():
  8. mapping_dict[row['cms_id']] = row
  9. json_datas = json.load(open(r'wind_data_all.json','r'))
  10. exists_json = list()
  11. department_map = {'发电机': '发电机', '齿轮箱': '齿轮箱', '行星': '齿轮箱', '主轴': '主轴'}
  12. for key,row in mapping_dict.items():
  13. if key in json_datas.keys():
  14. json_data = json_datas[key]
  15. json_data['wind_farm_id'] = row['id']
  16. json_data['wind_turbine_type'] = row['type']
  17. json_data['wind_turbine_id'] = row['wind_turbine_id']
  18. # childrens = json_data['children']
  19. # js_childrens = list()
  20. # for children in childrens:
  21. # pointName = children['name']
  22. # for k,v in department_map.items():
  23. # if k in pointName:
  24. # children['department_name'] = v
  25. # js_childrens.append(children)
  26. # break
  27. # json_data['children'] = js_childrens
  28. del json_data['children']
  29. exists_json.append(json_data)
  30. print(len(exists_json))
  31. sl1500_items = [item for item in exists_json if item.get('wind_turbine_type') == 'SL1500-82']
  32. my52_items = [item for item in exists_json if item.get('wind_turbine_type') == 'MY5.2se-166']
  33. other_items = [item for item in exists_json if item.get('wind_turbine_type') not in ('SL1500-82', 'MY5.2se-166')]
  34. other_1 = [item for i, item in enumerate(other_items) if i % 2 == 0]
  35. other_2 = [item for i, item in enumerate(other_items) if i % 2 == 1]
  36. exists_json_1 = sl1500_items + other_1
  37. exists_json_2 = my52_items + other_2
  38. print(len(exists_json_1),len(exists_json_2),len(exists_json_1) + len(exists_json_2))
  39. with open(r'wind_data_with_scada_1.json','w') as f:
  40. json.dump(exists_json_1,f,ensure_ascii=False,indent=4)
  41. with open(r'wind_data_with_scada_2.json','w') as f:
  42. json.dump(exists_json_2,f,ensure_ascii=False,indent=4)