Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Logging time stamps using inline script

edited March 2024 in OpenSesame

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 the logger . 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 the log object, 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:

    var.current_time_1 = get_current_timestamp()
    

    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

  • 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 :)

Sign In or Register to comment.