# Translating JS equation to PY in code command

**URL:** <https://discourse.psychopy.org/t/translating-js-equation-to-py-in-code-command/32075>\
**Category:** Coding\
**Tags:** python3, frame-rate, refresh\
**Created:** [November 21, 2022, 5:38am UTC](https://discourse.psychopy.org/t/translating-js-equation-to-py-in-code-command/32075 "2022-11-21T05:38:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![caitantal](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@caitantal](https://discourse.psychopy.org/u/caitantal)\
**Post date:** [November 21, 2022, 5:38am UTC](https://discourse.psychopy.org/t/translating-js-equation-to-py-in-code-command/32075/1 "2022-11-21T05:38:05Z")

</div>

Hi all,

I originally ran a PsychoPy script online via Pavlovia during COVID. Now, I am trying to adapt my script to be run locally–that is, I am converting my JS coding to Python.

In my original JS coding, I added some equations to calculate the approximate refresh rate of the participants monitors. However, when translating to Python, two problems emerge:

(1) The output to the first equation is incorrect, and  
(2) The second equation yields this error code: TypeError: unsupported operand type(s) for /: ‘int’ and ‘NoneType’

Can anyone help out with this? The coding chunks are pasted below.  
Many thanks!!!  
Cait

(1)  
average\_refresh\_duration = (duration\_clock.getTime()\*1000)/frame\_count  
average\_refresh\_duration = thisExp.addData(‘average\_refresh\_duration’,average\_refresh\_duration)

(2)  
approx\_frame\_rate = 1000/average\_refresh\_duration  
approx\_frame\_rate = thisExp.addData(‘approx\_frame\_rate’, approx\_frame\_rate)

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [November 21, 2022, 8:38am UTC](https://discourse.psychopy.org/t/translating-js-equation-to-py-in-code-command/32075/2 "2022-11-21T08:38:59Z")

</div>

Hello,

when your equation (1) is not solved, equation (2) will fail as average\_refresh\_duration is not defined. Why not add some print-commands to see what values your variables have?

print(frame\_count)  
print(average\_refresh\_duration) aso.

You might want to take a look [here](https://www.psychopy.org/general/timing/detectingFrameDrops.html).

Best wishes Jens
