Solved

Cognite functions

  • 19 July 2023
  • 4 replies
  • 48 views

Badge +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?

icon

Best answer by HaydenH 20 July 2023, 09:09

View original

4 replies

Userlevel 3

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.

Badge +2

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. 

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.

Userlevel 3

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

Reply