diff --git a/+ww/formatTable.m b/+ww/formatTable.m
index 6859435..4edc626 100644
--- a/+ww/formatTable.m
+++ b/+ww/formatTable.m
@@ -49,14 +49,18 @@
case 'html'
dataInCells(cellfun('isempty', dataInCells)) = {' '};
% Print the headers
- out = ['
', ...
- strjoin(strip(columnHeaders), ' | '), ' |
'];
- % Print each row
+ out = sprintf(...
+ '\n\n\t%s | \n
',....
+ strjoin(strip(columnHeaders), '\n\t'));
+ % Print each row -
+ % NB: Line breaks are essential to avoid 1000 charecter line limit.
for i = 1:size(dataInCells,1)
- out = [out, ' | ', strjoin(dataInCells(i,:), ...
- ' | '), ' |
'];
+ rowStr = sprintf(...
+ '\n\n\t%s | \n
',...
+ strjoin(dataInCells(i,:), '\n\t'));
+ out = [out, rowStr];
end
- out = [out, ' |
'];
+ out = [out, newline, '
'];
%%% FOR DEBUGGING %%%
if ww.Params().get('Mode') > 0
save(fullfile(userpath, 'printWeekendWaterVars.mat'))
diff --git a/+ww/generate.m b/+ww/generate.m
index a37d480..4ed6376 100644
--- a/+ww/generate.m
+++ b/+ww/generate.m
@@ -32,6 +32,15 @@ function generate(nDays, varargin)
p.parse(varargin{:})
force = p.Results.force;
test = p.Results.test;
+debug = params.get('Mode') > 0 || test;
+% Temp dir for saving log and email
+tmpdir = iff(ispc, getenv('APPDATA'), getenv('HOME'));
+if debug
+ % In debug mode we activate the log
+ diaryState = get(0, 'Diary');
+ diaryFile = get(0, 'DiaryFile');
+ diary(fullfile(tmpdir, 'ww.log'))
+end
% Get list of mice to be trained over the weekend. These will be marked as
% 'PIL' on the list (so long as they've been weighed)
@@ -40,7 +49,7 @@ function generate(nDays, varargin)
% Path to email file which will be sent
filename = sprintf('mail%s.txt', iff(test, '-test', ''));
-mail = fullfile(iff(ispc, getenv('APPDATA'), getenv('HOME')), filename);
+mail = fullfile(tmpdir, filename);
% Check when email was last generated and potentially return if too soon
mod = file.modDate(mail);
@@ -107,14 +116,14 @@ function generate(nDays, varargin)
%% 'Weekend water',...
% Write email to file
-fid = fopen(mail, 'w');
+fid = fopen(mail, 'w', 'n', 'UTF-8');
fprintf(fid, ['From: Alyx Database <%s>\n',...
'Reply-To: Alyx Database <%s>\n',...
'To: %s\nSubject: Weekend Water\n',...
- 'Content-Type: text/html; charset="us-ascii"\n',...
+ 'Content-Type: text/html; charset="utf-8"\n',...
'Content-Transfer-Encoding: quoted-printable\n',...
- 'Mime-version: 1.0\n\n',...
- '\n',...
+ 'Mime-version: 1.0\n\n',...
+ 'Weekend Water Email'...
'\n',...
'Please find below the water table for this weekend. ',...
'Any blank spaces must be filled in manually by the respective ',...
@@ -128,7 +137,7 @@ function generate(nDays, varargin)
cmd = sprintf(['curl "%s:%i" -v --mail-from "%s" ',...
'--mail-rcpt "%s" --ssl -u %s:%s -T "%s" -k --anyauth'],...
params.get('SMTP_Server'), params.get('SMTP_Port'), params.get('E_mail'), ...
- strjoin(to, "' --mail-rcpt '"), getpref('Internet','E_mail'),...
+ strjoin(to, '" --mail-rcpt "'), getpref('Internet','E_mail'),...
getpref('Internet','SMTP_Password'), strrep(mail, '\', '/'));
% Wrap in call to git bash
@@ -142,4 +151,6 @@ function generate(nDays, varargin)
% Restore previous preferences
for prop = string(fieldnames(internetPrefs))'
setpref('Internet', prop, internetPrefs.(prop))
-end
\ No newline at end of file
+end
+% Restore diary state
+if debug, diary(diaryState), set(0, 'DiaryFile', diaryFile), end
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3e3461a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.asv
diff --git a/postWeightsToDev.m b/postWeightsToDev.m
new file mode 100644
index 0000000..ca3b866
--- /dev/null
+++ b/postWeightsToDev.m
@@ -0,0 +1,34 @@
+% This script posts some weights to the dev database so that when we run
+% the weekend water script in test mode the table will get fully populated.
+% One of the mice will not have its weight updated.
+params = ww.Params;
+% Alyx instance
+ai = Alyx('','');
+ai.BaseURL = params.get('ALYX_DEV_URL');
+ai = ai.login(params.get('ALYX_Login'), params.get('ALYX_Password'));
+fprintf('Using test database: %s\n', ai.BaseURL);
+% Post weights to test db:
+wrSubs = ai.getData(ai.makeEndpoint('water-restricted-subjects'));
+% Double-check mice aren't dead (should be done Alyx side)
+alive = ai.listSubjects;
+wrSubs = wrSubs(ismember({wrSubs.nickname}, alive));
+n = params.get('nDaysInFuture');
+
+% Go through posting weights for those that need one
+for iSubject = 1:length(wrSubs)
+ if iSubject == 3, continue, end % Skip the third mouse
+ subject = wrSubs(iSubject).nickname;
+ endpnt = sprintf('water-requirement/%s?start_date=%s&end_date=%s', ...
+ subject, datestr(now - 1, 'yyyy-mm-dd'), datestr(now + n, 'yyyy-mm-dd'));
+ wr = ai.getData(endpnt);
+ records = catStructs(wr.records, nan);
+ % no weighings found
+ if isempty(wr.records) || isnan(records(2).weighing_at)
+ % If the mouse weight has no weight for yesterday, post one around
+ % 25g, otherwise use yesterday's weight.
+ w = iff(isnan(records(1).weighing_at), 24 + rand, records(1).weighing_at);
+ d = ai.postWeight(w, subject);
+ assert(contains(d.url, 'dev') && w == d.weight)
+ end
+end
+