Hi everyone,
As suggested by @yanokwa (thanks!), I will copy/paste here an ODK related issue that I posted on GitHub yesterday. Here it goes, and thanks in advance for your help:
This is my first contribution here [i.e. on GitHub, but on the ODK Forum as well!], from a freshly created GitHub account, so I hope this the right place (and procedure) to post my comment. Please let me know if that's not the case or if I should create a new issue for this.
I'm precisely coming from the link posted by @adammichaelwood ( https://docs.opendatakit.org/form-logic/#when-expressions-are-evaluated ), because I realised that the now()
function doesn't behave (anymore?) as described there. Used on its own (as in the "datetime_last_saved" example), it is evaluated only once when the survey is opened. I've read several discussions here [on GitHub; I couldn't find anything on the ODK forum] about this subject (and related ones) over the past few weeks and I'm not sure where the debate is at today. But because the ODK documentation is an important source of information for XLSForm coders such as me, I thought I should point out this problem. (BTW, at the end of this same documentation section, the calculation formula should read if(${age} = '', '', once(now()))
instead of if(age = '', '', once(now()))
. I wasted more time than I care to admit because of this, back in December, but really, that's on me. )
Here is some context, in case you'd have some guidance on the particular problem I'm facing. We're suspecting massive "Interviewer Fabrication" (to quote the title of Benjamin Birnbaum's dissertation, linked in another discussion [on GitHub] by @LN) in some of our recent assessments, initially based on how quickly the surveys were filled. So to be able to monitor this in the future, we'd like to calculate the duration of each interview in-survey. The reasons for using this instead of the more elaborate "audit" feature (which I haven't tested yet) are 1) to keep it light, and 2) to give the survey managers an easy way to monitor this indicator on the KoBo online interface, even mid-assessment, so they can take measures if necessary.
My first implementation of this was to use a "calculate" variable with ${end}-${start}
(and some time unit conversion). It worked really well in my first tests with Enketo, but I realised a few days ago that ODK/KoBo Collect behave differently: variables using ${end}
are not re-evaluated when the survey is finalised and their values remain empty.
Yesterday, I finally came up with another solution: I'm still using ${start}
as the initial timestamp, but I'm now using if(${some_variable}='','',now())
for the final timestamp, again with some time unit conversion. I'm not sure why exactly (the behaviour of now()
is still a bit of a mystery to me), but this seems to work as I want it to. (See attached XLS form: Convert timestamps and calculate durations within survey.xlsx) However, I still have two problems with this solution:
- I don't really know why it works and how
now()
works, so I'm afraid it may not work anymore in the future if the behaviour ofnow()
changes at some point. - It uses a reference to an unrelated variable (which, in addition, needs to be required and always relevant), which may need to be changed when coding a different survey: I'd like to find a more self-contained solution.
Any insight into this matter would be greatly appreciated.