Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- import math
- def lambda_handler(event,context):
- dynamodb = boto3.resource('dynamodb')
- table = dynamodb.Table('tableforhotspot')
- data = table.scan()['Items']
- loc_x = []
- loc_y = []
- location_info = []
- #print(data[0])
- for i in range(len(data)):
- #string_out = string_out +str(data[i]['record']) + "<br><br>"
- location_info.append(str(data[i]['record']))
- array = str(data[i]['record']).split(',')
- loc_x.append(float(array[2]))
- loc_y.append(float(array[3]))
- #record_from_data = data[0]['record']
- #grupowanie
- group_x = []
- group_y = []
- group_x.append(loc_x[0])
- group_y.append(loc_y[0])
- asigned_to_groups = [ [] ]
- for i in range(len(loc_x)):
- assigned = False
- for j in range(len(group_x)):
- 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
- if distance < 3:
- asigned_to_groups[j].append(i)
- assigned = True
- if assigned == False:
- group_x.append(loc_x[i])
- group_y.append(loc_y[i])
- asigned_to_groups.append([])
- asigned_to_groups[len(asigned_to_groups)-1].append(i)
- #tworzenie stringa wyjsciowego
- string_out = "<b> LISTA HOTSPOTOW W GDANSKU </b> <br><br>"
- string_out = string_out+"liczba grup:"+ str(len(group_x))+"<br><br>"
- print(len(string_out))
- for i in range(len(asigned_to_groups)):
- string_out = string_out+','+"Grupa"+ str(i)+ ",<br><br><br><br> "
- for j in range(len(asigned_to_groups[i])):
- string_out = string_out + ','+location_info[asigned_to_groups[i][j]]+"<br><br> "
- #print(loc_x)
- #print(len(loc_x))
- #print(len(asigned_to_groups))
- #print(len(group_x))
- return string_out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement