Calculating Standard Deviation in Server Script

Can someone help me with calculating Standard Deviation (STDEV) in server script?

Hey
I believe you can either import statistics library

OR numpy numpy.std — NumPy v1.23 Manual

and if you dont want to import anything you can do it by typing the whole formula manually

Thank you for the response @Harsh_Magiya. I tried this, but how do you import within a Server Script? This is the response i get:

Traceback (most recent call last):
  File "apps/frappe/frappe/core/doctype/scheduled_job_type/scheduled_job_type.py", line 83, in execute
    frappe.get_doc("Server Script", script_name).execute_scheduled_method()
  File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 101, in execute_scheduled_method
    safe_exec(self.script)
  File "apps/frappe/frappe/utils/safe_exec.py", line 64, in safe_exec
    exec(compile_restricted(script), exec_globals, _locals)  # pylint: disable=exec-used
  File "<unknown>", line 1, in <module>
ImportError: __import__ not found

Hey your error is not much clear to me
So you can import your module by adding it in .py file where you add your server script
and since numpy or statistics are extra library
you would have to add them in your requirement.txt file
you would have to do some further steps also like building the app so something that will download the library in you environment

It’s not possible to import libraries in a server script, and even if it were server scripts only allow a subset of explicitly whitelisted functions.

If you’re willing to use an app, you could import numpy. Otherwise, you’ll just have to do the calculation manually.

Yes I understood. I am stuck. Let me go learn how to create app and write code now :smiley: Thanks.