% WRITTEN BY CAGDAS & JUN
classdef MotoActvManager < handle
    %MOTOACTVMANAGER Summary of this class goes here
    %   Detailed explanation goes here
    
    properties (SetAccess = private)
        ctrl;
    end
    
    methods 
        function hr = downloadData(MAM)
        %this method downloads heartrate data from motoactv website
        %if no session is provided, downloads all data
        %currently it cannot download a specific session but downloads all
        o = Main;
        
        javaMethod('main', o, '');
        unzip('test.zip');
        end
        
        function exportToDB(MAM)
        %this method saves downloaded heartrate data to database    
            fileList = dir('workoutdata\CSV');
            k = 1; 
            while k <=size(fileList,1)
                fileList(k).name
                if(size(fileList(k).name,2) >40)
                    session = fileList(k).name(1:length(fileList(k).name)-4);
                    if(~DatabaseManager.doesSessionExistinHR(session,MAM.ctrl.currentUser.id))
                        %add it to db if we don't have it already
                        data = xlsread(['workoutdata\CSV\' fileList(k).name],'c:c');
                        HR = HeartRateData(session);
                        for i=1:length(data)
                            HR.AddData(data(i));
                        end
                        DatabaseManager.saveHeartRateData(HR,MAM.ctrl.currentUser.id);
                    end
                end
                k = k +1;
            end
            
        end
        function MAM = MotoActvManager(controller)
            MAM.ctrl = controller;
        end
    end
    
end

