Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import boto3
  2. import math
  3.  
  4. def lambda_handler(event,context):
  5. dynamodb = boto3.resource('dynamodb')
  6. table = dynamodb.Table('tableforhotspot')
  7. data = table.scan()['Items']
  8.  
  9. loc_x = []
  10. loc_y = []
  11. location_info = []
  12.  
  13.  
  14. #print(data[0])
  15.  
  16.  
  17. for i in range(len(data)):
  18. #string_out = string_out +str(data[i]['record']) + "<br><br>"
  19. location_info.append(str(data[i]['record']))
  20. array = str(data[i]['record']).split(',')
  21. loc_x.append(float(array[2]))
  22. loc_y.append(float(array[3]))
  23.  
  24. #record_from_data = data[0]['record']
  25.  
  26. #grupowanie
  27. group_x = []
  28. group_y = []
  29.  
  30. group_x.append(loc_x[0])
  31. group_y.append(loc_y[0])
  32.  
  33. asigned_to_groups = [ [] ]
  34.  
  35.  
  36.  
  37. for i in range(len(loc_x)):
  38.  
  39. assigned = False
  40.  
  41. for j in range(len(group_x)):
  42.  
  43. distance = math.sqrt(math.pow(loc_x[i]-group_x[j],2) + math.pow(math.cos((loc_x[i]*3.14)/180)*(loc_y[i]-group_y[j]),2)) * 40075.704/360
  44.  
  45. if distance < 3:
  46.  
  47. asigned_to_groups[j].append(i)
  48. assigned = True
  49.  
  50. if assigned == False:
  51. group_x.append(loc_x[i])
  52. group_y.append(loc_y[i])
  53. asigned_to_groups.append([])
  54. asigned_to_groups[len(asigned_to_groups)-1].append(i)
  55.  
  56. #tworzenie stringa wyjsciowego
  57.  
  58. string_out = "<b> LISTA HOTSPOTOW W GDANSKU </b> <br><br>"
  59. string_out = string_out+"liczba grup:"+ str(len(group_x))+"<br><br>"
  60. print(len(string_out))
  61.  
  62. for i in range(len(asigned_to_groups)):
  63. string_out = string_out+','+"Grupa"+ str(i)+ ",<br><br><br><br> "
  64. for j in range(len(asigned_to_groups[i])):
  65. string_out = string_out + ','+location_info[asigned_to_groups[i][j]]+"<br><br> "
  66.  
  67. #print(loc_x)
  68. #print(len(loc_x))
  69. #print(len(asigned_to_groups))
  70. #print(len(group_x))
  71.  
  72. return string_out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement