-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): python onboarding updating to influxdb3 python (#6770)
* added python package changes * Updated PythonWizard * chore: refactor component and fix exports --------- Co-authored-by: Jay Clifford <[email protected]>
- Loading branch information
Showing
6 changed files
with
201 additions
and
74 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/homepageExperience/components/steps/python/ExecuteAggregateQuerySql.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react' | ||
import CodeSnippet from 'src/shared/components/CodeSnippet' | ||
|
||
import {SafeBlankLink} from 'src/utils/SafeBlankLink' | ||
import {event} from 'src/cloud/utils/reporting' | ||
|
||
const logCopyCodeSnippet = () => { | ||
event('firstMile.pythonWizard.executeAggregateQuery.code.copied') | ||
} | ||
|
||
const logDocsOpened = () => { | ||
event('firstMile.pythonWizard.executeAggregateQuery.docs.opened') | ||
} | ||
|
||
type OwnProps = { | ||
bucket: string | ||
} | ||
|
||
export const ExecuteAggregateQuerySql = (props: OwnProps) => { | ||
const {bucket} = props | ||
|
||
const sqlSnippet = `SELECT mean(count) | ||
FROM 'census' | ||
WHERE time > now() - '10m'` | ||
|
||
const querySnippet = `query = """SELECT mean(count) | ||
FROM 'census' | ||
WHERE time > now() - '10m'""" | ||
# Execute the query | ||
table = client.query(query=query, database="${bucket}", language='influxql') ) | ||
# Convert to dataframe | ||
df = table.to_pandas().sort_values(by="time") | ||
print(df) | ||
` | ||
|
||
return ( | ||
<> | ||
<h1>Execute an Aggregate Query</h1> | ||
<p> | ||
<SafeBlankLink | ||
href="https://docs.influxdata.com/flux/v0.x/function-types/#aggregates" | ||
onClick={logDocsOpened} | ||
> | ||
Aggregate functions | ||
</SafeBlankLink>{' '} | ||
take the values of all rows in a table and use them to perform an | ||
aggregate operation. The result is output as a new value in a single-row | ||
table. | ||
</p> | ||
<CodeSnippet | ||
text={sqlSnippet} | ||
showCopyControl={false} | ||
onCopy={logCopyCodeSnippet} | ||
language="sql" | ||
/> | ||
<p> | ||
In this example, we use the{' '} | ||
<code className="homepage-wizard--code-highlight">mean()</code> function | ||
to calculate the average value of data points in the last 10 minutes. | ||
<br /> | ||
<br /> | ||
Run the following: | ||
</p> | ||
<CodeSnippet | ||
text={querySnippet} | ||
onCopy={logCopyCodeSnippet} | ||
language="python" | ||
/> | ||
<p> | ||
In this example we use{' '} | ||
<code className="homepage-wizard--code-highlight">InfluxQL</code> to | ||
perform our aggregation. SQL and InfluxQL can be used interchangeably in | ||
the Python client. | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/homepageExperience/components/steps/python/InitializeClientSql.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react' | ||
import {useSelector} from 'react-redux' | ||
|
||
import CodeSnippet from 'src/shared/components/CodeSnippet' | ||
import {event} from 'src/cloud/utils/reporting' | ||
|
||
import {getOrg} from 'src/organizations/selectors' | ||
import {selectCurrentIdentity} from 'src/identity/selectors' | ||
|
||
const logCopyCodeSnippet = () => { | ||
event('firstMile.pythonWizard.initializeClient.code.copied') | ||
} | ||
|
||
export const InitializeClientSql = () => { | ||
const org = useSelector(getOrg) | ||
const {org: quartzOrg} = useSelector(selectCurrentIdentity) | ||
|
||
const url = quartzOrg.clusterHost || window.location.origin | ||
|
||
const pythonCode = `import os, time | ||
from influxdb_client_3 import InfluxDBClient3, Point | ||
token = os.environ.get("INFLUXDB_TOKEN") | ||
org = "${org.name}" | ||
host = "${url}" | ||
client = InfluxDBClient3(host=host, token=token, org=org)` | ||
|
||
return ( | ||
<> | ||
<h1>Initialize Client</h1> | ||
<p> | ||
Run this command in your terminal to open the interactive Python shell: | ||
</p> | ||
<CodeSnippet language="properties" text="python3" /> | ||
<p> | ||
Paste the following code after the prompt (>>>) and press | ||
Enter. | ||
</p> | ||
<CodeSnippet | ||
language="python" | ||
onCopy={logCopyCodeSnippet} | ||
text={pythonCode} | ||
/> | ||
<p> | ||
Here, we initialize the token, organization info, and server url host | ||
that are needed to set up the initial connection to InfluxDB. The client | ||
connection is then established with the{' '} | ||
<code className="homepage-wizard--code-highlight">InfluxDBClient</code>{' '} | ||
initialization. | ||
</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters