def Launch_Locator(password): db = Database(password) cur = db.get_cur() halligan_two = os.path.join('static_files/', 'Halligan_2.png') cur.execute("""SELECT x, y from marauder_demhoes order by id desc limit 1 """) row = cur.fetchone() if row is not None: x = int(float(row[0])) y = int(float(row[1])) image = Image.open(halligan_two) radius = 5 # point radius draw_image = ImageDraw.Draw(image) draw_image.ellipse((x-radius, y-radius, x+radius, y+radius), fill='blue', outline='red') image.show() image.close()
def dump(password, output_file): db = Database(password) cur = db.get_cur() fp = open('output/{}'.format(output_file), 'w+') cur.execute(q2) access_points = cur.fetchall() res = [] for f in access_points: print f msg = { 'floor_id': f[0], 'location_id': f[1], 'x': f[2], 'y': f[3], 'direction': f[4], 'macs': f[5].split(','), 'rss': map(float, f[6].split(',')) } print json.dumps(msg) res.append(msg) json.dump(res, fp) fp.close()
def Analyse(password): db = Database(password) cur = db.get_cur() count = 0 sum_data = [[0 for i in range(5)] for j in range(5)] for ts_id, id_list in enumerate(ids): for t_id, ID in enumerate(id_list): names[str(ID)] = titles[ts_id][t_id] data = {} if len(id_list) != 5: continue cur.execute("""SET SESSION group_concat_max_len = 1000000""") cur.execute("""SELECT accesspoint.location_id, GROUP_CONCAT(MAC) as MAC_list, GROUP_CONCAT(strength) as strength_list, GROUP_CONCAT(std_dev) as std_list from marauder_accesspoint join marauder_location on location.id=accesspoint.location_id where location.id in (%s,%s,%s,%s,%s) group by accesspoint.location_id,x,y,direction""", id_list) all_macs = [] for row in cur.fetchall(): data[str(row[0])] = {"mac": row[1].split(","), "strengths": [float(r) for r in row[2].split(",")]} # "stds": [float(r) for r in row[3].split(",")]} all_macs.append( row[1].split(",") ) if not all_macs: continue count += 1 unique_macs = set(flatten(all_macs)) unique = len(unique_macs) if PRINT_TABLES: print "All {} accesspoints".format(unique) ks = [" " * 20] for k in sorted(data.keys(),key=lambda x: int(names[x].split()[0])): ks.append(names[str(k)].rjust(15)) print ' '.join(ks) mac_dict = {} for mac_addr in unique_macs: mac_dict[mac_addr] = [] MAC_Counts = [] for k,vals in sorted(data.iteritems(),key=lambda x: int(names[x[0]].split()[0])): MAC_counter = 0 for mac_addr in unique_macs: index = get_index(vals["mac"], mac_addr) if index != -1: mac_dict[mac_addr].append(str(round(vals["strengths"][index],2)).rjust(15)) MAC_counter += 1 else: mac_dict[mac_addr].append("-".rjust(15)) MAC_Counts.append(MAC_counter) for k,v in mac_dict.iteritems(): print k.rjust(20), ' '.join(v) print "Total Macs".rjust(20), ' '.join([str(x).rjust(15) for x in MAC_Counts]) intermacs = intersection(all_macs) stds = [] print "Comparing {} common mac addresses of {} unique".format(len(intermacs),unique) for imac in intermacs: L = {} for k in data.keys(): L[k] = [] for k,vals in sorted(data.iteritems()): L[k].append( vals["strengths"][vals["mac"].index(imac)] ) ks = [" " * 10] for k in sorted(L.keys(),key=lambda x: int(names[x].split()[0])): ks.append(names[str(k)].rjust(10)) print ' '.join(ks) sorted_items = sorted(L.iteritems(),key=lambda x: int(names[x[0]].split()[0])) for i,(k,v) in enumerate(sorted_items): d = [names[str(k)].ljust(10)] for j,(key,val) in enumerate(sorted_items): diff = difference(val,v) sum_data[i][j] += diff d.append(str( round(diff ,2) ).rjust(10) ) print ' '.join(d) print print if count == 0: return print "Average Table:" for i in sum_data: print ' '.join([str( round(x / float(count), 2) ).rjust(10) for x in i])
from db.db import Database import os from PIL import Image, ImageDraw SHOW = False # Determines if images are shown or merely saved password = os.environ.get('SIRIUS_PASSWORD') radius = 5 # point radius if password is None: raise Exception('No password available') db = Database(password) cur = db.get_cur() path_offset = "../Static_Files/" # Path offset from cwd to image directory def overlay(FID1, FID2): """Given 2 arrays of (x,y) and an image will plot points on the same image. This is useful when plotting test points and gathered points on the same map. The saved image will be saved as floor_FID1_AND_FID2.png. The image paths are assumed the same and the image from FID1 is used. Points from FID1 are in blue while points from FID2 are in red.""" cur.execute("""SELECT imagePath from floor where id=%s""",[FID1]) floor_path = cur.fetchone() if not floor_path: return imagePath = floor_path[0] #extracting string from tuple