-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature anywhere create detector flyout page #487
Merged
jackiehanyang
merged 12 commits into
opensearch-project:featureAnywhere
from
jackiehanyang:reviewBranch
May 24, 2023
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c24ed0f
Add create detector flyout page
jackiehanyang 051a075
cleanup
jackiehanyang 1647132
run prettier
jackiehanyang 0b279d3
remove enzyme usage
jackiehanyang a396e06
reuse existing helper function when creating detector
jackiehanyang 6a04e0c
cleanup
jackiehanyang b10bfac
Merge branch 'featureAnywhere' into reviewBranch
jackiehanyang b2e1671
rebase with associated detector change
jackiehanyang a456378
move helper functions to helper file
jackiehanyang b69963c
use VisLayerTypes for VisLayerExpressionFn
jackiehanyang a1fe2f2
address comments
jackiehanyang bbab3e8
use OVERLAY_ANOMALIES constant
jackiehanyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions
58
public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/helpers.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,58 @@ | ||
import { FEATURE_TYPE } from '../../../../public/models/interfaces'; | ||
import { FeaturesFormikValues } from '../../../../public/pages/ConfigureModel/models/interfaces'; | ||
import { find, snakeCase } from 'lodash'; | ||
|
||
export function visFeatureListToFormik( | ||
featureList, | ||
seriesParams | ||
): FeaturesFormikValues[] { | ||
return featureList.map((feature) => { | ||
return { | ||
featureId: feature.id, | ||
featureName: getFeatureNameFromVisParams(feature.id, seriesParams), | ||
featureEnabled: true, | ||
featureType: FEATURE_TYPE.SIMPLE, | ||
importance: 1, | ||
newFeature: false, | ||
aggregationBy: 'sum', | ||
aggregationOf: visAggregationToFormik(feature), | ||
aggregationQuery: JSON.stringify( | ||
visAggregationQueryToFormik(feature, seriesParams) | ||
), | ||
}; | ||
}); | ||
} | ||
|
||
export function formikToDetectorName(title) { | ||
const detectorName = | ||
title + '_anomaly_detector_' + Math.floor(100000 + Math.random() * 900000); | ||
detectorName.replace(/[^a-zA-Z0-9-_]/g, '_'); | ||
return detectorName; | ||
} | ||
|
||
const getFeatureNameFromVisParams = (id, seriesParams) => { | ||
let name = find(seriesParams, function (param) { | ||
if (param.data.id === id) { | ||
return true; | ||
} | ||
}); | ||
|
||
return name.data.label.replace(/[^a-zA-Z0-9-_]/g, '_'); | ||
}; | ||
|
||
function visAggregationToFormik(value) { | ||
return [ | ||
{ | ||
label: value.params.field.name, | ||
type: 'number', | ||
}, | ||
]; | ||
} | ||
|
||
function visAggregationQueryToFormik(value, seriesParams) { | ||
return { | ||
[snakeCase(getFeatureNameFromVisParams(value.id, seriesParams))]: { | ||
sum: { field: value.params.field.name }, | ||
}, | ||
}; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you consume this constant in
overlay_anomalies.ts
file as well. There is aname
value there. We can set it to this constant instead of redefining there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
overlay_anomalies.ts
file with this constant