Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7 from mtb14006/master
Commit of MATLAB Files
  • Loading branch information
JRM13027 committed May 10, 2019
2 parents 7ae9dd4 + 83787a7 commit e4ea08d
Show file tree
Hide file tree
Showing 124 changed files with 127,963 additions and 0 deletions.
Binary file added MATLAB_Functions/HuskyTrack.mltbx
Binary file not shown.
82 changes: 82 additions & 0 deletions MATLAB_Functions/HuskyTrack/SenDes_HuskyTrack/GraphData.m
@@ -0,0 +1,82 @@
%
% Function: GraphData
% Author: Michael T. Ballard (michael.ballard@uconn.edu)
% Date: Spring 2019
%
% Description: The GraphData function takes a matrix of data pulled from
% the HuskyTrack Database and translated by this package's
% parsing function and then creates a visualization of this
% data overlaid onto a map of the University of Connecticut.
% If a first and last index are provided, only the subset
% denoted by the indices will be graphed. Any provided
% indices that are beyond the range of the set are ignored.
%
% Parameters: dataMat - A matrix of HuskyTrack Data as parsed by the
% Parser function. This parameter is required.
% first - The index of the first user to be graphed.
% This parameter is optional.
% last - The index of the last user to be graphed.
% This parameter is optional.
%
%
% Return: >0 - The Number of Users Graphed
% Else - Failure
%

function [success] = GraphData(varargin)
dataMat = varargin{1};
[r,c] = size(dataMat);

try
parsed_osm = evalin('base', 'parsed_osm');
catch
try
load('parsed_osm.mat', 'parsed_osm');
catch
disp('Parsed File not found, Parsing...')
parsed_osm = ParseMap();
end
end

fig = figure;
ax = axes('Parent', fig);
hold(ax, 'on');

plot_way(ax, parsed_osm);
hold(ax, 'on');

success = 0;
if(nargin == 1)
for i = 1:r
plot([dataMat(i).locations.longitude], [dataMat(i).locations.latitude]);
hold(ax, 'on');
success = success+1;
end
hold(ax, 'off');
elseif(nargin == 3)
first = varargin{2};
last = varargin{3};

for i = 1:r
if(i >= first & i <= last)
plot([dataMat(i).locations.longitude], [dataMat(i).locations.latitude]);
hold(ax, 'on');
success = success + 1;
end
end
hold(ax, 'off');
else
error('GraphData may take only 1 or 3 inputs (dataMat) or (dataMat, first, last)')
end
end

% Parse the map if a parsed version does not exist
function [parsed_osm, osm_xml] = ParseMap()

openOSM = 'map.osm';
[parsed_osm, osm_xml] = parse_openstreetmap(openOSM);
save('parsed_osm.mat', 'parsed_osm');
assignin('base','parsed_osm',parsed_osm);

end

34 changes: 34 additions & 0 deletions MATLAB_Functions/HuskyTrack/SenDes_HuskyTrack/PullData.m
@@ -0,0 +1,34 @@
%
% Function: PullData
% Author: Michael T. Ballard (michael.ballard@uconn.edu)
% Date: Spring 2019
%
% Description: The PullData function opens a TCP connection to the
% specified host and places a query to the database designed for the
% HuskyTrack System. The response to this query is then collected and
% stored for further manipulations and analysis. Note that
% time is always considered to be 12:00 AM Midnight, thus the
% end date is exclusive.
%
% Parameters: url - A URL to access the host database's API from
% ie. 'http://sdp40.cse.uconn.edu/api/'
% startTime - A time stamp to indicate the earliest desired
% data. In the form 'YYYYMMDD', ie. 20190503
% (May 3, 2019)
% endTime - A time stamp to indicate the latest desired
% data. In the form 'YYYYMMDD', ie. 20190503
% (May 3, 2019)
%
% Return: dataMat - A struct containing all users and their
% location data retrieved from the host
%

function [dataMat] = PullData(url, startTime, endTime)

api = [url 'locationdata?start=' startTime 'T000000&end=' endTime 'T000000'];
options = weboptions('ContentType', 'json');
data = webread(api);
dataMat = jsondecode(data);

end

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<MATLABProject xmlns="http://www.mathworks.com/MATLABProjectFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"/>
25 changes: 25 additions & 0 deletions MATLAB_Functions/HuskyTrack/SenDes_HuskyTrack/SortData.m
@@ -0,0 +1,25 @@
%
% Function: SortData
% Author: Michael T. Ballard (michael.ballard@uconn.edu)
% Date: Spring 2019
%
% Description: The SortData function sorts a HuskyTrack retrieved data
% struct by the timestamp of each location point. Should not
% be necessary for data taken directly from th database.
%
% Parameters: dataMat - A matrix of HuskyTrack Data to be sorted
%
%
% Return: 0 - Successful Termination
%
function [success] = SortData(dataMat)

[r,c] = size(dataMat);

for i = 1:r
[tmp ind] = sort({dataMat(i).locations.timestamp});
dataMat(i) = dataMat(i).locations(ind);
end

end

0 comments on commit e4ea08d

Please sign in to comment.