PHD Project - Driver energy prediction
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

2 years ago
function upload_computed_data(data, chunksize)
if nargin < 2
chunksize = 2500;
end
nchunks = ceil(height(data) / chunksize);
firstchunk = true;
for n = 1:nchunks
from = (n-1) * chunksize + 1;
to = min(n * chunksize, height(data));
chunk = data(from:to, :);
csvname = [tempname() '.csv'];
writetable(chunk, csvname);
gzname = gzip(csvname);
delete(csvname);
import matlab.net.http.*
import matlab.net.http.io.*
fp = FileProvider(gzname);
if firstchunk
% UGLY INFLEXIBLE HACK
userdata = data.Properties.UserData;
userdata{1,3}.duration = milliseconds(userdata{1,3}.duration);
mfp = MultipartFormProvider('file', fp, 'userdata', StringProvider(jsonencode(userdata)));
else
mfp = MultipartFormProvider('file', fp);
end
req = RequestMessage('post', HeaderField('Auth', 'Qnb7jfeGZM'), mfp);
url = 'https://driver-observer.thi.de/upload_computed_data.php';
if firstchunk
url = strcat(url,'?clear=1');
firstchunk = false;
end
res = req.send(url);
delete(gzname{1});
if res.StatusCode ~= StatusCode.OK
throw(MException('upload_computed_data:http_error', ...
'HTTP Error %s (%s); Body: %s', string(res.StatusCode), ...
string(getReasonPhrase(res.StatusCode)), res.Body.Data));
end
end
end