├── AndroidApp ├── .gitignore ├── ic_launcher-web.png ├── libs │ ├── gson-2.3.jar │ ├── okio-1.0.1.jar │ ├── okhttp-2.0.0.jar │ └── android-support-v4.jar ├── ant.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values │ │ ├── strings.xml │ │ ├── urls.xml │ │ ├── location_names.xml │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── layout │ │ ├── list_item_wifi.xml │ │ └── activity_main.xml ├── src │ └── com │ │ └── zackaryscholl │ │ └── wifilocation │ │ └── scanner │ │ ├── WifiScanApplication.java │ │ ├── WifiPoint.java │ │ ├── ViewResultsActivity.java │ │ ├── UploadService.java │ │ └── ScanActivity.java ├── .classpath ├── project.properties ├── .settings │ └── org.eclipse.jdt.core.prefs ├── proguard-project.txt ├── .project ├── AndroidManifest.xml └── build.xml ├── RaspberryPi ├── db │ └── data.db ├── dbsetup.py ├── server.py ├── update.php ├── databasecommands.py ├── index.html ├── calculatePriors.py └── server_com.py ├── README.md └── LICENSE /AndroidApp/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | bin 3 | gen 4 | *.jar.properties 5 | local.properties 6 | -------------------------------------------------------------------------------- /RaspberryPi/db/data.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/RaspberryPi/db/data.db -------------------------------------------------------------------------------- /AndroidApp/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/ic_launcher-web.png -------------------------------------------------------------------------------- /AndroidApp/libs/gson-2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/libs/gson-2.3.jar -------------------------------------------------------------------------------- /AndroidApp/libs/okio-1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/libs/okio-1.0.1.jar -------------------------------------------------------------------------------- /AndroidApp/ant.properties: -------------------------------------------------------------------------------- 1 | application.package=com.zackaryscholl.wifilocation.scanner 2 | java.target=1.7 3 | java.source=1.7 4 | -------------------------------------------------------------------------------- /AndroidApp/libs/okhttp-2.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/libs/okhttp-2.0.0.jar -------------------------------------------------------------------------------- /AndroidApp/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/libs/android-support-v4.jar -------------------------------------------------------------------------------- /AndroidApp/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidApp/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidApp/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidApp/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jschools/wifi_triangulation/HEAD/AndroidApp/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidApp/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WiFi Scanner 4 | %1$,d data points collected 5 | 6 | 7 | -------------------------------------------------------------------------------- /AndroidApp/res/values/urls.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | http://morning-wave-7971.herokuapp.com/ 6 | 7 | -------------------------------------------------------------------------------- /AndroidApp/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /AndroidApp/src/com/zackaryscholl/wifilocation/scanner/WifiScanApplication.java: -------------------------------------------------------------------------------- 1 | package com.zackaryscholl.wifilocation.scanner; 2 | 3 | import android.app.Application; 4 | 5 | public class WifiScanApplication extends Application { 6 | 7 | private static WifiScanApplication sInstance; 8 | 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | 13 | sInstance = this; 14 | } 15 | 16 | public static WifiScanApplication getInstance() { 17 | return sInstance; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AndroidApp/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /AndroidApp/res/values/location_names.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | Room 0 10 | Room 1 11 | Room 2 12 | Room 3 13 | Room 4 14 | Room 5 15 | 16 | 17 | -------------------------------------------------------------------------------- /AndroidApp/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-20 15 | -------------------------------------------------------------------------------- /AndroidApp/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.7 12 | -------------------------------------------------------------------------------- /AndroidApp/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /RaspberryPi/dbsetup.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import hashlib 3 | 4 | exec(open('databasecommands.py').read()) 5 | 6 | DB = DataBase('db/data.db') 7 | 8 | # 9 | #SET UP INITIAL TABLES 10 | # 11 | 12 | #locations TABLE 13 | 14 | if not DB.tableExists('locations'): 15 | print('no table "locations"... making one now...') 16 | #lat: latitude 17 | #long: longitude 18 | #time: unix time stamp, unixepoch 19 | DB.createTable('locations ('\ 20 | +'id INTEGER PRIMARY KEY AUTOINCREMENT, '\ 21 | +'mac TEXT, '\ 22 | +'rssi INTEGER, '\ 23 | +'room INTEGER, '\ 24 | +'time INTEGER'\ 25 | +')') 26 | else: 27 | print('already "locations" table') 28 | 29 | print('adding test data...') 30 | if DB.getData(1): 31 | print('already data..') 32 | else: 33 | DB.addData('none',0,0) 34 | 35 | def _resetDB(): 36 | DB.dropTable('locations') 37 | DB.close() 38 | -------------------------------------------------------------------------------- /AndroidApp/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /AndroidApp/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | WifiLocationAndroid 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /RaspberryPi/server.py: -------------------------------------------------------------------------------- 1 | import tornado.httpserver 2 | import tornado.websocket 3 | import tornado.ioloop 4 | import tornado.web 5 | import time 6 | import socket 7 | import sys 8 | 9 | def get_lock(process_name): 10 | global lock_socket 11 | lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) 12 | try: 13 | lock_socket.bind('\0' + process_name) 14 | print 'I got the lock' 15 | except socket.error: 16 | print 'lock exists' 17 | sys.exit() 18 | 19 | class WSHandler(tornado.websocket.WebSocketHandler): 20 | clients = [] 21 | def open(self): 22 | self.clients.append(self) 23 | print 'New connection was opened' 24 | self.write_message("Con!") 25 | 26 | def on_message(self, message): 27 | #print 'Got :', message 28 | for s in self.clients: 29 | s.write_message(message) 30 | 31 | def on_close(self): 32 | self.clients.remove(self) 33 | print 'Conn closed...' 34 | 35 | application = tornado.web.Application([ 36 | (r'/ws', WSHandler), 37 | ]) 38 | 39 | 40 | if __name__ == "__main__": 41 | get_lock('server_python') 42 | http_server = tornado.httpserver.HTTPServer(application) 43 | http_server.listen(9003) 44 | tornado.ioloop.IOLoop.instance().start() 45 | 46 | -------------------------------------------------------------------------------- /AndroidApp/res/layout/list_item_wifi.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 23 | 24 | 31 | 32 | 39 | 40 | -------------------------------------------------------------------------------- /AndroidApp/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /AndroidApp/src/com/zackaryscholl/wifilocation/scanner/WifiPoint.java: -------------------------------------------------------------------------------- 1 | package com.zackaryscholl.wifilocation.scanner; 2 | 3 | import android.net.wifi.ScanResult; 4 | import android.os.Parcel; 5 | import android.os.Parcelable; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | public class WifiPoint implements Parcelable { 10 | 11 | @SerializedName("mac") 12 | public final String macAddress; 13 | 14 | @SerializedName("rssi") 15 | public final int rssi; 16 | 17 | @SerializedName("room") 18 | public final int location; 19 | 20 | @SerializedName("time") 21 | public final long timestamp; 22 | 23 | public WifiPoint(ScanResult scanResult, int location, long time) { 24 | macAddress = scanResult.BSSID; 25 | rssi = scanResult.level; 26 | this.location = location; 27 | timestamp = time; 28 | } 29 | 30 | @Override 31 | public int describeContents() { 32 | return 0; 33 | } 34 | 35 | @Override 36 | public void writeToParcel(Parcel dest, int flags) { 37 | dest.writeString(macAddress); 38 | dest.writeInt(rssi); 39 | dest.writeInt(location); 40 | dest.writeLong(timestamp); 41 | } 42 | 43 | private WifiPoint(Parcel in) { 44 | macAddress = in.readString(); 45 | rssi = in.readInt(); 46 | location = in.readInt(); 47 | timestamp = in.readLong(); 48 | } 49 | 50 | public static final Creator CREATOR = new Creator() { 51 | @Override 52 | public WifiPoint createFromParcel(Parcel source) { 53 | return new WifiPoint(source); 54 | } 55 | 56 | @Override 57 | public WifiPoint[] newArray(int size) { 58 | return new WifiPoint[size]; 59 | } 60 | 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /RaspberryPi/update.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 39 | $query = " 40 | INSERT INTO locations ( 41 | mac, 42 | rssi, 43 | room, 44 | time 45 | ) VALUES ( 46 | :mac, 47 | :rssi, 48 | :room, 49 | :time 50 | ) 51 | "; 52 | 53 | $stmt = $db->prepare($query); 54 | $stmt->bindValue(':mac', (string) $mac, SQLITE3_TEXT); 55 | $stmt->bindValue(':rssi', (float) $rssi, SQLITE3_INTEGER); 56 | $stmt->bindValue(':room', (float) $room, SQLITE3_INTEGER); 57 | $stmt->bindValue(':time', (float) $time, SQLITE3_INTEGER); 58 | $stmt->execute(); 59 | // close database 60 | $db = null; 61 | } 62 | catch(Exception $e) { 63 | //print $e; 64 | } 65 | } 66 | } 67 | 68 | 69 | // read the POST body 70 | $request_body = file_get_contents('php://input'); 71 | 72 | // decode the JSON 73 | $data_points = json_decode($request_body, true); 74 | 75 | // loop over the elements of the array, inserting each one into the db 76 | $num_points = 0; 77 | foreach ($data_points as $data_point) { 78 | insert_data_point($data_point); 79 | $num_points++; 80 | } 81 | 82 | // respond with the number of points we inserted 83 | echo $num_points; 84 | 85 | // TODO: add gzip compression support 86 | // TODO: send http_response_code(400) for bad requests 87 | 88 | ?> 89 | -------------------------------------------------------------------------------- /RaspberryPi/databasecommands.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import hashlib 3 | import re 4 | 5 | class DataBase: 6 | 7 | def __init__(self,name): 8 | self.name = name 9 | self.conn = sqlite3.connect(self.name) 10 | self.c = self.conn.cursor() 11 | 12 | 13 | def close(self): 14 | self.conn.close() 15 | self.conn = None 16 | self.c = None 17 | 18 | 19 | '''DATA''' 20 | 21 | 22 | def getAllData(self): 23 | return [row for row in self.c.execute('SELECT * FROM locations')] 24 | 25 | #NOT USER INPUT#id: auto generated just add null 26 | #lat: latitude 27 | #long: longitude 28 | #NOT USER INPUT#date: YYYY-MM-DD HH:MM:SS 29 | def addData(self,mac,rssi,room): 30 | self.c.execute('SELECT strftime("%s","now")') 31 | date = self.c.fetchone()[0] 32 | self.c.execute('INSERT INTO locations VALUES (?,?,?,?,?)',(None,mac,rssi,room,date)) 33 | id = self.c.lastrowid 34 | #remember to commit changes so we don't lock the db! 35 | self.conn.commit() 36 | return True 37 | 38 | def removeData(self,id): 39 | self.c.execute('DELETE FROM locations WHERE id=?',(id,)) 40 | self.conn.commit() 41 | 42 | def getData(self,id): 43 | return [row for row in self.c.execute('SELECT * FROM locations WHERE id=(?)',(id,))] 44 | 45 | 46 | ''' 47 | 48 | GENERAL TABLE COMMANDS 49 | 50 | ''' 51 | 52 | 53 | #returns true if table exists 54 | def tableExists(self,table_name): 55 | self.c.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name=?;',(table_name,)) 56 | return not self.c.fetchone()[0] is 0 57 | 58 | 59 | #builds table if doesn't already exist 60 | #-a little sketchy 61 | def createTable(self,table_data): 62 | if self.tableExists(table_data): 63 | return False 64 | else: 65 | self.c.execute('CREATE TABLE %s;' % table_data) 66 | self.conn.commit() 67 | return True 68 | 69 | 70 | #drops table 71 | #-a little sketchy 72 | def dropTable(self,table_name): 73 | if self.tableExists(table_name): 74 | self.c.execute('DROP TABLE %s' % table_name) 75 | self.conn.commit() 76 | return True 77 | else: 78 | return False 79 | -------------------------------------------------------------------------------- /AndroidApp/src/com/zackaryscholl/wifilocation/scanner/ViewResultsActivity.java: -------------------------------------------------------------------------------- 1 | package com.zackaryscholl.wifilocation.scanner; 2 | 3 | import java.util.List; 4 | 5 | import android.app.ListActivity; 6 | import android.content.Context; 7 | import android.os.Bundle; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ArrayAdapter; 12 | import android.widget.TextView; 13 | 14 | public class ViewResultsActivity extends ListActivity { 15 | 16 | public static final String EXTA_POINTS = ViewResultsActivity.class.getName() + ".EXTRA_POINTS"; 17 | 18 | private List mPoints; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | mPoints = getIntent().getParcelableArrayListExtra(EXTA_POINTS); 25 | setListAdapter(new WifiPointAdapter(this, mPoints)); 26 | } 27 | 28 | private static class WifiPointAdapter extends ArrayAdapter { 29 | 30 | public WifiPointAdapter(Context context, List objects) { 31 | super(context, R.layout.list_item_wifi, objects); 32 | } 33 | 34 | @Override 35 | public View getView(int position, View convertView, ViewGroup parent) { 36 | View v = convertView; 37 | ViewHolder holder; 38 | if (v == null) { 39 | v = LayoutInflater.from(getContext()).inflate(R.layout.list_item_wifi, parent, false); 40 | holder = new ViewHolder(v); 41 | v.setTag(holder); 42 | } 43 | else { 44 | holder = (ViewHolder) v.getTag(); 45 | } 46 | 47 | final WifiPoint point = getItem(position); 48 | holder.position.setText(Integer.toString(position)); 49 | holder.mac.setText("MAC: " + point.macAddress); 50 | holder.rssi.setText("RSSI: " + point.rssi); 51 | holder.location.setText("Location: " + point.location); 52 | 53 | return v; 54 | } 55 | 56 | private static class ViewHolder { 57 | public final TextView position; 58 | public final TextView mac; 59 | public final TextView rssi; 60 | public final TextView location; 61 | 62 | public ViewHolder(View v) { 63 | position = (TextView) v.findViewById(R.id.position); 64 | mac = (TextView) v.findViewById(R.id.mac); 65 | rssi = (TextView) v.findViewById(R.id.rssi); 66 | location = (TextView) v.findViewById(R.id.location); 67 | } 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /RaspberryPi/index.html: -------------------------------------------------------------------------------- 1 | 2 | WiFi IPS 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 68 | 69 | 70 | 71 | 72 | 73 |
74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /RaspberryPi/calculatePriors.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import cPickle as pickle 3 | import math 4 | from sqlite3 import connect 5 | 6 | conn = connect('/var/www/where3/db/data.db') # use your own location here 7 | 8 | # Determine all unique rooms and mac addressed automatically 9 | c = conn.cursor() 10 | macs = [] 11 | for row in c.execute("select distinct mac from locations where room>0"): 12 | macs.append(str(row[0]).decode('utf-8')) 13 | 14 | rooms = [] 15 | for row in c.execute("select distinct room from locations where room>0"): 16 | rooms.append(str(row[0]).decode('utf-8')) 17 | 18 | # Initialize probabilities 19 | P={} 20 | nP={} 21 | Wdefault = {} 22 | for mac in macs: 23 | Wdefault[mac]=0 24 | P[mac]={} 25 | nP[mac]={} 26 | nP[mac] = numpy.zeros(100) 27 | for room in rooms: 28 | P[mac][room] = numpy.zeros(100) 29 | 30 | # Add a Gaussian centered around RSSI with STD of 1 RSSI - this takes awhile 31 | for mac in macs: 32 | for room in rooms: 33 | for row in c.execute("select rssi from (select rssi from locations where mac like '" + mac + "' and room=" + str(room) + ")"): 34 | try: 35 | P[mac][room][row[0]+100]=P[mac][room][row[0]+100]+0.4 36 | P[mac][room][row[0]+99]=P[mac][room][row[0]+99]+0.14 37 | P[mac][room][row[0]+101]=P[mac][room][row[0]+101]+0.14 38 | P[mac][room][row[0]+98]=P[mac][room][row[0]+98]+0.06 39 | P[mac][room][row[0]+102]=P[mac][room][row[0]+102]+0.06 40 | P[mac][room][row[0]+97]=P[mac][room][row[0]+97]+0.06 41 | P[mac][room][row[0]+103]=P[mac][room][row[0]+103]+0.06 42 | except Exception,e: 43 | print str(e) 44 | for row in c.execute("select rssi from locations where mac like '" + mac + "' and room>0"): 45 | try: 46 | nP[mac][row[0]+100]=nP[mac][row[0]+100]+0.4 47 | nP[mac][row[0]+99]=nP[mac][row[0]+99]+0.14 48 | nP[mac][row[0]+101]=nP[mac][row[0]+101]+0.14 49 | nP[mac][row[0]+98]=nP[mac][row[0]+98]+0.06 50 | nP[mac][row[0]+102]=nP[mac][row[0]+102]+0.06 51 | nP[mac][row[0]+97]=nP[mac][row[0]+97]+0.06 52 | nP[mac][row[0]+103]=nP[mac][row[0]+103]+0.06 53 | except Exception,e: 54 | print str(e) 55 | 56 | # close the database 57 | conn.close() 58 | 59 | # Normalize the distributions 60 | for mac in macs: 61 | for room in rooms: 62 | pTotal = sum(P[mac][room]) 63 | if pTotal>0: 64 | for i in range(100): 65 | P[mac][room][i] = P[mac][room][i]/pTotal 66 | npTotal = sum(nP[mac]) 67 | if npTotal>0: 68 | for i in range(100): 69 | nP[mac][i] = nP[mac][i]/npTotal 70 | 71 | # Dumpe them to a pickle 72 | data = pickle.dumps(P,2) 73 | pickle.dump(data,open('P.p','wb')) 74 | data = pickle.dumps(nP,2) 75 | pickle.dump(data,open('nP.p','wb')) 76 | data = pickle.dumps(Wdefault,2) 77 | pickle.dump(data,open('W.p','wb')) 78 | -------------------------------------------------------------------------------- /AndroidApp/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 20 | 21 |