Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
__author__ = 'Shweta'
import csv
import glob
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from datetime import date, timedelta, datetime
from pylab import scatter, show, title, xlabel, ylabel, plot, contour
import re
import os, time
import datetime
from collections import defaultdict
import itertools
import math
import numpy
from math import radians, cos, sin, asin, sqrt
############## This script calculates the median values for all the latitude and longitude for each unique BSSID and writes to a file.
def median(lst):
return numpy.mean(numpy.array(lst))
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
c = 2 * asin(sqrt(a))
metr = 6367 * c * 1000
return metr
fz1 = open("bssidmappingfile.csv", "w", encoding="utf8")
cz1 = csv.writer(fz1)
cz1.writerow(["BSSID","Longitude", "Latitude"])
################### euclidean
subbud = pd.read_csv("mergedbssid_final.csv")
bs = subbud.BSSID.unique()
elat1 = subbud.Latitude.tolist()
elong1 = subbud.Longitude.tolist()
minpts = 3
for i, v in enumerate(bs):
# t=eud[eud['BSSID']==v]
t = subbud[subbud['BSSID'] == v] # find all matches for BSSID.
vlat = t.Latitude
vlong = t.Longitude
clat1 = vlat.astype(float)
clat11 = clat1.tolist()
clong1 = vlong.astype(float)
clong11 = clong1.tolist()
##############trying median
if (len(clat11) > minpts and len(clong11) > minpts):
clat = median((clat11))
clong = median((clong11))
cz1.writerow([bs[i], clong, clat]) # appending not found.
fz1.close()