-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): add a sitewise connected chart story
- Loading branch information
Showing
4 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
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,9 @@ | ||
AWS_ACCESS_KEY_ID=xxxxxxxxxx | ||
AWS_SECRET_ACCESS_KEY=xxxxxxxxxx | ||
AWS_SESSION_TOKEN=xxxxxxxxxx | ||
AWS_REGION=xxxxxxxxxx | ||
|
||
ASSET_ID_1=xxxxxxxxxx | ||
PROPERTY_ID_1=xxxxxxxxxx | ||
PROPERTY_ID_2=xxxxxxxxxx | ||
PROPERTY_ID_3=xxxxxxxxxx |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { getIotEventsClient, getSiteWiseClient } from '@iot-app-kit/core-util'; | ||
import { SiteWiseDataStreamQuery, initialize } from '@iot-app-kit/source-iotsitewise'; | ||
|
||
const getEnvCredentials = () => { | ||
if ( | ||
process.env.AWS_ACCESS_KEY_ID == null || | ||
process.env.AWS_SECRET_ACCESS_KEY == null || | ||
process.env.AWS_SESSION_TOKEN == null | ||
) { | ||
throw new Error( | ||
'Missing credentials: must provide the following env variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN within .env' | ||
); | ||
} | ||
return { | ||
// Provided by `.env` environment variable file | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | ||
sessionToken: process.env.AWS_SESSION_TOKEN, | ||
}; | ||
}; | ||
|
||
const getRegion = () => { | ||
if (process.env.AWS_REGION == null) { | ||
throw new Error('Missing credentials: Must provide the following env variables: AWS_REGION'); | ||
} | ||
return process.env.AWS_REGION; | ||
}; | ||
|
||
const getAssetQuery = () => { | ||
if ( | ||
process.env.ASSET_ID_1 == null || | ||
process.env.PROPERTY_ID_1 == null || | ||
process.env.PROPERTY_ID_2 == null || | ||
process.env.PROPERTY_ID_3 == null | ||
) { | ||
throw new Error( | ||
'Missing configuration: Must provide the following env variables: ASSET_ID_1. PROPERTY_ID_1. PROPERTY_ID_2 and PROPERTY_ID_3' | ||
); | ||
} | ||
return { | ||
assetId: process.env.ASSET_ID_1, | ||
propertyId1: process.env.PROPERTY_ID_1, | ||
propertyId2: process.env.PROPERTY_ID_2, | ||
propertyId3: process.env.PROPERTY_ID_3, | ||
}; | ||
}; | ||
|
||
export const getIotSiteWiseQuery = () => { | ||
const clientConfiguration = { | ||
awsCredentials: getEnvCredentials(), | ||
awsRegion: getRegion(), | ||
}; | ||
return initialize({ | ||
iotSiteWiseClient: getSiteWiseClient(clientConfiguration), | ||
iotEventsClient: getIotEventsClient(clientConfiguration), | ||
}).query; | ||
}; | ||
|
||
export const getTimeSeriesDataQuery = (dataStreamQuery?: SiteWiseDataStreamQuery) => { | ||
if (dataStreamQuery) { | ||
return getIotSiteWiseQuery().timeSeriesData(dataStreamQuery); | ||
} | ||
|
||
const { assetId, propertyId1, propertyId2, propertyId3 } = getAssetQuery(); | ||
|
||
return getIotSiteWiseQuery().timeSeriesData({ | ||
assets: [ | ||
{ | ||
assetId, | ||
properties: [ | ||
{ | ||
propertyId: propertyId1, | ||
aggregationType: 'AVERAGE', | ||
resolution: '1m', | ||
}, | ||
{ | ||
propertyId: propertyId2, | ||
aggregationType: 'AVERAGE', | ||
resolution: '1m', | ||
}, | ||
{ | ||
propertyId: propertyId3, | ||
aggregationType: 'AVERAGE', | ||
resolution: '1m', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
export const queryConfigured = () => { | ||
try { | ||
getEnvCredentials(); | ||
getRegion(); | ||
getAssetQuery(); | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
}; |
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