Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import json
  3.  
  4.  
  5. # получения максимума слева или справа
  6. def get_max_section(section, xy, id_height_max):
  7. max = {}
  8. height_max_section = 0.0
  9.  
  10. # срез от максимальной высоты
  11. if section == 'right':
  12. xy_section = xy[id_height_max + 1:]
  13. elif section == 'left':
  14. xy_section = xy[:id_height_max - 1]
  15. else:
  16. xy_section = xy
  17.  
  18. # максимальная высота в списке координат справа
  19. for item in xy_section:
  20. if height_max_section < item['x']:
  21. height_max_section = item['x']
  22. max = item
  23.  
  24. return max
  25.  
  26.  
  27. def calculate_height(heightsArray, struct):
  28. return list(map(lambda a, b: a + b, heightsArray, struct))
  29.  
  30.  
  31. def chart_height_calculation(first_height, data):
  32. # результат высоты первой антенны
  33. result_first_height = 0
  34. # результат высоты второй антенны
  35. result_second_height = 0
  36.  
  37. # координаты высот
  38. heightsArray = data['heightsArray']
  39. y = data['distanceArray']
  40. # координаты с учетом помех
  41. struct = data['struct']
  42.  
  43. # считаем общие координаты
  44. x = calculate_height(heightsArray, struct)
  45.  
  46. # список dict координат
  47. xy = []
  48. for enum, x_item in enumerate(x):
  49. xy.append({'id': enum, 'x': x_item})
  50.  
  51. for enum, item in enumerate(xy):
  52. xy[enum].update({'y': y[enum]})
  53.  
  54. # максимальная высота
  55. height_max = 0.0
  56. max_center = {}
  57.  
  58. # находим максимальную высоту
  59. for item in xy:
  60. if height_max < item['x']:
  61. height_max = item['x']
  62. max_center = item
  63.  
  64. if first_height == 0:
  65. # максимальная высота справа от максимума
  66. max_right = get_max_section('right', xy, max_center['id'])
  67. # максимальная высота слева от максимума
  68. max_left = get_max_section('left', xy, max_center['id'])
  69.  
  70. print(max_center)
  71. print(max_left)
  72. print(max_right)
  73. elif first_height > 0:
  74. pass
  75. else:
  76. print 'The height of the first antenna can not be negative.'
  77.  
  78. print 'Height of the first antenna: %s' % result_first_height
  79. print'Height of the second antenna: %s' % result_second_height
  80.  
  81.  
  82. if __name__ == '__main__':
  83. # данные для теста
  84. with open('data_test.json') as f:
  85. data = json.load(f)
  86. first_height = 0
  87.  
  88. chart_height_calculation(0, data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement