Skip to main content
Solved

Cognite functions


Forum|alt.badge.img+2

I want to create a cognite function that will do lot of computations and finally attach the derived output to a timeseries. Is there some production-ready sample code snippet that can be shared to see how to attach a derived value from cognite function to a timseries?

Best answer by HaydenH

eashwar11 wrote:

Hi @roman.chesnokov ,

Thanks for the inputs. Is it possible to perform the insertion inside a cognite function but not return any json as output and deploy the function?

I think Cognite fucntion expects to have a json output. 

Are you referring to the output from the handle function in a Cognite Function? If so, this is more for status purposes. E.g., if your handle/function was successful you might have a dictionary returned as follows:

return {“status”: “success”, “message”: f“processed {len(total_data)} datapoints”}

This dictionary would then be viewable as a JSON from the Functions webpage in Fusion. Maybe if you were handling a failure you might also write something like:

return {“status”: “failure”, “message”: “no timeseries found”}

The functions referred to by @roman.chesnokov do not return any JSON values though (they actually return None). Does that make sense? If you don’t want to return anything in the handle function, then you could return an empty dictionary, but good practice would be to do something like above.

View original
Did this topic help you find an answer to your question?

4 replies

roman.chesnokov
Seasoned Practitioner

Hey @eashwar11 . Can you provide more details about attaching values to time-series? Do you want simply add a datapoint? According to the documentation, you can insert datapoints or insert a pandas dataframe as datapoints in multiple time-series simultaneously. Let me know if that’s helpful.


Forum|alt.badge.img+2
  • Author
  • 42 replies
  • July 20, 2023

Hi @roman.chesnokov ,

Thanks for the inputs. Is it possible to perform the insertion inside a cognite function but not return any json as output and deploy the function?

I think Cognite fucntion expects to have a json output. 


  • Practitioner
  • 20 replies
  • Answer
  • July 20, 2023
eashwar11 wrote:

Hi @roman.chesnokov ,

Thanks for the inputs. Is it possible to perform the insertion inside a cognite function but not return any json as output and deploy the function?

I think Cognite fucntion expects to have a json output. 

Are you referring to the output from the handle function in a Cognite Function? If so, this is more for status purposes. E.g., if your handle/function was successful you might have a dictionary returned as follows:

return {“status”: “success”, “message”: f“processed {len(total_data)} datapoints”}

This dictionary would then be viewable as a JSON from the Functions webpage in Fusion. Maybe if you were handling a failure you might also write something like:

return {“status”: “failure”, “message”: “no timeseries found”}

The functions referred to by @roman.chesnokov do not return any JSON values though (they actually return None). Does that make sense? If you don’t want to return anything in the handle function, then you could return an empty dictionary, but good practice would be to do something like above.


  • Seasoned Practitioner
  • 223 replies
  • August 9, 2023

Hi @eashwar11, did the above help you? You can always mark an answer as Best answer if it helped you solve your issue. 


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings