Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created August 20, 2020 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/b205c1809e35e2c6245f17e585f1fd76 to your computer and use it in GitHub Desktop.
Save amankharwal/b205c1809e35e2c6245f17e585f1fd76 to your computer and use it in GitHub Desktop.
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