Logging time stamps using inline script
Hello,
I need to use time stamps for connecting the data to two external sources (EdaMove4 and PolarH10). I wrote the following inline script for logging the time stamp:
----
Prepare:
import datetime
def get_current_timestamp():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
var.current_timestamp = get_current_timestamp()
Run:
# Log the timestamp
log.current_timestamp = var.current_timestamp
After the inline script I inserted a normal logger widget.
----
I think I did something wrong, because the time stamps are not for every event in the task. I actually want to log every single event from the beginning and actually also the end of the event to be able to connect it with the external source. Does anyone know how to do this?
I inserted a simplified version of the task (sorry most is in Dutch).
Thank you in advance.
Comments
Hi @SMD1990 ,
As a first step, let's try to understand what you are doing now. I suspect you copied this script from someone else and inserted it into your own experiment without fully understanding it, right?
In the Prepare phase of the script, you are assigning the current timestamp to the
var.current_timestamp. This variable will be automatically logged by thelogger. While this works, it will capture the timestamp during preparation, which is probably not what you want.In the Run phase, you are assigning the current timestamp to
log.current_timestamp, which you probably do with the assumption that this will trigger a new timestamp being logged. But it won't. It simply assigns the existing timestamp as a property of thelogobject, which effectively does nothing.What you want to do instead is to, at every point where you want to log the current time, assign to a unique variable in the Run phase of a script:
These variables will be automatically logged by the
logger. However, to make sure that timestamps for different events don't overwrite each other, you need to use different variable names for the different events.Does that make sense?
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan! Thank you I indeed did not fully understand what and why is logged with the timestamp. I thought using the same linked inline script would produce a more understandable logfile. Therefore I used the same variable for all the time stamps, but indeed, it did not make any sense. Now it does! Thanks :)