Skip to main content
Solved

Synthetic time series query not supporting IF statements in 'expressions' parameter


Forum|alt.badge.img+1

I am trying to create a synthetic time series query that looks are two other time series and if those values meet a certain condition, is outputs a 1 or 0 as the synthetic time series but I keep getting a syntax error that I can’t solve. Below is a code sample.

 

temp_id_list = [3308928194658464]
flow_id_list = [1256034258207391, 3564715377369546]

for temperature in temp_id_list:
    temp_expression = f"TS{{id:{temperature}}} < 200"
    flow_expression = " + ".join([f"(TS{{id:{flowrate}}})" for flowrate in flow_id_list])

    final_expression = f"if({temp_expression} and {flow_expression} > 0, 1, 0)"

    cv_query = client.time_series.data.synthetic.query(expressions=final_expression, start="1d-ago", end="now")

Best answer by Everton Colling

Hi Talia!

Our current capabilities for synthetic time series do not support the use of if expressions. The supported functions include various mathematical operators, trigonometric functions, and specific functions like ln, pow, sqrt, exp, abs, and map. However, conditional statements like if are not listed among these supported functions. For more detailed information and to explore potential workarounds, you can refer to the Cognite synthetic time series documentation: Synthetic time series documentation.

In some cases the usage of functions like max and min can help you achieve the similar outcome as with an if expression, but we do understand that it’s not as flexible. If this is an important feature for you, I recommend making a feature request as a Product Idea here on the hub.

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

2 replies

Everton Colling
Seasoned Practitioner
Forum|alt.badge.img
  • Seasoned Practitioner
  • 174 replies
  • Answer
  • December 7, 2023

Hi Talia!

Our current capabilities for synthetic time series do not support the use of if expressions. The supported functions include various mathematical operators, trigonometric functions, and specific functions like ln, pow, sqrt, exp, abs, and map. However, conditional statements like if are not listed among these supported functions. For more detailed information and to explore potential workarounds, you can refer to the Cognite synthetic time series documentation: Synthetic time series documentation.

In some cases the usage of functions like max and min can help you achieve the similar outcome as with an if expression, but we do understand that it’s not as flexible. If this is an important feature for you, I recommend making a feature request as a Product Idea here on the hub.


  • Backend developer
  • 37 replies
  • December 7, 2023

I’ve used some workarounds before, using max, min, round, but also hack with the on_error method.
For instance
on_error(sqrt(200-TS{id:...}) this will throw an error if TS>200, due to sqrt of negative number

* 0 + (value if expression is true), value if no error

(value if expression is false)) value if error

You can also use ln, which fails on <= 0, not just <0

The syntax is not very nice, but it should get the work done

If the input is string time series, it is actually easier, using the map() function


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