Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created August 20, 2020 16:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
def get_infected_names(input_name):
epsilon = 0.0018288 # a radial distance of 6 feet in kilometers
model = DBSCAN(eps=epsilon, min_samples=2, metric='haversine').fit(df[['latitude', 'longitude']])
df['cluster'] = model.labels_.tolist()
input_name_clusters = []
for i in range(len(df)):
if df['id'][i] == input_name:
if df['cluster'][i] in input_name_clusters:
pass
else:
input_name_clusters.append(df['cluster'][i])
infected_names = []
for cluster in input_name_clusters:
if cluster != -1:
ids_in_cluster = df.loc[df['cluster'] == cluster, 'id']
for i in range(len(ids_in_cluster)):
member_id = ids_in_cluster.iloc[i]
if (member_id not in infected_names) and (member_id != input_name):
infected_names.append(member_id)
else:
pass
return infected_names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment