fullruntic = tic;

rclonePath = 'C:\Users\spraydata\rclone\rclone.exe';
remoteFile = 'remote:7day-sensor-data_resampled.parquet';
localFolder = '\\atlas.shore.mbari.org\ProjectLibrary\901805_Coastal_Biogeochemical_Sensing\Locness\ParquetPartitions';

% DOWNLOAD DATA
datadownloadtic = tic;
% command = sprintf('"%s" copy %s "%s"', ...
%     rclonePath, remoteFile, localFolder);

command = sprintf('"%s" copy %s "%s" --checksum', ...
    rclonePath, remoteFile, localFolder);

[status, ~] = system(command);
downloadStatus = (status == 0);
fprintf('Data download took %.2f seconds.\n', toc(datadownloadtic));

% ASSEMBLE DATA
assembledata = tic;
vars = {'timestamp', 'lat', 'lon', 'rhodamine', 'ph', 'temp', 'salinity', 'ph_ma'};
pds = parquetDatastore("ParquetPartitions","IncludeSubfolders",true,"OutputType","table","SelectedVariableNames",vars);
T = pds.readall;
fprintf('Data assembly took %.2f seconds.\n', toc(assembledata));

% BUILD TIMETABLE
buildtimetabletic = tic;
if ~isdatetime(T.timestamp)
    T.Time = datetime(T.timestamp, 'InputFormat', 'yyyy-MM-dd HH:mm:ss', "TimeZone", "UTC");
else
    T.Time = T.timestamp;
end
tempTT = table2timetable(T, 'RowTimes', 'Time'); 

% Resample
n = 5; % minutes
TT = retime(tempTT, 'regular', 'mean', 'TimeStep', minutes(n));
fprintf('Timetable build + resample took %.2f seconds.\n', toc(buildtimetabletic));

% Total runtime
fprintf('Total runtime: %.2f seconds.\n', toc(fullruntic));
%%
% tic
% handler = ShipDataHandler();
% handler.downloadData();
% handler.resampleData(5);
% toc