From 317641ce1e74c99afd495409754939874b3ec3c6 Mon Sep 17 00:00:00 2001 From: Jay Clifford Date: Wed, 9 Aug 2023 11:06:23 +0100 Subject: [PATCH 1/2] fixed python language errors --- .../components/steps/python/ExecuteAggregateQuerySql.tsx | 6 +++--- .../components/steps/python/ExecuteQuerySql.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx b/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx index 8a6e260bb9..b28c14f2ab 100644 --- a/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx +++ b/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx @@ -20,15 +20,15 @@ export const ExecuteAggregateQuerySql = (props: OwnProps) => { const {bucket} = props const sqlSnippet = `SELECT mean(count) -FROM 'census' +FROM census WHERE time > now() - '10m'` const querySnippet = `query = """SELECT mean(count) -FROM 'census' +FROM census WHERE time > now() - '10m'""" # Execute the query -table = client.query(query=query, database="${bucket}", language='influxql') ) +table = client.query(query=query, database="${bucket}", language='influxql') # Convert to dataframe df = table.to_pandas().sort_values(by="time") diff --git a/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx b/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx index cdc8dfd439..5be1329e15 100644 --- a/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx +++ b/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx @@ -15,17 +15,17 @@ export const ExecuteQuerySql = (props: OwnProps) => { const {bucket} = props const sqlSnippet = `SELECT * -FROM 'census' +FROM census WHERE time >= now() - interval '1 hour' AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)` const query = `query = """SELECT * -FROM 'census' +FROM census WHERE time >= now() - interval '24 hours' AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)""" # Execute the query -table = client.query(query=query, database="${bucket}", language='sql') ) +table = client.query(query=query, database="${bucket}", language='sql') # Convert to dataframe df = table.to_pandas().sort_values(by="time") From 0b984f631ee18d6220da43e9743c038347c03d00 Mon Sep 17 00:00:00 2001 From: Jay Clifford Date: Wed, 9 Aug 2023 13:28:25 +0100 Subject: [PATCH 2/2] updated aggregation --- .../steps/python/ExecuteAggregateQuerySql.tsx | 16 ++++++++-------- .../components/steps/python/ExecuteQuerySql.tsx | 6 ++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx b/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx index b28c14f2ab..e4d300dabd 100644 --- a/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx +++ b/src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx @@ -19,13 +19,13 @@ type OwnProps = { export const ExecuteAggregateQuerySql = (props: OwnProps) => { const {bucket} = props - const sqlSnippet = `SELECT mean(count) -FROM census -WHERE time > now() - '10m'` + const sqlSnippet = `SELECT mean(ants) as ant_mean, mean(bees) as bee_mean + FROM census + WHERE time >= now() - 24h` - const querySnippet = `query = """SELECT mean(count) -FROM census -WHERE time > now() - '10m'""" + const querySnippet = `query = """SELECT mean(ants) as ant_mean, mean(bees) as bee_mean + FROM census + WHERE time >= now() - 24h""" # Execute the query table = client.query(query=query, database="${bucket}", language='influxql') @@ -40,7 +40,7 @@ print(df)

Execute an Aggregate Query

Aggregate functions @@ -58,7 +58,7 @@ print(df)

In this example, we use the{' '} mean() function - to calculate the average value of data points in the last 10 minutes. + to calculate the average value of data points in the last 24 hours.

Run the following: diff --git a/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx b/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx index 5be1329e15..803590a51c 100644 --- a/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx +++ b/src/homepageExperience/components/steps/python/ExecuteQuerySql.tsx @@ -16,13 +16,11 @@ export const ExecuteQuerySql = (props: OwnProps) => { const sqlSnippet = `SELECT * FROM census -WHERE time >= now() - interval '1 hour' -AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)` +WHERE time >= now() - interval '1 hour'` const query = `query = """SELECT * FROM census -WHERE time >= now() - interval '24 hours' -AND ('bees' IS NOT NULL OR 'ants' IS NOT NULL)""" +WHERE time >= now() - interval '24 hours'""" # Execute the query table = client.query(query=query, database="${bucket}", language='sql')