Skip to content

Updating Private Repo #1

Merged
merged 30 commits into from May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7de41f9
Initial roundup of Ionic files
JRM13027 Nov 30, 2018
79c14ea
Initial commit of Ionic files
JRM13027 Nov 30, 2018
ca862a6
Adding plugin files
JRM13027 Dec 1, 2018
bab15d6
Added a single file archive of the repository to work around nested g…
JRM13027 Dec 1, 2018
ad631d3
added some rationale to the readme, for realzies...
JRM13027 Dec 1, 2018
699046b
tweaked interface. updated config.xml to account for plugin
JRM13027 Dec 2, 2018
92ad8c0
putting web app into project
rkv14001 Dec 5, 2018
b1caa5f
adding .gitignore
rkv14001 Dec 5, 2018
e74fcea
update README for webapp
rkv14001 Dec 5, 2018
4fc4e1f
Merge pull request #1 from rkv14001/web-app
JRM13027 Dec 15, 2018
3246702
integrated plugin
JRM13027 Jan 16, 2019
9c520c9
GPS Plugin now tracks locations within a specified radius at UCONN. U…
JRM13027 Feb 22, 2019
4b4c1ac
API - initial commit
mrd14005 Feb 27, 2019
ef88c75
Merge pull request #2 from mrd14005/master
JRM13027 Mar 4, 2019
02cd949
iOS and Android are feature parity
JRM13027 Apr 3, 2019
b2a7d39
web app update
rkv14001 Apr 11, 2019
4351a21
update views
rkv14001 Apr 12, 2019
986ab60
Merge pull request #3 from rkv14001/web-app
JRM13027 Apr 12, 2019
5104c61
next build
rkv14001 Apr 23, 2019
1bfae86
next build
rkv14001 Apr 23, 2019
04f3256
Merge pull request #4 from rkv14001/web-app
JRM13027 Apr 25, 2019
fb99584
fixing timepicker bug
rkv14001 Apr 25, 2019
1f373fd
Merge pull request #5 from rkv14001/web-app
JRM13027 Apr 26, 2019
c3e45aa
Add Ionic 4 app as its own side directory. Will remove the old one ne…
JRM13027 Apr 27, 2019
f76f9c4
removed old mobile app
JRM13027 Apr 27, 2019
0aefaa1
Update README.md
JRM13027 Apr 27, 2019
f1c12d5
Updates
mrd14005 May 8, 2019
6eb3472
Merge branch 'master' of https://github.uconn.edu/mrd14005/GPS-Tracki…
mrd14005 May 8, 2019
4962332
Merge branch 'master' of https://github.uconn.edu/JRM13027/GPS-Tracki…
mrd14005 May 8, 2019
7ae9dd4
Merge pull request #6 from mrd14005/master
JRM13027 May 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
40 changes: 40 additions & 0 deletions API/DataObjects.py
@@ -0,0 +1,40 @@
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, Binary, Float
from sqlalchemy.orm import relationship, sessionmaker, deferred
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.ext.declarative import declarative_base

from datetime import datetime

Base = declarative_base()

class LocationData(Base):
"""
Location Data for HuskyTrack
Attributes:
uuid: The Location Data's universally unique identifier
uid: The user ID of the user this data belongs to
latitude: The latitude of the device when this measurement was taken
longitude: The longitude of the device when this measurement was taken
accuracy: The accuracy of the measurement as reported by the device
speed: The speed of the device when this measurement was taken
heading: The heading of the device when this measurement was taken
altitude: The altitude of the device when this measurement was taken
timestamp: The time at which this measurement was taken [ISO-8601 UTC]
"""

__tablename__ = 'location_data'

uuid = Column('uuid', String, primary_key=True)
uid = Column('uid', String, nullable=False)
latitude = Column('latitude', Float, nullable=False)
longitude = Column('longitude', Float, nullable=False)
accuracy = Column('accuracy', Float, nullable=False)
speed = Column('speed', Float, nullable=False)
heading = Column('heading', Float, nullable=False)
altitude = Column('altitude', Float, nullable=False)
timestamp = Column('timestamp', String, nullable=False)

def __repr__(self):
return self.uuid
Binary file added API/DataObjects.pyc
Binary file not shown.
Binary file added API/__pycache__/DataObjects.cpython-36.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions API/apache_conf.conf
@@ -0,0 +1,13 @@
<VirtualHost *>
ServerName sdp40.cse.uconn.edu

LoadModule wsgi_module "/var/www/api/env/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

WSGIDaemonProcess HuskyTrackAPI threads=1
WSGIProcessGroup HuskyTrackAPI
WSGIScriptAlias /api /var/www/api/HuskyTrackAPI.wsgi process-group=HuskyTrackAPI application-group=%{GLOBAL}
<Directory /var/www/api>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
160 changes: 160 additions & 0 deletions API/api.py
@@ -0,0 +1,160 @@
import configparser
import sys
import json
from datetime import datetime

from flask import Flask, request, g

from DataObjects import LocationData
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from collections import defaultdict

app = Flask(__name__)

ISO8601 = "%Y%m%dT%H%M%S"
ISO8601_O = "%Y-%m-%d %H:%M:%S"


def get_config():
"""
Get the configuration data for the application
"""
try:
config = configparser.SafeConfigParser()
config.read('config.ini')
return config
except Exception as e:
print("No configuration file found.", e)
sys.exit()

def get_session(config):
"""
Attempt to initialize the database session, quit if the
program cannot find the database.
"""
try:
# Collect Configuration
dao_type = config.get('database', 'type').lower()
username = config.get('database', 'username')
password = config.get('database', 'pass')
host = config.get('database', 'host')
port = config.get('database', 'port')
database = config.get('database', 'database')

# Build URL
if dao_type == 'sqlite':
url = dao_type + ":///" + host
else:
url = dao_type + "://" + username +\
":" + password + "@" + host + \
":" + port + "/" + database

# Create session
engine = create_engine(url)
Session = sessionmaker(bind=engine)
session = getattr(g, '_session', None)
if session is None:
session = Session()
return session

except Exception as e:
print("Unable to configure database connection. Error:", e)
sys.exit()

@app.route('/', methods=('GET', 'POST'))
def test():
if request.method == 'POST':
print (request.get_json())
return "Success"

@app.route('/api')
def api():
"""
Returns the version for compatibility/availability checks"
"""
return 'v0.1'

@app.route('/api/locationdata', methods=('GET', 'POST'))
def location_data():
"""
Request or post location data
"""
session = get_session(get_config())
if request.method == 'POST':
if request.is_json:
try:
raw_location_data = request.get_json()
locations = raw_location_data["location"]
uid = raw_location_data["user_id"]
for location in locations:
coords = location["coords"]
lat = coords["latitude"]
lng = coords["longitude"]
acc = coords["accuracy"]
spd = coords["speed"]
hed = coords["heading"]
alt = coords["altitude"]
tim = location["timestamp"]
uuid = location["uuid"]
locationData = LocationData(uuid = uuid,
uid = uid,
latitude = lat,
longitude = lng,
accuracy = acc,
speed = spd,
heading = hed,
altitude = alt,
timestamp = tim)
session.add(locationData)
session.commit()
return "Success"
except Exception as e:
session.rollback()
return ("Fail", str(e))
else:
return "NOT JSON"
else:
if 'start' and 'end' in request.args:
start = request.args.get('start')
end = request.args.get('end')

start = datetime.strptime(start, ISO8601)
end = datetime.strptime(end, ISO8601)

print(str([str(start), str(end)]))
query_results = session.query(LocationData).filter(LocationData.timestamp > start, LocationData.timestamp < end).all()

dataPoints = defaultdict(list)
for result in query_results:
dataPoints[result.uid].append(result)

result = []
for user in dataPoints:
print(user)
json_entry = json.loads('{}')
json_entry['user_id'] = user
json_entry['start_time'] = min(dataPoints[user], key=lambda x:x.timestamp).timestamp
json_entry['end_time'] = max(dataPoints[user], key=lambda x:x.timestamp).timestamp
json_entry['locations'] = []
for location in dataPoints[user]:
json_location = json.loads('{}')
json_location['latitude'] = location.latitude
json_location['longitude'] = location.longitude
json_location['timestamp'] = location.timestamp
json_entry['locations'].append(json_location)
result.append(json_entry)

return json.dumps(result)
else:
return json.dumps([[l.uuid, l.latitude, l.longitude, l.timestamp] for l in session.query(LocationData).all()])

@app.teardown_appcontext
def close_connection(exception):
session = getattr(g, '_session', None)
if session is not None:
session.close()

if __name__ == '__main__':
app.run(host='0.0.0.0', port=44)
7 changes: 7 additions & 0 deletions API/config.ini
@@ -0,0 +1,7 @@
[database]
type = sqlite
host = C:\Users\demel\Documents\GitHub\GPS-Tracking-of-On-Campus-Walking-Project\API\db\test.db
username = mason
pass = mason
port = 3306
database = mason
14 changes: 14 additions & 0 deletions API/db/init_sqlite.sql
@@ -0,0 +1,14 @@
BEGIN TRANSACTION;
DROP TABLE IF EXISTS `location_data`;
CREATE TABLE IF NOT EXISTS `location_data` (
`uuid` TEXT NOT NULL PRIMARY KEY UNIQUE,
`uid` TEXT NOT NULL,
`latitude` REAL NOT NULL,
`longitude` REAL NOT NULL,
`accuracy` REAL NOT NULL,
`speed` REAL NOT NULL,
`heading` REAL NOT NULL,
`altitude` REAL NOT NULL,
`timestamp` TEXT NOT NULL
);
COMMIT;
Binary file added API/db/test.db
Binary file not shown.