How can I have the total time Psychopy - psychopy

I made an experimentation on Psychopy. I have Intructions, 10 differents routines and then msg end.
I am able to have all the time it took for each routine, but I will like to have the total time of my 10 routines without having to calculate it my self in my csv file at the end.
Code for having my duration of each trial. I putted this line in each routine.
thisExp.addData('trial_duration1', t)
I tried to create a variable total and adding all the trial_duration, but my column was empty in the csv file at the end.
Thanks!!

Psychopy has an internal clock which starts when the experiment starts. You can read the time using core.monotonicClock.getTime(). The timing of this clock starts almost immediately as you hit "run", i.e. before the dialogue box, so it doesn't read the time since the first routine started. However, you can get that duration by first recording the time of the clock in a code component when you want time zero to be defined:
time_zero = core.monotonicClock.getTime()
... and then record the time elapsed doing
thisExp.addData('cumulative_duration', core.monotonicClock.getTime() - time_zero)
Note that if you want to do this only for particular loops (e.g. define time_zero in the first loop and record cumulative_duration in the last loop) require the condition to be satisfied:
# If this is the first iteration of the loop (no matter the name of the loop)
if currentLoop.thisN == 0:
time_zero = core.monotonicClock.getTime()

Related

Create a variable to count from 1 to n in AnyLogic

I am looking to add a variable to count from 1 to 217 every hour in AnyLogic, in order to use as a choice condition to set a parameters row reference.
I am assuming I either need to use an event or a state chart however I am really struggling with the exact and cannot find anything online.
If you have any tips please let me know, any help would be appreciated
Thank you,
Tash
A state machine isn't necessary in this case as this can be achieve using a calculation or a timed event. AnyLogic has time() function which returns time since model start as a double in model time units of measurements.
For example: if model time units is seconds and it has been running for 2hr 2min 10sec then time(SECOND) will return 7330.0 (it is always a double value). 1/217th of an hour corresponds to about 3600/217 = 16.58 seconds. Also, java has a handy function Math.floor() which rounds down a double value, so Math.floor(8.37) = 8.0.
Assembling it all together:
// how many full hours have elapsed from the start of the model
double fullHrsFromStart = Math.floor(time(HOUR));
// how many seconds have elapsed in the current model hour
double secondsInCurrentHour = time(SECOND) - fullHrsFromStart * 3600.0;
// how many full 16.58 (1/217th of an hour) intervals have elapsed
int fullIntervals = (int)(secondsInCurrentHour / 16.58);
This can be packaged into a function and called any time and it is pretty fast.
Alternatively: an Event can be created which increments some count by 1 every 16.58 seconds and ten resets it back to 0 when the count reaches 217.

How to create a binary window for an event in Python

I have some sensor data and I know when the main event happens, but there's some noise before and after this event, and so I want to create a binary window where I can then just through away all the non important information.
Here is a toy example.
eg=pd.DataFrame({"Seconds":[0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5],
"Event":[0,0,1,0,0,0,0,1,0,0,0,1],
"Start":[0,1,0,0,0,0,1,0,0,0,1,0],
"End": [0,0,0,1,0,0,0,0,1,0,0,0],
"Want": [0,1,1,1,0,0,1,1,1,0,1,1]})
I have generated my start and end with shifting. What I cannot seem to create in Python is my Want. The start and the end are more than 1 row away from the event, albeit they are fixed intervals.
In excel I am able to create a 3 nested that effectively does the following:
fup_bottom["Want"]=np.where(fup_bottom.End==1,0,
np.where(fup_bottom.Start==1,1,
np.where(fup_bottom.Want.shift(1)==1,1,0)))
In python this doesn't work because the "Want" doesn't exist yet.
I have tried recording the seconds where Start is 1 and forward filling, and then similarly where End is one and backward filling. However, this leads to Want always being 1 after the first event.
I greatly appreciate any help on this. I've been trying to figure this out for a couple of hours and am stuck.
J

How to get the time elapsed time after using the reset of the "Elapsed Time" component?

I am calculating the capacitance of a circuit using LabVieW. I have tried to get the time after the voltage across it reaches 2.5V. I am giving a supply of 5V. I used a logic operator and connected it to the reset to the elapsed time component. But I get zero as the time gets reseted. I want to get the actual time elapsed.
The block diagram of the circuit:
Try this code: Do not wire something on the reset and place a False on the Auto Reset Input
Block Diagram

What does In [*] at the upper left-hand of the cell mean when running a jupyter notebook?

What does In [*] at the upper left-hand of the cell mean when running a jupyter notebook and how I can resolve this?
Please any one can help me.
It means that the cell is running, or in queue to be run. You don't solve it really, you just have to wait for the cell to finish executing. If you think the cell has gotten stuck for some reason, you can try to interrupt it by going to "Kernel" in the menu bar and selecting "Interrupt". When the cell is finished running, a number will appear instead of a star. The number is the order in which that cell was executed in this session.
If you have a cell that takes a really long time to execute, I suggest outputting some periodic status to the user. I like to do something like:
update_freq = 100 # or however often you want it to update you
print('Running', end='', flush=True)
for iter in range(a_whole_lot_of_iterations):
# ... code that runs for a long time or for a ton of iterations ...
if iter >= update_freq and iter % summary_freq == 0:
print('.', end='', flush=True) # periodically print something
print('done!')
You can get as fancy as you want with this approach, printing all kinds of cool stuff in your first line as a header, controlling how many updates are printed total to the screen so you can create a sort of ASCII status bar, etc. I found this guide to the Python string formatting language helpful when figuring out how to make nicely formatted status updates.

Optaplanner, How to catch the current time at the beginning of the rule to use it in score?

I have something like that:
scoreHolder.addSoftConstraintMatch(kcontext, (System.currentTimeMillis()-$time.getTime()));
I want to use the current time at the beginning of firing the rule only, and not to be updated during running the rule. just to catch the current time at the first moment the rule is fired and does not change till the end of solving.
I'm using optaplanner 6.1.
thanks in advance.
That would break OptaPlanner, as the Score of the same Solution would change over time (which also implies that comparing 2 different Solutions can not be done fairly - so if a new working score is compared to the best score (which was calculated x seconds ago) it breaks).
Instead, before the solver starts, set the current time millis in a singleton:
myParametrization.setStartingMillis(System.currentMillis());
... = solver.solve(...);
and add that as a problem fact and use it in the score rules (see examination example's InstitutionParameterization).